/* ── Lelocom Admin ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f4f9f6;
  --card:      #ffffff;
  --border:    #e3ece7;
  --border-h:  rgba(34, 197, 94, 0.5);
  --green:     #16a34a;
  --green-l:   #22c55e;
  --green-d:   #15803d;
  --green-dim: rgba(34, 197, 94, 0.10);
  --text:      #111827;
  --muted:     #6b7280;
  --muted-l:   #4b5563;
  --amber:     #b45309;
  --amber-bg:  #fef3c7;
  --red:       #dc2626;
  --red-bg:    #fee2e2;
  --radius:    14px;
  --shadow:    0 1px 3px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.04);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green-d); text-decoration: none; }
a:hover { text-decoration: underline; }
.logo-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); display: inline-block; }
.mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.muted { color: var(--muted); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── Auth pages ── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 40px; width: 100%; max-width: 400px; }
.auth-logo { font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 9px; margin-bottom: 24px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.sb-logo-tag, .auth-logo .sb-logo-tag { background: var(--green-dim); color: var(--green-d); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 3px 7px; border-radius: 6px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ── Shell ── */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh;
}
.sb-logo { font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 9px; color: var(--text); padding: 0 8px 20px; }
.sb-logo:hover { text-decoration: none; }
.sb-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.sb-nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--muted-l); font-weight: 500; font-size: 14.5px; }
.sb-nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sb-nav a.active { background: var(--green-dim); color: var(--green-d); font-weight: 600; }
.sb-ic { width: 18px; text-align: center; font-size: 14px; opacity: .85; }
.sb-foot { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.sb-user { font-weight: 600; font-size: 14px; padding: 0 8px 4px; }
.sb-foot a { font-size: 13px; padding: 4px 8px; color: var(--muted); }
.sb-logout { color: var(--red) !important; }

.content { flex: 1; padding: 30px 38px; max-width: 1200px; }

/* ── Topbar ── */
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 26px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; padding: 9px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; transition: .15s; font-family: inherit; }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-l); }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--border-h); }
.btn-danger-ghost { background: transparent; border-color: var(--border); color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-bg); border-color: var(--red); }
.btn-block { width: 100%; justify-content: center; margin-top: 10px; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }

/* ── Flash ── */
.flash { padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 18px; }
.flash-success { background: var(--green-dim); color: var(--green-d); border: 1px solid var(--border-h); }
.flash-error { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }

/* ── Stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-k { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-v { font-size: 26px; font-weight: 800; margin: 6px 0 2px; }
.stat-v.green { color: var(--green-d); }
.stat-v.amber { color: var(--amber); }
.stat-note { font-size: 12.5px; color: var(--muted); }

/* ── Panels ── */
.panel-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.invoice-grid { grid-template-columns: 1.7fr 1fr; }
.docs-grid { grid-template-columns: 360px 1fr; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; font-weight: 700; }
.panel-head a { font-size: 13px; font-weight: 600; }
.empty-panel { text-align: center; padding: 48px 20px; }
.empty { color: var(--muted); font-size: 14px; margin-bottom: 14px; }

