/* ============================================================
   Components. Every control in the product is defined once here.
   If a screen needs a button that looks different, the answer is
   a variant in this file, not a one-off rule in a view sheet.
   ============================================================ */

/* ---------------------------------------------------------- button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 34px;
  padding: 0 var(--s3);
  border-radius: var(--r-control);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--t-13);
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--fast) var(--ease),
              border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease),
              opacity var(--fast) var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--line-3); }
/* A press that moves is the single cheapest way to make a UI feel
   built rather than rendered. One pixel, 120ms, no bounce. */
.btn:active { transform: translateY(1px); background: var(--surface-4); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--text-on-accent);
  box-shadow: var(--lift-1);
}
.btn-primary:hover {
  background: color-mix(in oklab, var(--accent) 88%, #ffffff);
  border-color: transparent;
}
.btn-primary:active { background: color-mix(in oklab, var(--accent) 88%, #000000); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text); }

.btn-danger { color: var(--danger-text); border-color: color-mix(in oklab, var(--danger) 34%, var(--line)); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-lg { height: 42px; padding: 0 var(--s5); font-size: var(--t-14); border-radius: var(--r-control); }
.btn-sm { height: 28px; padding: 0 var(--s2); font-size: var(--t-12); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }

.btn svg { flex: none; }

/* A link that is really a button. Underline on hover only, so a row
   of them does not read as a paragraph of links. */
.link-btn {
  color: var(--text-2);
  font-size: var(--t-13);
  border-radius: var(--r-chip);
}
.link-btn:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }

/* ----------------------------------------------------------- input */

.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field > label { font-size: var(--t-12); font-weight: 550; color: var(--text-2); }
.field-hint { font-size: var(--t-12); color: var(--text-3); }
.field-error { font-size: var(--t-12); color: var(--danger-text); }

.input, .select, .textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px var(--s3);
  border-radius: var(--r-control);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--t-14);
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 84px; resize: vertical; line-height: var(--lh-snug); }

.select {
  appearance: none;
  padding-right: var(--s7);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 15px, calc(100% - 12px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* Date and time inputs render their own icon in a colour the browser
   picks. Inverting it is the only way to stop a black glyph sitting
   on a near-black field. */
.input[type="date"], .input[type="datetime-local"], .input[type="time"] { min-height: 36px; }
:root:not([data-theme="light"]) .input::-webkit-calendar-picker-indicator {
  filter: invert(0.75);
  cursor: pointer;
}

.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-size: var(--t-13); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }

/* A search field, used in the top bar and in pickers. */
.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  max-width: 420px;
}
.search svg { position: absolute; left: 10px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 32px; }

/* Segmented control, for view switches. One track, a sliding-free
   active pill, because a sliding pill is an animation that has to be
   right on every resize and buys nothing. */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
}
.segmented button {
  height: 26px;
  padding: 0 var(--s3);
  border-radius: 6px;
  font-size: var(--t-12);
  font-weight: 550;
  color: var(--text-2);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.segmented button:hover { color: var(--text); background: var(--surface-3); }
.segmented button[aria-selected="true"] {
  background: var(--surface-4);
  color: var(--text);
  box-shadow: var(--lift-1);
}

/* ------------------------------------------------------------ card */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--lift-1), var(--edge-top);
}
.card-pad { padding: var(--s5); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: var(--t-14); }
.card-body { padding: var(--s5); }
.card-foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--line); }

/* ------------------------------------------------------------ chip */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-chip);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--t-11);
  font-weight: 550;
  letter-spacing: 0.01em;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
.chip > .truncate { min-width: 0; flex: 0 1 auto; }
.chip > svg { flex: none; }

