/* ============================================================================
   Omniweb — Leads & Commission Dashboard
   Editorial UI inspired by anthropic.com: warm off-white, restrained serif
   headings, generous whitespace, 1px dividers, sharp edges.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg:            #F0EDE6;  /* warm off-white background */
  --surface:       #F7F5F0;  /* cards / elevated surfaces */
  --surface-2:     #ECE8DF;  /* subtle fills (chips, inputs) */
  --ink:           #141413;  /* near-black text + primary actions */
  --ink-2:         #565248;  /* secondary text */
  --ink-3:         #8A857A;  /* muted / meta text */
  --border:        #DDD9D0;  /* 1px borders & dividers */
  --border-strong: #CBC6BA;

  /* Muted status tags — desaturated to sit in the warm palette */
  --green-bg:  #E2E7DC;  --green-ink:  #4C5B45;
  --amber-bg:  #EEE6D5;  --amber-ink:  #7A6531;
  --blue-bg:   #DFE4E9;  --blue-ink:   #45576A;
  --grey-bg:   #E7E4DD;  --grey-ink:   #6A665C;

  --radius:    2px;
  --radius-lg: 3px;
  --maxw:      1180px;
  --shadow:    0 1px 2px rgba(20,20,19,.05);
  --shadow-pop: 0 8px 30px rgba(20,20,19,.12);

  --ff-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --ff-sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --ff-mark:  "Space Grotesk", var(--ff-sans);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ff-sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv05";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-family: var(--ff-serif); font-weight: 500; letter-spacing: -0.01em; line-height: 1.1; margin: 0; }
p { margin: 0; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- Brand wordmark ---------- */
.brand {
  font-family: var(--ff-mark);
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--ink);
  user-select: none;
}
.brand .wm-omni { font-weight: 700; }
.brand .wm-web  { font-weight: 400; color: var(--ink-2); }
.brand--lg { font-size: 30px; }

/* ---------- Fade-in ---------- */
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadein .3s ease both; }
@media (prefers-reduced-motion: reduce) { .fade-in { animation: none; } }

/* ============================================================================
   LOGIN
   ========================================================================== */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login__inner {
  width: 100%;
  max-width: 380px;
  text-align: left;
}
.login .brand--lg { margin-bottom: 36px; }
.login__title { font-size: 30px; margin-bottom: 8px; }
.login__subtitle { color: var(--ink-2); margin-bottom: 28px; font-size: 14.5px; }
.login__form { display: grid; gap: 16px; }
.login__hint { margin-top: 22px; font-size: 13px; color: var(--ink-3); }

/* ============================================================================
   FORM PRIMITIVES
   ========================================================================== */
