/*
 * App extensions to the SkAna visual system.
 *
 * The handoff pack is a set of static mockups, so it never needed tables, toasts,
 * dropdowns, flash messages, drag feedback or bottom sheets. Everything here is
 * derived from a primitive the pack does define, so the app stays inside one visual
 * language — the brief's words: "do not invent a second visual language".
 *
 * skana.css is the system and must not be edited; this file is where the app adapts.
 */

/*
 * Metric-matched fallback.
 *
 * Geist is ~8% narrower than the system UI font (measured: 3330px vs 3628px for the
 * same 100px sample string). Without this, text reflows when Geist finishes loading
 * and the page visibly jumps — worst on the wrapping notification strip, where a
 * width change moves a whole row. These overrides make the fallback occupy exactly
 * the space Geist will, so the swap is invisible.
 *
 * Re-derive with: canvas measureText on both families at the same size.
 */
@font-face {
  font-family: "Geist Fallback";
  src: local("Segoe UI"), local("Roboto"), local("Helvetica Neue"), local("Arial");
  size-adjust: 91.78%;
  ascent-override: 100.24%;
  descent-override: 23.97%;
  line-gap-override: 0%;
}

:root {
  /* skana.css is verbatim, so the fallback is spliced into the stack here. */
  --font: "Geist", "Geist Fallback", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Layout helpers the mockups did inline ---------- */
.grid-4 { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-sidebar { display: grid; gap: 16px; grid-template-columns: 1fr 360px; align-items: start; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-sidebar { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-4, .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ---------- Utilities ---------- */
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.muted { color: var(--crm-muted); }
.faint { color: color-mix(in oklab, var(--crm-cream) 45%, transparent); }
.strong { font-weight: 600; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
@media (max-width: 720px) { .hide-sm { display: none !important; } }

/* ---------- Native controls the pack never styled ---------- */
input[type="checkbox"], input[type="radio"] { accent-color: var(--crm-cream); width: 16px; height: 16px; }
input[type="date"], input[type="datetime-local"], input[type="time"] { color-scheme: dark; }
::selection { background: color-mix(in oklab, var(--crm-cream) 15%, transparent); color: var(--crm-cream); }
select.control option, .field select option { background: var(--crm-sidebar); color: var(--crm-cream); }
input[type="file"] {
  width: 100%; padding: 8px 10px; cursor: pointer; font-size: 13px;
  border: 1px dashed color-mix(in oklab, var(--crm-cream) 22%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--crm-bg) 40%, transparent);
  color: var(--crm-muted);
}
input[type="file"]::file-selector-button {
  margin-right: 12px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13px;
  border: 1px solid var(--crm-border); border-radius: 8px;
  background: none; color: var(--crm-cream);
}
input[type="file"]::file-selector-button:hover { background: rgba(255,255,255,0.05); }
.btn-ghost.sm, .btn-primary.sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Tables ----------
   The pack's only repeating-row primitive is .list-row, so on a phone each row
   collapses into exactly that shape rather than scrolling sideways. */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 10px 12px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--crm-muted);
  border-bottom: 1px solid color-mix(in oklab, var(--crm-cream) 12%, transparent);
}
.table td {
  padding: 12px; vertical-align: middle;
  border-bottom: 1px solid color-mix(in oklab, var(--crm-cream) 10%, transparent);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255,255,255,0.04); }
.table .num { font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    border: 1px solid color-mix(in oklab, var(--crm-cream) 18%, transparent);
    background: color-mix(in oklab, var(--crm-bg) 35%, transparent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 4px 12px; margin-bottom: 12px;
  }
  .table td { border: 0; padding: 7px 0; display: flex; gap: 12px; align-items: baseline; }
  .table td::before {
    content: attr(data-label); flex: 0 0 38%;
    font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--crm-muted);
  }
  .table td:empty { display: none; }
  .table td.right { text-align: left; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: color-mix(in oklab, var(--crm-bg) 40%, transparent);
  border: 1px solid var(--crm-border);
  color: var(--crm-muted);
}
.badge.success { background: rgba(16,185,129,0.2); border-color: rgba(16,185,129,0.35); color: #a7f3d0; }
.badge.warning { background: rgba(245,158,11,0.2); border-color: rgba(245,158,11,0.35); color: #fde68a; }
.badge.danger { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.45); color: #fecaca; }
.badge.info { background: rgba(14,165,233,0.2); border-color: rgba(14,165,233,0.35); color: #bae6fd; }
.badge.count {
  min-width: 20px; height: 20px; padding: 0 6px; justify-content: center;
  background: #fbbf24; border-color: #fbbf24; color: var(--crm-bg); font-size: 10px; font-weight: 700;
}

/* ---------- Flash messages ---------- */
.flash {
  border: 1px solid rgba(16,185,129,0.4); background: rgba(16,185,129,0.15); color: #a7f3d0;
  border-radius: var(--radius-lg); padding: 10px 14px; font-size: 14px; font-weight: 500;
  margin-bottom: 16px;
}
.flash.alert-error { border-color: rgba(239,68,68,0.45); background: rgba(239,68,68,0.15); color: #fecaca; }

/* ---------- Drag feedback on the boards ---------- */
.deal[draggable="true"], .task-card[draggable="true"] { cursor: grab; }
.deal.dragging, .task-card.dragging { opacity: .45; }
.panel.dragover { outline: 2px dashed color-mix(in oklab, var(--crm-cream) 55%, transparent); outline-offset: -4px; }
/* Touch fallback — HTML5 drag and drop does not work on iOS, per handoff §6.
   Hidden wherever a real pointer can drag, so the desktop board matches the pack
   exactly; shown on touch devices and narrow screens. */
.move-select { display: none; }
@media (hover: none), (pointer: coarse), (max-width: 860px) {
  .move-select {
    display: block;
    width: 100%; margin-top: 6px; min-height: 44px;
    border: 1px solid var(--crm-border); border-radius: 10px;
    background: color-mix(in oklab, var(--crm-bg) 45%, transparent);
    color: var(--crm-muted); font-size: 12px; padding: 6px 8px;
  }
}

/* Keep a deal's product line on one row, as in the pack. */
.deal-sub > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-sub b { flex: none; }

/* ---------- Floating panels ----------
   The pack has no dropdown (it uses the always-visible .notif-bar), so this borrows
   the modal's opaque fill — a translucent panel over a scrolling board is unreadable. */
.dropdown {
  position: absolute; z-index: 40; width: 340px;
  background: var(--crm-sidebar); border: 1px solid var(--crm-border);
  border-radius: var(--radius-xl); box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.dropdown__scroll { max-height: 360px; overflow-y: auto; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  max-width: 320px; bottom: calc(16px + var(--safe-bottom));
}
.toast {
  display: block; padding: 10px 12px; font-size: 14px; cursor: pointer;
  background: var(--crm-sidebar); border: 1px solid var(--crm-border);
  border-left: 3px solid var(--crm-cream);
  border-radius: var(--radius-lg); box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.toast__title { display: block; font-weight: 600; margin-bottom: 2px; }
.toast__text { color: var(--crm-muted); }

/* ---------- Modal behaviour ----------
   The pack ships modal styling but no markup or open/close logic. */
.modal-back { display: none; overflow-y: auto; }
.modal-back.open { display: flex; }
.modal { animation: modal-pop .14s ease; max-height: 90vh; overflow-y: auto; }
@keyframes modal-pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-close { border: 0; background: none; color: var(--crm-muted); font-size: 22px; line-height: 1; cursor: pointer; }
.sheet-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius-lg); min-height: 48px;
}
.sheet-link:hover { background: rgba(255,255,255,0.05); }

@media (max-width: 640px) {
  /* Modals become bottom sheets on a phone, per handoff §6. */
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { max-width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding-bottom: calc(16px + var(--safe-bottom)); }
  .dropdown { position: fixed; inset: auto 0 0 0; width: auto; border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding-bottom: var(--safe-bottom); }
  .notif-bar { gap: 8px; padding: 8px 16px; }
  .notif-bar .notif-chip:nth-of-type(n + 2) { display: none; }
  /* Keep the bell, one chip and "View all" on a single row. */
  .notif-chip { flex: 1; min-width: 0; }
  .notif-chip strong, .notif-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- Chat attachments ---------- */
.bubble__time { display: block; font-size: 10px; opacity: .7; margin-top: 3px; }
.bubble__preview { display: block; margin-top: 6px; max-width: 240px; border-radius: 10px; cursor: pointer; }
.bubble__attach { display: inline-block; margin-top: 4px; font-size: 13px; text-decoration: underline; }
.bubbles { overflow-y: auto; max-height: 60vh; }

/* ---------- Rich-text signature editor ---------- */
.sig-editor { border: 1px solid var(--crm-border); border-radius: var(--radius-lg); overflow: hidden; background: color-mix(in oklab, var(--crm-bg) 40%, transparent); }
.sig-toolbar { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--crm-border); background: rgba(255,255,255,0.04); }
.sig-btn { width: 30px; height: 28px; border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; color: var(--crm-cream); }
.sig-btn:hover { background: rgba(255,255,255,0.06); border-color: var(--crm-border); }
.sig-surface { min-height: 110px; padding: 10px 12px; font-size: 14px; outline: none; }
.sig-surface:focus { box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--crm-cream) 15%, transparent); }
.sig-surface a { color: var(--crm-cream); text-decoration: underline; }

/* ---------- Masked credential values ---------- */
.masked { font-family: var(--font-mono); letter-spacing: .08em; }

/* ---------- Offline splash ---------- */
.offline { min-height: 100vh; display: grid; place-items: center; padding: 64px 16px; text-align: center; }
.offline img { width: 120px; margin: 0 auto 24px; }
.offline h1 { font-size: 24px; margin: 0 0 12px; }
.offline p { color: var(--crm-muted); margin: 0 0 24px; max-width: 22rem; }


/* Segmented control items are links in the app so each tab is a real URL. */
.seg > a { display: inline-flex; }
.seg > a > button { pointer-events: none; }

/* Day cells are interactive once the day modal exists. */
.day[data-date] { cursor: pointer; }
.day[data-date]:hover { border-color: color-mix(in oklab, var(--crm-cream) 35%, transparent); }