.chip[data-tone="action"]  { background: var(--attention-soft); color: var(--attention-text); }
.chip[data-tone="gold"]    { background: var(--booked-soft);    color: var(--booked-text); }
.chip[data-tone="go"]      { background: var(--won-soft);       color: var(--won-text); }
.chip[data-tone="trust"]   { background: var(--trust-soft);     color: var(--trust-text); }
.chip[data-tone="accent"]  { background: var(--accent-soft);    color: var(--accent-text); }
.chip[data-tone="danger"]  { background: var(--danger-soft);    color: var(--danger-text); }
.chip[data-tone="muted"],
.chip[data-tone="neutral"] { background: var(--surface-3);      color: var(--text-2); }

.chip-outline { background: transparent; border: 1px solid var(--line-2); }

/* ----------------------------------------------------------- table */

.table { width: 100%; border-collapse: collapse; font-size: var(--t-13); }
.table th {
  text-align: left;
  padding: var(--s2) var(--s3);
  font-size: var(--t-11);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--fast) var(--ease); }
.table tr[data-clickable] { cursor: pointer; }
.table tr[data-clickable]:hover td { background: var(--surface-2); }
.table .right { text-align: right; }

/* ------------------------------------------------- empty + loading */

/* An empty state says what will appear here and, when there is one,
   offers the action that fills it. "No leads found" is not a state,
   it is an apology. */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  padding: var(--s8) var(--s5);
  text-align: center;
}
.empty-glyph {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-card);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-3);
}
.empty h3 { font-size: var(--t-15); }
.empty p { color: var(--text-2); max-width: 44ch; font-size: var(--t-13); }
.empty-inline { padding: var(--s6) var(--s4); }

.skeleton {
  border-radius: var(--r-chip);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 40%, var(--surface-2) 80%);
  background-size: 300% 100%;
  animation: shimmer 1.3s var(--ease) infinite;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -40% 0; } }

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid color-mix(in oklab, currentColor 28%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 620ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- toast */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--s2);
  max-width: min(92vw, 480px);
  padding: var(--s2) var(--s4);
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  box-shadow: var(--lift-3), var(--edge-top);
  font-size: var(--t-13);
  pointer-events: auto;
  animation: toast-in var(--base) var(--ease-out) both;
}
.toast.is-out { animation: toast-out var(--fast) var(--ease) both; }
.toast[data-kind="error"] { border-color: color-mix(in oklab, var(--danger) 45%, var(--line)); }
.toast[data-kind="error"] .toast-dot { background: var(--danger); }
.toast[data-kind="success"] .toast-dot { background: var(--won); }
.toast-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(6px) scale(0.98); } }

/* ----------------------------------------------------- dialog/sheet */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity var(--base) var(--ease);
}
.scrim.is-open { opacity: 1; }

.dialog {
  position: fixed;
  z-index: 61;
  left: 50%;
  top: 50%;
  width: min(92vw, 440px);
  transform: translate(-50%, -48%) scale(0.98);
  opacity: 0;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-panel);
  box-shadow: var(--lift-4), var(--edge-top);
  transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out);
}
.dialog.is-open { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.dialog-head { display: flex; gap: var(--s3); padding: var(--s5) var(--s5) var(--s3); }
.dialog-glyph {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: var(--r-control); background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text-2);
}
.dialog-head h2 { font-size: var(--t-15); }
.dialog-head p { font-size: var(--t-13); color: var(--text-2); margin-top: 2px; }
.dialog-body { padding: 0 var(--s5) var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: var(--s2);
  padding: var(--s3) var(--s5); border-top: 1px solid var(--line);
}
.dialog-choices { display: flex; flex-wrap: wrap; gap: var(--s2); }
.dialog-choices .btn { flex: 1 1 auto; justify-content: flex-start; }