.field { display: grid; gap: 7px; }
.field__label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.input {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  transition: border-color .15s ease, background .15s ease;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--ink); background: #fff; }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--ink-2); cursor: not-allowed; }
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238A857A' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.form-error {
  color: var(--amber-ink);
  background: var(--amber-bg);
  border: 1px solid #E2D6BB;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 0;
}
.field-error { color: var(--amber-ink); font-size: 12.5px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 500; line-height: 1;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn--primary { background: var(--ink); color: var(--bg); }
.btn--primary:hover { background: #2c2b28; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { background: transparent; color: #8a3b32; border-color: #d8b6af; }
.btn--danger:hover { background: #f0e2df; }
.btn--solid-danger { background: #7c352c; color: #fff; }
.btn--solid-danger:hover { background: #682b23; }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 13px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.is-loading { color: transparent; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 15px; height: 15px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite; color: var(--bg);
}
.btn--ghost.is-loading::after, .btn--danger.is-loading::after { color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

.link-reset {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--ink-2); font-size: 13px; font-family: inherit;
  position: relative;
}
.link-reset::after {
  content: ""; position: absolute; left: 0; bottom: -2px; width: 100%; height: 1px;
  background: currentColor; transform: scaleX(0); transform-origin: left; transition: transform .2s ease;
}
.link-reset:hover::after { transform: scaleX(1); }

/* ============================================================================
   TOP BAR
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(240,237,230,.88);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar__right { display: flex; align-items: center; gap: 14px; }
.user-badge { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.user-badge__name { font-weight: 600; }
.role-tag {
  font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 7px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  color: var(--ink-2); background: var(--surface);
}
.role-tag--admin { color: var(--green-ink); background: var(--green-bg); border-color: #cdd6c4; }

/* ============================================================================
   PAGE LAYOUT
   ========================================================================== */
.page { max-width: var(--maxw); margin: 0 auto; padding: 40px 24px 96px; }
.page__head { margin-bottom: 32px; }
.page__title { font-size: clamp(30px, 5vw, 42px); margin-bottom: 8px; }
.page__lede { color: var(--ink-2); max-width: 60ch; font-size: 15.5px; }

/* ---------- Stat blocks ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.stat { background: var(--surface); padding: 18px 20px; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; }
.stat__label { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.stat__value { font-family: var(--ff-serif); font-size: 30px; font-weight: 500; letter-spacing: -.02em; line-height: 1; }
.stat__value small { font-size: 15px; color: var(--ink-3); font-family: var(--ff-sans); margin-left: 2px; }
.stat--accent { background: var(--ink); }
.stat--accent .stat__label { color: rgba(240,237,230,.65); }
.stat--accent .stat__value { color: var(--bg); }

/* ---------- Admin per-person breakdown ---------- */
.breakdown {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 18px 20px; margin-bottom: 28px;
}
.breakdown__title { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 14px; }
.breakdown__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 28px; }
.breakdown__row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.breakdown__name { font-weight: 600; font-size: 14px; }
.breakdown__amts { text-align: right; font-size: 13px; color: var(--ink-2); }
.breakdown__owed { font-family: var(--ff-serif); font-size: 18px; color: var(--ink); display: block; }

/* ---------- Controls ---------- */
.controls { margin: 0 0 22px; }
.controls__row { display: flex; align-items: flex-end; gap: 12px; }
.controls__row--filters { margin-top: 16px; flex-wrap: wrap; }
.search { flex: 1; }
.search__input { background: var(--surface); }
.field--inline { gap: 6px; }
.field--inline .select { min-width: 168px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink-2); cursor: pointer; transition: all .15s ease;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip__count { font-variant-numeric: tabular-nums; opacity: .7; font-size: 11.5px; }
.chip.is-active .chip__count { opacity: .85; }

/* ============================================================================
   LEADS TABLE  (becomes cards on mobile)
   ========================================================================== */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
table.leads-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.leads-table thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-3); padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
}
.leads-table td { padding: 15px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.leads-table tbody tr:last-child td { border-bottom: none; }
.leads-table tbody tr { transition: background .12s ease; }
.leads-table tbody tr:hover { background: var(--surface-2); }
.col-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-actions { text-align: right; white-space: nowrap; }

.biz { display: flex; flex-direction: column; gap: 2px; }
.biz__name { font-weight: 600; font-size: 14.5px; }
.biz__contact { font-size: 12.5px; color: var(--ink-3); }
.meta-name { font-weight: 500; }
.meta-sub { font-size: 12px; color: var(--ink-3); }

/* status tag + inline select */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: var(--radius);
  border: 1px solid transparent; white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.tag--grey  { background: var(--grey-bg);  color: var(--grey-ink);  border-color: #dcd8cf; }
.tag--blue  { background: var(--blue-bg);  color: var(--blue-ink);  border-color: #cdd6df; }
.tag--amber { background: var(--amber-bg); color: var(--amber-ink); border-color: #e2d6bb; }
.tag--green { background: var(--green-bg); color: var(--green-ink); border-color: #cdd6c4; }

.status-select {
  font-family: inherit; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 26px 6px 10px; cursor: pointer; color: var(--ink); background-color: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238A857A' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.status-select:focus { outline: none; border-color: var(--ink); }
.status-cell { display: flex; align-items: center; gap: 8px; }

.stale-flag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; color: var(--amber-ink);
  margin-top: 3px;
}
.stale-flag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--amber-ink); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

.paid-pill { font-size: 11px; font-weight: 600; color: var(--green-ink); }
.icon-btn {
  background: none; border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--ink); transition: all .15s ease; font-family: inherit;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.muted { color: var(--ink-3); }

/* ---------- Empty state ---------- */
.empty {
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 56px 24px; text-align: center; background: var(--surface);
}
.empty__title { font-family: var(--ff-serif); font-size: 22px; margin-bottom: 8px; }
.empty__text { color: var(--ink-2); max-width: 42ch; margin: 0 auto 18px; }

/* ============================================================================
   MODAL
   ========================================================================== */
.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-overlay { position: absolute; inset: 0; background: rgba(20,20,19,.34); animation: fadein .2s ease; }
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100dvh - 40px);
  overflow: auto; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); animation: fadein .25s ease both;
}
.modal__head { padding: 24px 26px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal__title { font-size: 24px; }
.modal__sub { color: var(--ink-2); font-size: 13.5px; margin-top: 4px; }
.modal__close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--ink-3); cursor: pointer; padding: 2px 6px; }
.modal__close:hover { color: var(--ink); }
.modal__body { padding: 22px 26px; display: grid; gap: 16px; }
.modal__foot { padding: 18px 26px 24px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); margin-top: 4px; flex-wrap: wrap; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.locked-note { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--ink-3); font-weight: 500; text-transform: none; letter-spacing: 0; }
.commission-box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; }
.commission-box__title { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.commission-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; }
.commission-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.commission-row--total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--ink); cursor: pointer; }
.checkbox-row label { font-size: 14px; cursor: pointer; }

