/* ============ CRĒO CRM — brand system ============
   Colours from CRĒO Brand Guide NOV25:
   Rose Pink #D0B6AD · Terracotta #B16243 · Brown #502A00
   Beige #E4DBCF · Deep Teal #004049 · Sky Blue #A3C4CA
   Fonts: Montserrat (headline/body) · PT Mono (captions, buttons)
================================================== */
:root {
  --teal: #004049;
  --teal-soft: #0a5560;
  --terracotta: #B16243;
  --terracotta-dark: #96502F;
  --brown: #502A00;
  --beige: #E4DBCF;
  --rose: #D0B6AD;
  --sky: #A3C4CA;
  --surface: #F7F3EC;        /* page background */
  --card: #FFFFFF;
  --ink: #23201B;
  --ink-2: #5C564C;
  --ink-3: #8B8478;
  --line: #E2D9CB;
  --good: #2E7D4F;
  --bad: #A63D3D;
  /* validated chart palette (brand hues snapped into data-colour band) */
  --c1: #0895A6;
  --c2: #B16243;
  --c3: #3E8CC7;
  --c4: #9A5A18;
  --c5: #C05F72;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(80, 42, 0, .08), 0 4px 16px rgba(80, 42, 0, .05);
  --font-head: 'Montserrat', system-ui, sans-serif;
  --font-body: 'Montserrat', system-ui, sans-serif;
  --font-mono: 'PT Mono', ui-monospace, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font-body); background: var(--surface); color: var(--ink); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 13px; }