/* ── Tables ── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 0 12px 10px; border-bottom: 1px solid var(--border); }
.table th.r { text-align: right; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--bg); }

/* ── Pills ── */
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: capitalize; }
.pill-unpaid { background: var(--amber-bg); color: var(--amber); }
.pill-paid { background: var(--green-dim); color: var(--green-d); }
.pill-cancelled { background: #f1f5f9; color: var(--muted); }
.pill-due { background: var(--green-dim); color: var(--green-d); }
.pill-overdue { background: var(--red-bg); color: var(--red); }
.pill-draft { background: #f1f5f9; color: var(--muted); }
.pill-sent { background: var(--amber-bg); color: var(--amber); }
.pill-accepted { background: var(--green-dim); color: var(--green-d); }
.pill-declined { background: var(--red-bg); color: var(--red); }
.pill-expired { background: #f1f5f9; color: var(--muted); }

/* ── Quote status actions ── */
.status-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.soft-rule { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Client ledger ── */
.ledger-stats { grid-template-columns: repeat(3, 1fr); }
.table td.owing { color: var(--amber); font-weight: 700; }
.table td .credit, .table td.credit { color: var(--green-d); }
.table tfoot td { border-top: 2px solid var(--border-h); background: var(--bg); padding: 12px; }
.table tfoot tr.ledger-foot td { border-bottom: none; }

/* ── DB admin ── */
.dbadmin-grid { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.dbadmin-tables { position: sticky; top: 18px; }
.dbadmin-tablelist { list-style: none; }
.dbadmin-tablelist li { margin: 0; }
.dbadmin-tablelist a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; font-size: 13px; color: var(--text); }
.dbadmin-tablelist a:hover { background: var(--bg); text-decoration: none; }
.dbadmin-tablelist a.active { background: var(--green-dim); color: var(--green-d); }
.dbadmin-main { display: grid; gap: 18px; min-width: 0; }
.sql-box { width: 100%; font-size: 13px; line-height: 1.5; resize: vertical; }
.sql-error { background: var(--red-bg); color: var(--red); padding: 12px 14px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.table.compact th, .table.compact td { padding: 7px 10px; font-size: 12.5px; white-space: nowrap; }
@media (max-width: 760px) { .dbadmin-grid { grid-template-columns: 1fr; } .dbadmin-tables { position: static; } }
.tag-chip { background: var(--bg); border: 1px solid var(--border); font-size: 12px; padding: 3px 9px; border-radius: 7px; color: var(--muted-l); }

/* ── Filter tabs ── */
.filter-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.filter-tabs a { padding: 7px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--muted-l); background: var(--card); border: 1px solid var(--border); }
.filter-tabs a:hover { text-decoration: none; border-color: var(--border-h); }
.filter-tabs a.active { background: var(--green); color: #fff; border-color: var(--green); }

/* ── Forms ── */
.form-panel { max-width: 760px; }
.fg { margin-bottom: 16px; }
.fg label, .block-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.block-label { margin-top: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; color: var(--text); background: #fff; transition: .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-dim); }
textarea { resize: vertical; }
.form-section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.form-section:first-child { margin-top: 0; }

/* ── Key/value lists ── */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; font-size: 14px; margin-bottom: 16px; }
.kv-tight { grid-template-columns: 90px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { color: var(--text); }

/* ── Line items editor ── */
.line-items { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.line-items th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 4px 8px; }
.line-items th.qty, .line-items th.price, .line-items th.amt { text-align: right; }
.line-items .qty { width: 80px; }
.line-items .price { width: 130px; }
.line-items .amt { width: 110px; text-align: right; padding-right: 8px; }
.line-items td { padding: 4px; vertical-align: middle; }
.line-amount { font-weight: 600; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.line-remove { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 6px 8px; border-radius: 6px; }
.line-remove:hover { background: var(--red-bg); color: var(--red); }

.invoice-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; margin: 18px 0; padding-top: 16px; border-top: 1px solid var(--border); }
.vat-fg { width: 150px; margin-bottom: 0; }
.totals-preview { min-width: 230px; font-size: 14px; }
.totals-preview > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-preview b { font-family: 'JetBrains Mono', monospace; }
.totals-preview .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; font-size: 17px; }
.totals-preview .grand b { color: var(--green-d); }

/* ── Invoice detail ── */
.items-table { margin: 14px 0; }
.totals-box { margin-left: auto; max-width: 280px; font-size: 14px; }
.totals-box > div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals-box b { font-family: 'JetBrains Mono', monospace; }
.totals-box .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 9px; font-size: 18px; }
.totals-box .grand b { color: var(--green-d); }
.invoice-notes { margin-top: 16px; font-size: 14px; color: var(--muted-l); background: var(--bg); padding: 12px 14px; border-radius: 10px; }
.paid-box { text-align: left; }
.paid-tick { display: inline-block; background: var(--green-dim); color: var(--green-d); font-weight: 700; padding: 6px 14px; border-radius: 999px; margin-bottom: 14px; }

/* ── Doc mini list (dashboard) ── */
.doc-mini { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.doc-mini li { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.doc-mini-title { font-weight: 500; }
.doc-file { font-size: 12.5px; margin-top: 2px; }

@media (max-width: 1000px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid, .invoice-grid, .docs-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .content { padding: 20px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ── Markdown report view ── */
.md-view { font-size: 14.5px; line-height: 1.6; color: var(--text); max-width: 820px; }
.md-view h1 { font-size: 24px; font-weight: 800; margin: 4px 0 12px; }
.md-view h2 { font-size: 19px; font-weight: 700; margin: 26px 0 8px; color: var(--green-d); }
.md-view h3 { font-size: 15.5px; font-weight: 700; margin: 18px 0 6px; }
.md-view p { margin: 0 0 12px; }
.md-view ul, .md-view ol { margin: 0 0 14px; padding-left: 22px; }
.md-view li { margin: 4px 0; }
.md-view blockquote { margin: 0 0 14px; padding: 8px 14px; border-left: 3px solid var(--green);
  background: var(--green-dim); color: var(--muted-l); border-radius: 0 8px 8px 0; }
.md-view hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.md-view code { background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 5px; font-size: 12.5px; font-family: 'JetBrains Mono', monospace; }
.md-view .md-table { width: 100%; border-collapse: collapse; margin: 6px 0 18px; font-size: 13px; }
.md-view .md-table th { background: var(--green); color: #fff; text-align: left;
  padding: 8px 10px; font-weight: 600; }
.md-view .md-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.md-view .md-table tr:nth-child(even) td { background: var(--bg); }