.dup-warn { border: 1px solid #e2d6bb; background: var(--amber-bg); border-radius: var(--radius); padding: 14px 16px; }
.dup-warn__title { color: var(--amber-ink); font-weight: 600; margin-bottom: 4px; }
.dup-warn__text { font-size: 13.5px; color: var(--ink-2); }

/* ============================================================================
   TOAST + BOOT LOADER
   ========================================================================== */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: var(--radius);
  font-size: 13.5px; box-shadow: var(--shadow-pop); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 80; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: #7c352c; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 90; transition: opacity .3s ease; }
.boot.hide { opacity: 0; pointer-events: none; }
.boot__dot { width: 26px; height: 26px; border: 2px solid var(--border-strong); border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; }

/* ============================================================================
   RESPONSIVE — table collapses to cards
   ========================================================================== */
@media (max-width: 820px) {
  .topbar__inner, .page { padding-left: 18px; padding-right: 18px; }
  .field--inline, .field--inline .select { flex: 1; min-width: 0; width: 100%; }
  .controls__row--filters { gap: 10px; }
  .controls__row--filters .field--inline { flex-basis: calc(50% - 5px); }

  .table-wrap { border: none; background: transparent; overflow: visible; }
  .leads-table, .leads-table tbody, .leads-table tr, .leads-table td { display: block; width: 100%; }
  .leads-table thead { display: none; }
  .leads-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 12px; padding: 6px 4px;
  }
  .leads-table tbody tr:hover { background: var(--surface); }
  .leads-table td { border: none; padding: 9px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .leads-table td::before {
    content: attr(data-label); flex: 0 0 auto;
    font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3);
  }
  .leads-table td.col-num, .leads-table td.col-actions { justify-content: space-between; text-align: left; }
  .biz, .status-cell { align-items: flex-end; }
  .biz { text-align: right; }
  .leads-table td.cell-biz { border-bottom: 1px solid var(--border); padding-bottom: 13px; margin-bottom: 3px; }
  .form-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .controls__row { flex-wrap: wrap; }
  .controls__row .btn--primary { width: 100%; }
  .search { flex-basis: 100%; }
  .modal__head, .modal__body, .modal__foot { padding-left: 18px; padding-right: 18px; }
  .modal__foot .btn { flex: 1; }
}