@media (max-width: 560px) {
  /* On a phone a centred dialog fights the keyboard. It becomes a
     sheet that rises from the bottom, where the thumb already is. */
  .dialog {
    top: auto; bottom: 0; left: 0;
    width: 100%;
    transform: translateY(14px);
    border-radius: var(--r-panel) var(--r-panel) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dialog.is-open { transform: translateY(0); }
  .dialog-foot .btn { flex: 1 1 0; height: 42px; }
}

/* ------------------------------------------------------------ panel */

/* The detail panel. A right-hand drawer on a desktop, a full-height
   sheet on a phone. Same component, two shapes. */
.panel {
  position: fixed;
  z-index: 61;
  top: 0; right: 0; bottom: 0;
  width: min(100vw, var(--panel-w));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line-2);
  box-shadow: var(--lift-4);
  transform: translateX(16px);
  opacity: 0;
  transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out);
}
.panel.is-open { transform: none; opacity: 1; }
.panel-head {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s4) var(--s4) var(--s3);
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: var(--t-17); letter-spacing: var(--track-title); }
.panel-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.panel-section { padding: var(--s4); border-bottom: 1px solid var(--line); }
.panel-section > h3 {
  font-size: var(--t-11); font-weight: 600; letter-spacing: var(--track-label);
  text-transform: uppercase; color: var(--text-3); margin-bottom: var(--s3);
}
.panel-section:last-child { border-bottom: none; }
.panel-foot {
  display: flex; gap: var(--s2); padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line); background: var(--surface-2);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom));
}

@media (max-width: 720px) {
  .panel {
    top: var(--s7); left: 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--line-2);
    border-radius: var(--r-panel) var(--r-panel) 0 0;
    transform: translateY(20px);
  }
}

/* -------------------------------------------------------- key-value */

.kv { display: grid; grid-template-columns: minmax(84px, auto) 1fr; gap: var(--s2) var(--s4); font-size: var(--t-13); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }

/* --------------------------------------------------------- tooltip */

[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: var(--r-chip);
  background: var(--surface-4);
  border: 1px solid var(--line-2);
  box-shadow: var(--lift-2);
  color: var(--text);
  font-size: var(--t-11);
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 70;
  animation: tip-in var(--fast) var(--ease) both;
}
@keyframes tip-in { from { opacity: 0; transform: translateX(-50%) translateY(3px); } }

/* A shop about to send a link that cannot do what they think it does.
 * Loud enough to stop them, quiet enough not to look like an error. */
.quote-warning {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  margin: 0 0 var(--s3);
  padding: var(--s3);
  border: 1px solid var(--attention-line, var(--line-2));
  border-radius: var(--r-card);
  background: var(--attention-soft);
  color: var(--attention-text);
  font-size: var(--t-13);
  line-height: var(--lh-snug);
}

.quote-warning svg { flex: none; margin-top: 1px; }

/* Sandbox previews look exactly like production, which is the point of
 * them and the danger. This is not dismissible on purpose. */
.sandbox-bar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: var(--s1) var(--s3);
  background: var(--attention);
  color: #140f0a;
  font-size: var(--t-12);
  line-height: 1.5;
  text-align: center;
}

.sandbox-bar strong {
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
}

@media (max-width: 560px) {
  .sandbox-bar span { display: none; }
}

/* Side panels are fixed to the top of the window, which the bar covers.
   The bar is 12px text at 1.5 line height plus 4px above and below. */
.is-sandbox .panel { top: calc(var(--t-12) * 1.5 + var(--s1) * 2); }

/* A compact select for filter bars and inline rows, the height of .btn-sm. */
.select.select-sm {
  width: auto; min-height: 30px;
  padding: 4px var(--s7) 4px var(--s3);
  font-size: var(--t-13);
  background-position: calc(100% - 15px) 12px, calc(100% - 10px) 12px;
}

/* "Done": a confirmation, so it reads as the won colour rather than the
   brand accent. Soft, because it sits in lists beside other buttons. */
.btn-go { background: var(--won-soft); color: var(--won-text); border-color: color-mix(in oklab, var(--won) 35%, transparent); }
.btn-go:hover { background: color-mix(in oklab, var(--won) 24%, var(--surface)); }
.outcome-buttons { display: inline-flex; gap: var(--s2); flex: none; }

/* The M in the Montar mark is cut out of its tile, so it takes the colour
   of whatever it sits on rather than a fixed dark. */
.mark-glyph { stroke: var(--text-on-accent); }
