@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --ink: #12172B;
  --ink-soft: #2A3150;
  --paper: #F7F5F0;
  --paper-dim: #EDEAE2;
  --line: #DCD8CC;
  --amber: #F2A93B;
  --amber-dim: #FBE8C4;
  --slate: #5B6478;
  --good: #2FA88A;
  --bad: #E4573D;
  --radius: 10px;
  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 36px 32px;
}
.login-brand {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px;
}
.login-brand span { color: var(--amber); }
.login-sub {
  color: var(--slate);
  font-size: 14px;
  margin: 0 0 28px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--amber); }
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 15px;
  margin-top: 6px;
}
.btn-primary:hover { background: var(--ink-soft); }
.form-error {
  color: var(--bad);
  font-size: 13px;
  margin: -8px 0 14px;
  min-height: 16px;
}
.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--slate);
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

/* ---------- App shell ---------- */
#app-screen { display: none; min-height: 100vh; }
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--ink);
  color: var(--paper);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 2px 8px;
}
.brand span { color: var(--amber); }
.brand-sub { font-size: 11px; color: #8B93AD; margin: 0 0 28px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 8px;
  background: none;
  border: none;
  color: #C7CBDA;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.4; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--amber); color: var(--ink); font-weight: 600; }
.nav-item.active .dot { opacity: 1; }
.sidebar-footer {
  position: absolute;
  bottom: 24px;
  left: 16px;
  right: 16px;
  font-size: 12px;
  color: #8B93AD;
}
.sidebar-footer button {
  background: none;
  border: none;
  color: #C7CBDA;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
}

.main { padding: 28px 32px 60px; max-width: 1180px; }
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 26px;
}
.page-title { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin: 0; }
.page-sub { color: var(--slate); font-size: 14px; margin: 4px 0 0; }
.range-select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-family: var(--font-body);
}

/* Ledger metric cards */
.ledger-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}
.ledger-cell {
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}
.ledger-cell:last-child { border-right: none; }
.ledger-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate);
  margin: 0 0 8px;
}
.ledger-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  margin: 0;
}
.ledger-value.good { color: var(--good); }
.ledger-value.bad { color: var(--bad); }
.ledger-delta { font-size: 12px; color: var(--slate); margin-top: 4px; }

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.panel-title { font-size: 15px; font-weight: 600; margin: 0; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-footer { position: static; margin-top: 20px; }
  .two-col { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 60px; }
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate);
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
}
table.data-table td { padding: 9px 6px; border-bottom: 1px solid var(--paper-dim); font-family: var(--font-mono); }
table.data-table td.text { font-family: var(--font-body); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-body);
}
.badge.new { background: var(--amber-dim); color: #8A5A00; }
.badge.in_progress { background: #DCE6FF; color: #2A4FB8; }
.badge.resolved { background: #DCF3EA; color: #1E7A5F; }
.badge.urgent { background: #FBDCD4; color: #B23A22; }
.badge.normal { background: var(--paper-dim); color: var(--slate); }
.badge.low { background: var(--paper-dim); color: var(--slate); }
.badge.contacted { background: var(--paper-dim); color: var(--slate); }
.badge.negotiation { background: #DCE6FF; color: #2A4FB8; }
.badge.offer_sent { background: var(--amber-dim); color: #8A5A00; }
.badge.closed { background: #DCF3EA; color: #1E7A5F; }
.badge.in_review { background: #DCE6FF; color: #2A4FB8; }
.badge.converted { background: #DCF3EA; color: #1E7A5F; }
.badge.draft { background: var(--paper-dim); color: var(--slate); }
.badge.sent { background: #DCE6FF; color: #2A4FB8; }
.badge.paid { background: #DCF3EA; color: #1E7A5F; }
.badge.overdue { background: #FBDCD4; color: #B23A22; }
.badge.qualified { background: var(--amber-dim); color: #8A5A00; }
.badge.lost { background: #FBDCD4; color: #B23A22; }

.btn-small {
  padding: 7px 12px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.btn-small:hover { background: var(--ink-soft); }
.btn-ghost {
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  font-size: 12px;
}
.btn-ghost:hover { border-color: var(--slate); }

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(18,23,43,0.5);
  align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 26px;
  width: 100%; max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-family: var(--font-display); margin: 0 0 18px; font-size: 19px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn-ghost, .modal-actions .btn-small { flex: 1; text-align: center; }

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--slate);
  font-size: 13.5px;
}

.chart-wrap { position: relative; height: 220px; }

.toast {
  position: fixed;
  bottom: 20px; right: 20px;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  z-index: 100;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: start; }
.kanban-col { background: var(--paper-dim); border-radius: 8px; padding: 12px; min-height: 80px; }
.kanban-col-head { display:flex; justify-content:space-between; align-items:center; font-size:12px; font-weight:600; text-transform:uppercase; letter-spacing:0.04em; color:var(--slate); margin-bottom:10px; }
.kanban-card { background:#fff; border:1px solid var(--line); border-radius:7px; padding:10px 12px; margin-bottom:8px; font-size:13px; }
.kanban-card .kc-amount { font-family: var(--font-mono); font-weight:600; margin-top:4px; }
.kanban-card select { width:100%; margin-top:8px; font-size:12px; padding:4px; border-radius:5px; border:1px solid var(--line); font-family: var(--font-body); }
@media (max-width: 860px) { .kanban { grid-template-columns: 1fr; } }

/* Customer list / detail */
.customer-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap:12px; }
.customer-card { background:#fff; border:1px solid var(--line); border-radius:8px; padding:14px 16px; cursor:pointer; }
.customer-card:hover { border-color: var(--amber); }
.customer-card h4 { margin:0 0 3px; font-size:14.5px; }
.customer-card p { margin:0; font-size:12.5px; color:var(--slate); }
.back-link { background:none; border:none; color:var(--slate); font-size:13px; padding:0; margin-bottom:14px; text-decoration:underline; }
.detail-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:20px; flex-wrap:wrap; gap:10px; }
.detail-header h2 { font-family:var(--font-display); font-size:22px; margin:0 0 4px; }
.detail-meta { font-size:13px; color:var(--slate); }
.tag-chip { display:inline-block; background:var(--amber-dim); color:#8A5A00; font-size:11px; padding:2px 8px; border-radius:20px; margin-right:4px; }
.mini-section-title { font-size:13px; font-weight:600; margin: 18px 0 8px; color:var(--ink-soft); }

/* Invoice preview */
.invoice-preview { border:1px solid var(--line); border-radius:8px; padding:20px; background:#fff; }
.invoice-preview .inv-head { display:flex; justify-content:space-between; margin-bottom:16px; }
.invoice-preview .inv-total-row td { font-weight:700; font-family:var(--font-mono); border-top:2px solid var(--ink); }

.field textarea { width:100%; padding:11px 12px; border:1px solid var(--line); border-radius:6px; background:#fff; font-family:var(--font-body); font-size:14px; resize:vertical; min-height:70px; }
.note-item { padding:10px 0; border-bottom:1px solid var(--paper-dim); font-size:13.5px; }
.note-item .note-meta { font-size:11px; color:var(--slate); margin-bottom:3px; }
.line-item-row { display:grid; grid-template-columns: 2fr 0.7fr 0.9fr auto; gap:8px; align-items:center; margin-bottom:8px; }
.line-item-row input { padding:8px; border:1px solid var(--line); border-radius:6px; font-size:13.5px; }
.icon-btn { background:none; border:none; color: var(--bad); font-size: 18px; line-height:1; padding: 0 6px; }
