/* ============ Studio CRM ============ */
:root {
  --paper: #FAF7F1;
  --paper-2: #F3EEE4;
  --card: #FFFFFF;
  --ink: #1C1A16;
  --ink-soft: #5C574D;
  --ink-faint: #8B857A;
  --line: #E5DFD2;
  --green: #173B2C;
  --green-soft: #E4EDE6;
  --gold: #B08A3C;
  --red: #A8352C;
  --red-soft: #F6E4E2;
  --amber-soft: #F4EBD6;
  --blue-soft: #E3EAF2;
  --blue: #2C4A6E;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28,26,22,.05), 0 4px 16px rgba(28,26,22,.06);
  --font-ui: 'Albert Sans', system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --bar-rev: #173B2C;
  --bar-cnt: #B08A3C;
}

/* ---------- dark theme ---------- */
:root[data-theme="dark"] {
  --paper: #131110;
  --paper-2: #221F1A;
  --card: #1B1917;
  --ink: #EDE7DB;
  --ink-soft: #B3AC9E;
  --ink-faint: #837D70;
  --line: #34302A;
  --green-soft: #22352A;
  --gold: #C69A4B;
  --red: #E06B5F;
  --red-soft: #3D2320;
  --amber-soft: #37301D;
  --blue-soft: #202B39;
  --blue: #8FB3D9;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --bar-rev: #5E9C79;
}
:root[data-theme="dark"] .badge.s-delivered, :root[data-theme="dark"] .badge.pay-paid, :root[data-theme="dark"] .badge.i-paid,
:root[data-theme="dark"] .status-select.s-delivered { color: #8FC7A6; }
:root[data-theme="dark"] .badge.s-inreview, :root[data-theme="dark"] .badge.i-partial, :root[data-theme="dark"] .badge.pay-partial,
:root[data-theme="dark"] .badge.r-paused, :root[data-theme="dark"] .status-select.s-inreview { color: #D9B36A; }
:root[data-theme="dark"] .badge.r-active { color: #8FC7A6; }
:root[data-theme="dark"] .badge.s-lead, :root[data-theme="dark"] .status-select.s-lead { background-color: #38222D; color: #E094BD; }
:root[data-theme="dark"] .badge.s-onhold, :root[data-theme="dark"] .status-select.s-onhold { background-color: #2C2433; color: #C5A3DC; }
:root[data-theme="dark"] .btn-primary { background: #2A5A43; border-color: #2A5A43; }
:root[data-theme="dark"] .btn-primary:hover { background: #336C50; border-color: #336C50; }
:root[data-theme="dark"] .chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* the invoice is a paper document: it keeps its light palette in every theme (and in print) */
.invoice-doc {
  --ink: #1C1A16;
  --ink-soft: #5C574D;
  --ink-faint: #8B857A;
  --line: #E5DFD2;
  --green: #173B2C;
  --green-soft: #E4EDE6;
  --blue: #2C4A6E;
  background: #FFFFFF;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; }
button { font-family: inherit; }

.layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 248px; flex-shrink: 0;
  background: #14120E;
  color: #EFEAE0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--green); color: #F5EFE2;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 20px; font-weight: 600;
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: var(--font-display); font-size: 17px; font-weight: 500; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: rgba(239,234,224,.55); }
.nav { display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  text-decoration: none; color: rgba(239,234,224,.72);
  font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .8; font-size: 13px; }
.sidebar-foot { padding: 14px 20px; font-size: 11px; color: rgba(239,234,224,.4); border-top: 1px solid rgba(255,255,255,.08); }

/* ---------- main ---------- */
.main { flex: 1; padding: 34px 40px 60px; max-width: 1200px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-size: 30px; font-weight: 500; margin: 0; letter-spacing: -0.01em; }
.page-sub { color: var(--ink-soft); font-size: 14px; margin: 4px 0 0; }
.head-actions { display: flex; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--ink-faint); }
.btn-primary { background: var(--green); border-color: var(--green); color: #F5EFE2; }
.btn-primary:hover { background: #1E4A38; border-color: #1E4A38; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: var(--red-soft); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--paper-2); border-color: transparent; }

/* ---------- cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); }
.stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 500; margin-top: 6px; }
.stat-note { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-title { font-family: var(--font-display); font-size: 18px; font-weight: 500; margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-faint); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.rowlink { cursor: pointer; transition: background .12s; }
tbody tr.rowlink:hover { background: var(--paper-2); }
td .sub { display: block; font-size: 12.5px; color: var(--ink-faint); }
.t-right { text-align: right; }
.empty { padding: 34px; text-align: center; color: var(--ink-faint); font-size: 14px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.s-lead { background: #F6E4EC; color: #93365F; }
.badge.s-backlog { background: var(--paper-2); color: var(--ink-soft); }
.badge.s-inprogress { background: var(--blue-soft); color: var(--blue); }
.badge.s-inreview { background: var(--amber-soft); color: #7A5A17; }
.badge.s-delivered { background: var(--green-soft); color: var(--green); }
.badge.s-onhold { background: #EEE7F2; color: #5B3A6E; }
.badge.s-cancelled { background: var(--paper-2); color: var(--ink-faint); text-decoration: line-through; }
.badge.pay-paid { background: var(--green-soft); color: var(--green); }
.badge.pay-partial { background: var(--amber-soft); color: #7A5A17; }
.badge.pay-unpaid { background: var(--red-soft); color: var(--red); }
.badge.pay-none { background: var(--paper-2); color: var(--ink-faint); }
.badge.i-draft { background: var(--paper-2); color: var(--ink-soft); }
.badge.i-sent { background: var(--blue-soft); color: var(--blue); }
.badge.i-paid { background: var(--green-soft); color: var(--green); }
.badge.i-partial { background: var(--amber-soft); color: #7A5A17; }
.badge.r-active { background: var(--green-soft); color: var(--green); }
.badge.r-paused { background: var(--amber-soft); color: #7A5A17; }
.badge.r-cancelled { background: var(--paper-2); color: var(--ink-faint); }
.badge.i-overdue { background: var(--red-soft); color: var(--red); }
.due-late { color: var(--red); font-weight: 600; }
.due-soon { color: #9A6E14; font-weight: 600; }

/* ---------- kanban board ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.board-col { min-width: 232px; width: 232px; flex-shrink: 0; background: var(--paper-2); border-radius: var(--radius); padding: 10px; }
.board-col.drop { outline: 2px dashed var(--green); outline-offset: -2px; }
.board-col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 0 2px; }
.board-count { font-size: 12px; color: var(--ink-faint); font-weight: 600; }
.board-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.board-card:hover { border-color: var(--ink-faint); }
.board-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.board-sub { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 8px; }
.board-meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; gap: 8px; }
.board-due { margin-top: 7px; font-size: 12px; }
.board-empty { text-align: center; color: var(--ink-faint); padding: 8px 0 4px; font-size: 13px; }

/* ---------- clickable stat cards ---------- */
.stat-card.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.stat-card.clickable:hover { border-color: var(--ink-faint); transform: translateY(-1px); }

/* ---------- quick search ---------- */
.search-overlay { position: fixed; inset: 0; background: rgba(20,18,14,.5); z-index: 300; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 20px 20px; backdrop-filter: blur(2px); }
.search-box { background: var(--paper); border-radius: 14px; width: 100%; max-width: 540px; box-shadow: 0 24px 60px rgba(0,0,0,.35); overflow: hidden; }
.search-box input { border: none; border-bottom: 1px solid var(--line); border-radius: 0; padding: 16px 18px; font-size: 16px; background: var(--paper); }
.search-box input:focus { outline: none; border-color: var(--line); }
.search-results { max-height: 320px; overflow-y: auto; }
.search-item { display: flex; align-items: center; gap: 10px; padding: 11px 16px; cursor: pointer; }
.search-item:hover, .search-item.sel { background: var(--paper-2); }
.search-type { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ink-faint); width: 54px; flex-shrink: 0; }
.search-label { font-weight: 600; font-size: 14px; }
.search-sub { font-size: 12.5px; color: var(--ink-faint); margin-left: auto; text-align: right; }
.search-hint { padding: 8px 16px; font-size: 11.5px; color: var(--ink-faint); border-top: 1px solid var(--line); }

/* ---------- sidebar search button ---------- */
.nav-search { display: flex; align-items: center; gap: 8px; margin: 12px 10px 0; padding: 9px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.05); color: rgba(239,234,224,.72); font-size: 13.5px; cursor: pointer; width: calc(100% - 20px); font-family: inherit; }
.nav-search:hover { background: rgba(255,255,255,.1); color: #fff; }
.kbd { margin-left: auto; font-size: 10.5px; border: 1px solid rgba(255,255,255,.2); padding: 1px 6px; border-radius: 5px; }

/* ---------- inline status dropdown ---------- */
.status-select {
  appearance: none; -webkit-appearance: none;
  border: none; border-radius: 99px; width: auto; cursor: pointer;
  padding: 4px 24px 4px 12px; font-size: 12px; font-weight: 600; font-family: inherit;
  background-color: var(--paper-2); color: var(--ink-soft);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238B857A' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 9px;
}
.status-select:focus { outline: 2px solid rgba(23,59,44,.25); }
.status-select.s-lead { background-color: #F6E4EC; color: #93365F; }
.status-select.s-backlog { background-color: var(--paper-2); color: var(--ink-soft); }
.status-select.s-inprogress { background-color: var(--blue-soft); color: var(--blue); }
.status-select.s-inreview { background-color: var(--amber-soft); color: #7A5A17; }
.status-select.s-delivered { background-color: var(--green-soft); color: var(--green); }
.status-select.s-onhold { background-color: #EEE7F2; color: #5B3A6E; }
.status-select.s-cancelled { background-color: var(--paper-2); color: var(--ink-faint); }

/* ---------- filters ---------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input[type=search] { min-width: 220px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-soft);
}
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- forms ---------- */
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(23,59,44,.25); border-color: var(--green); }
textarea { resize: vertical; min-height: 90px; }
label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- modal ---------- */
.modal-backdrop[hidden], .toast[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,18,14,.5);
  display: grid; place-items: center; z-index: 50; padding: 24px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--paper); border-radius: 14px; width: 100%; max-width: 620px;
  max-height: 88vh; overflow-y: auto; padding: 26px 28px;
  box-shadow: 0 24px 60px rgba(20,18,14,.35);
}
.modal h2 { font-family: var(--font-display); font-weight: 500; font-size: 22px; margin: 0 0 18px; }

/* ---------- login ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--paper);
  display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 40px 44px; width: 100%; max-width: 380px;
  text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-card h2 { font-family: var(--font-display); font-weight: 500; font-size: 24px; margin: 0; }
.login-card p { margin: 0 0 6px; font-size: 14px; color: var(--ink-soft); }
.login-mark { width: 46px; height: 46px; font-size: 24px; margin: 0 auto 4px; border-radius: 12px; background: var(--green); color: #F5EFE2; display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; }
.login-err { color: var(--red); font-size: 13px; font-weight: 600; min-height: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 11px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500; z-index: 100; box-shadow: var(--shadow);
}
.toast.err { background: var(--red); }

/* ---------- project detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 14px; }
.meta-list dt { color: var(--ink-faint); font-weight: 500; }
.meta-list dd { margin: 0; font-weight: 500; }
.desc { white-space: pre-wrap; font-size: 14.5px; color: var(--ink-soft); }
.link-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.link-list li { display: flex; align-items: center; gap: 8px; }
.link-list a { color: var(--blue); font-weight: 500; word-break: break-all; }
.file-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.file-list a { font-weight: 500; text-decoration: none; flex: 1; word-break: break-all; }
.file-list a:hover { text-decoration: underline; }
.file-size { font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.file-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); flex-shrink: 0; }
.icon-x { border: none; background: none; cursor: pointer; color: var(--ink-faint); font-size: 15px; padding: 2px 6px; border-radius: 6px; }
.icon-x:hover { color: var(--red); background: var(--red-soft); }
.dropzone {
  border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center;
  color: var(--ink-faint); font-size: 13.5px; cursor: pointer; transition: all .15s; margin-top: 12px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.crumb { font-size: 13px; color: var(--ink-faint); margin-bottom: 6px; }
.crumb a { color: var(--ink-faint); text-decoration: none; }
.crumb a:hover { color: var(--ink); }

/* ---------- chart ---------- */
.chart-legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--ink-soft); margin-top: 8px; }
.chart-legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.chart-legend .lg-rev::before { background: var(--green); }
.chart-legend .lg-cnt::before { background: var(--gold); }

/* ---------- invoice items editor ---------- */
.items-editor { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 70px 110px 32px; gap: 8px; align-items: center; }
.items-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 600; }
.items-total { text-align: right; font-weight: 700; font-size: 16px; margin-top: 10px; font-family: var(--font-display); }

/* ---------- invoice document ---------- */
.invoice-doc {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 48px 54px; max-width: 820px;
}
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; }
.inv-brand { font-family: var(--font-display); font-size: 26px; font-weight: 600; }
.inv-brand-sub { font-size: 13px; color: var(--ink-soft); white-space: pre-line; margin-top: 6px; }
.inv-label { font-family: var(--font-display); font-size: 34px; font-weight: 500; color: var(--green); text-align: right; }
.inv-number { text-align: right; font-size: 14px; color: var(--ink-soft); margin-top: 4px; }
.inv-meta { display: flex; justify-content: space-between; margin-bottom: 36px; gap: 30px; }
.inv-meta h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin: 0 0 6px; }
.inv-meta p { margin: 0; font-size: 14.5px; white-space: pre-line; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.inv-table th { border-bottom: 2px solid var(--ink); color: var(--ink); padding: 10px 8px; }
.inv-table td { padding: 12px 8px; border-bottom: 1px solid var(--line); }
.inv-totals { display: flex; justify-content: flex-end; }
.inv-totals table td { border: none; padding: 6px 8px; font-size: 15px; }
.inv-grand { font-family: var(--font-display); font-size: 22px; font-weight: 600; border-top: 2px solid var(--ink) !important; }
.inv-terms { margin-top: 30px; border-top: 1px solid var(--line); padding-top: 16px; }
.inv-terms h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin: 0 0 5px; }
.inv-terms p { margin: 0; font-size: 14px; font-weight: 500; }
.inv-notes { margin-top: 34px; font-size: 13.5px; color: var(--ink-soft); white-space: pre-line; border-top: 1px solid var(--line); padding-top: 18px; }
.inv-terms + .inv-notes { margin-top: 18px; border-top: none; padding-top: 0; }
.inv-paid-stamp {
  position: absolute; top: 90px; right: 60px; transform: rotate(-12deg);
  border: 3px solid var(--green); color: var(--green); font-weight: 800; font-size: 26px;
  padding: 6px 22px; border-radius: 8px; letter-spacing: .15em; opacity: .8;
}
.invoice-doc { position: relative; }

@media print {
  /* zero page margins so the browser cannot stamp its date/title/URL header and footer */
  @page { margin: 0; }
  .sidebar, .page-head, .no-print, .toast { display: none !important; }
  .main { padding: 0; max-width: none; }
  .invoice-doc { border: none; box-shadow: none; padding: 18mm 16mm; max-width: none; }
  body { background: #fff; }
}