a { color: var(--teal); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--teal); }
.login-card { background: var(--surface); border-radius: 16px; padding: 48px 44px; width: 380px; box-shadow: 0 24px 64px rgba(0,0,0,.35); }
.login-logo { font-family: var(--font-head); font-weight: 500; font-size: 34px; letter-spacing: .32em; color: var(--teal); text-align: center; margin-bottom: 4px; }
.login-sub { font-family: var(--font-mono); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--terracotta); text-align: center; margin-bottom: 32px; }
.login-card label { display: block; font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 14px 0 5px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.login-card input:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.login-error { color: var(--bad); font-size: 12px; margin-top: 12px; min-height: 16px; }
.btn-primary { width: auto; background: var(--teal); color: var(--beige); border: none; padding: 11px 22px; border-radius: 8px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; }
.btn-primary:hover { background: var(--teal-soft); }
.login-card .btn-primary { width: 100%; margin-top: 24px; }
.login-hint { margin-top: 18px; font-size: 11px; color: var(--ink-3); text-align: center; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 218px 1fr; min-height: 100vh; }
.sidebar { background: var(--teal); color: var(--beige); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-logo { font-family: var(--font-head); font-weight: 500; font-size: 22px; letter-spacing: .3em; padding: 26px 22px 4px; color: #fff; }
.side-tag { font-family: var(--font-mono); font-size: 9px; letter-spacing: .22em; text-transform: uppercase; padding: 0 22px 26px; color: var(--sky); }
.nav { flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 11px 22px; color: var(--beige); text-decoration: none; font-size: 13.5px; font-weight: 500; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(255,255,255,.10); border-left-color: var(--terracotta); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .85; }
.side-user { padding: 18px 22px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12.5px; }
.side-user .nm { font-weight: 600; color: #fff; }
.side-user button { background: none; border: none; color: var(--sky); font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 4px 0; }
.side-user button:hover { color: #fff; }

.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font-family: var(--font-head); font-weight: 600; font-size: 22px; color: var(--teal); letter-spacing: .01em; }
.page-head .sub { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .1em; margin-top: 3px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn { background: var(--card); border: 1px solid var(--line); color: var(--ink); padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.btn:hover { border-color: var(--teal); }
.btn.accent { background: var(--terracotta); border-color: var(--terracotta); color: #fff; }
.btn.accent:hover { background: var(--terracotta-dark); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }

select.ctl, input.ctl { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }
input.ctl:focus, select.ctl:focus { outline: 2px solid var(--sky); }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-title { font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); padding: 16px 18px 0; }
.card .card-body { padding: 14px 18px 18px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid #F0EAE0; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #FBF8F3; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl a { font-weight: 600; text-decoration: none; }
.tbl a:hover { text-decoration: underline; }
.muted { color: var(--ink-3); }
.right { text-align: right; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .04em; background: var(--beige); color: var(--brown); white-space: nowrap; }
.pill.won { background: #DDEBE2; color: var(--good); }
.pill.lost { background: #F0DCDC; color: var(--bad); }
.pill.teal { background: #D8E7E9; color: var(--teal); }
.pill.terra { background: #F0E0D8; color: var(--terracotta-dark); }

/* ---------- Task preset chips ---------- */
.tchips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tchip { background: var(--card); border: 1px solid var(--line); color: var(--ink-2); padding: 7px 13px; border-radius: 99px; font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.tchip:hover { border-color: var(--teal); }
.tchip.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.tchip-n { font-family: var(--font-mono); font-size: 10.5px; background: var(--beige); color: var(--brown); border-radius: 99px; padding: 1px 7px; min-width: 14px; text-align: center; }
.tchip.active .tchip-n { background: rgba(255, 255, 255, .22); color: #fff; }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile .t-label { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-2); }
.tile .t-value { font-family: var(--font-head); font-weight: 600; font-size: 30px; color: var(--teal); margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .t-foot { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }
.tile.accent .t-value { color: var(--terracotta); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-2 > .card { min-width: 0; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }

/* ---------- Kanban ---------- */
/* Fixed-height board: columns scroll internally so the horizontal scrollbar is always in view */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; align-items: stretch; height: calc(100vh - 160px); min-height: 320px; }
.kcol { min-width: 250px; width: 250px; flex: 0 0 auto; background: #EFE8DC; border-radius: var(--radius); border: 1px solid var(--line); display: flex; flex-direction: column; max-height: 100%; }
.kcol-head { padding: 12px 14px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kcol-head .nm { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--brown); font-weight: 700; }
.kcol-head .ct { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
.kcol-sum { padding: 0 14px 8px; font-size: 11.5px; color: var(--terracotta-dark); font-weight: 600; font-variant-numeric: tabular-nums; }
.kcol-body { min-height: 60px; padding: 6px 8px 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.kcol.drag-over { outline: 2px dashed var(--terracotta); outline-offset: -4px; }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(80,42,0,.06); }
.kcard:active { cursor: grabbing; }
.kcard .knm { font-weight: 600; font-size: 13px; color: var(--teal); }
.kcard .kmeta { font-size: 11.5px; color: var(--ink-2); margin-top: 4px; line-height: 1.5; }
.kcard .kamt { font-family: var(--font-mono); font-size: 12px; color: var(--terracotta-dark); margin-top: 4px; }
.kcard.dragging { opacity: .4; }

/* ---------- Detail pages ---------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field-grid .full { grid-column: 1 / -1; }
.fld label { display: block; font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-2); margin-bottom: 4px; }
.fld input, .fld select, .fld textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: 2px solid var(--sky); }
.fld .checkbox-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; }
.fld .checkbox-row input { width: auto; }
.stagebar { display: flex; gap: 4px; margin: 4px 0 18px; flex-wrap: wrap; }
.stagebar .st { flex: 1; min-width: 70px; text-align: center; font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .02em; text-transform: uppercase; padding: 7px 4px; background: var(--beige); color: var(--brown); cursor: pointer; border: none; border-radius: 4px; }
.stagebar .st.done { background: var(--sky); color: var(--teal); }
.stagebar .st.current { background: var(--teal); color: #fff; font-weight: 700; }
.stagebar .st.won-current { background: var(--good); color: #fff; }
.stagebar .st.lost-current { background: var(--bad); color: #fff; }

/* ---------- Autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 40; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; }
.ac-item { padding: 9px 12px; cursor: pointer; font-size: 13px; }
.ac-item:hover, .ac-item.sel { background: var(--beige); }
.ac-item .sub { font-size: 11px; color: var(--ink-3); }
.ac-new { color: var(--terracotta); font-weight: 600; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(35,32,27,.45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; padding: 26px 28px; width: 620px; max-width: 100%; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal h2 { font-family: var(--font-head); font-size: 17px; color: var(--teal); margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--teal); color: var(--beige); padding: 12px 18px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); animation: fadein .2s; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---------- Settings ---------- */
.stage-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.stage-row input[type=text] { flex: 1; }
.stage-row select { width: 90px; }
.pipe-block { margin-bottom: 22px; }
.pipe-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.pipe-head input { font-size: 15px; font-weight: 600; }

/* ---------- Deal notes timeline ---------- */
.note-row { padding: 10px 0; border-bottom: 1px solid #F0EAE0; }
.note-row:last-child { border-bottom: none; }
.note-head { display: flex; align-items: center; gap: 10px; font-size: 12px; margin-bottom: 3px; }
.note-head .muted { font-family: var(--font-mono); font-size: 10.5px; }
.note-head .note-del { margin-left: auto; opacity: 0; padding: 2px 7px; }
.note-row:hover .note-del { opacity: 1; }
.note-body { font-size: 13px; line-height: 1.55; white-space: pre-wrap; }

/* ---------- Quotes & invoices ---------- */
.doc-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #F0EAE0; font-size: 13px; }
.doc-row a { text-decoration: none; }
.doc-row .num { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.doc-page { max-width: 860px; margin: 0 auto; padding: 26px 20px 60px; }
.doc-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.doc-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 44px 48px; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--teal); padding-bottom: 18px; margin-bottom: 18px; }
.doc-logo { font-family: var(--font-head); font-weight: 500; font-size: 30px; letter-spacing: .3em; color: var(--teal); }
.doc-sub { font-family: var(--font-mono); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--terracotta); }
.doc-kind { font-family: var(--font-mono); font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-2); }
.doc-num { font-family: var(--font-head); font-weight: 600; font-size: 22px; color: var(--teal); }
.doc-meta { font-size: 13px; line-height: 2; margin-bottom: 18px; }
.doc-table th { background: #FBF8F3; }
.doc-totals { margin-top: 16px; margin-left: auto; width: 280px; font-size: 13.5px; }
.doc-totals > div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #F0EAE0; }
.doc-totals .grand { font-size: 16px; font-weight: 700; color: var(--teal); border-bottom: 2px solid var(--teal); }
.doc-notes { margin-top: 24px; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.doc-terms { margin-top: 20px; font-size: 9.5px; line-height: 1.5; color: var(--ink-2); white-space: pre-wrap; }
.doc-section-title { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--terracotta-dark); border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 6px; white-space: normal; }
.doc-company { font-size: 11px; color: var(--ink-2); margin-top: 8px; line-height: 1.5; white-space: pre-wrap; }
@media print {
  .no-print, .sidebar { display: none !important; }
  body { background: #fff; }
  .doc-page { padding: 0; max-width: none; }
  .doc-sheet { border: none; box-shadow: none; border-radius: 0; padding: 0; }
}

.empty { padding: 40px; text-align: center; color: var(--ink-3); font-size: 13px; }
.loading { padding: 40px; text-align: center; color: var(--ink-3); font-family: var(--font-mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.list-tools { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 0; }
