:root {
  --bg: #070b14;
  --surface: #0f172a;
  --surface-2: #162033;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #14b8a6;
  --accent-2: #0ea5e9;
  --emerald: #10b981;
  --rose: #f43f5e;
  --amber: #f59e0b;
  --radius: 12px;
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-2: #0284c7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-frame {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.brand-logo { width: 34px; height: 34px; border-radius: 9px; }
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: -0.2px; }
.brand-tag { font-size: 11px; color: var(--muted); }

.cmd-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.cmd-trigger kbd {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: rgba(20, 184, 166, 0.14);
  color: var(--accent);
  border-color: rgba(20, 184, 166, 0.28);
}

.nav-icon { font-size: 14px; width: 18px; text-align: center; }
.nav-pill {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text);
}
.nav-pill.warn { background: rgba(244, 63, 94, 0.18); color: var(--rose); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.offline-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--emerald);
  font-weight: 600;
}

.offline-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
}

.footer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* Workspace */
.workspace {
  padding: 24px 28px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; flex-direction: column; gap: 18px; }
.view.active { display: flex; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}

h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
h3 { font-size: 14px; font-weight: 700; }
.muted { font-size: 12px; color: var(--muted); margin-top: 3px; }

.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #031514;
  border: none;
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover, .btn-mini:hover { border-color: var(--accent); }

.btn-mini {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.14);
  color: var(--rose);
  border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Cards & KPIs */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
}

.kpi-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.kpi-val { font-size: 24px; font-weight: 800; margin: 4px 0 2px; }
.kpi-val.emerald { color: var(--emerald); }
.kpi-val.cyan { color: var(--accent-2); }
.kpi-val.rose { color: var(--rose); }
.kpi-sub { font-size: 11px; color: var(--muted); }

.dash-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}

#revenueChart { width: 100%; height: 220px; display: block; }

.radar-list, .list-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 10px;
}

.radar-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
}

/* Forms */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form-row-4 { display: grid; grid-template-columns: 2fr 1.2fr 1fr auto; gap: 10px; margin-bottom: 14px; }
.two-col-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stack-form { display: flex; flex-direction: column; gap: 9px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .field-lbl { font-size: 11px; font-weight: 600; color: var(--muted); }

input, select, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.search-input { min-width: 210px; }
.mini-select { padding: 6px 9px; font-size: 11px; }
.file-btn { display: inline-block; text-align: center; }

/* Studio Split */
.studio-split {
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  gap: 18px;
  align-items: start;
}

.studio-editor { display: flex; flex-direction: column; gap: 11px; }

.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

.bar-right { display: flex; gap: 6px; align-items: center; }

.lines-editor { display: flex; flex-direction: column; gap: 7px; }
.line-row {
  display: grid;
  grid-template-columns: 2.2fr 0.7fr 1fr auto;
  gap: 6px;
  align-items: center;
}

/* Live A4 Paper */
.a4-stage {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 16px;
}

.a4-sheet {
  background: #ffffff;
  color: #0f172a;
  border-radius: 6px;
  padding: 34px 36px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  min-height: 700px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.a4-sheet.tpl-executive .a4-top { border-bottom: 3px solid #0f766e; padding-bottom: 16px; }
.a4-sheet.tpl-executive .pv-doc-type { color: #0f766e; }
.a4-sheet.tpl-swiss .a4-top { border-bottom: 4px solid #1e293b; padding-bottom: 16px; }
.a4-sheet.tpl-swiss .pv-doc-type { color: #1e293b; }
.a4-sheet.tpl-minimal .a4-top { border-bottom: 1px solid #cbd5e1; padding-bottom: 14px; }
.a4-sheet.tpl-minimal .pv-doc-type { color: #334155; }

.a4-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.a4-brand { display: flex; align-items: center; gap: 12px; }
.pv-logo { max-width: 54px; max-height: 54px; object-fit: contain; border-radius: 6px; }
.pv-biz-name { font-size: 18px; font-weight: 800; color: #0f172a; }
.pv-biz-meta { font-size: 11px; color: #475569; margin-top: 3px; }

.a4-doc-meta { text-align: right; }
.pv-doc-type { font-size: 22px; font-weight: 900; letter-spacing: 0.8px; }
.pv-doc-num { font-size: 12px; font-weight: 700; color: #334155; margin-top: 2px; }
.pv-status-pill {
  display: inline-block;
  margin-top: 5px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: #e2e8f0;
  color: #1e293b;
}

.a4-parties { display: flex; justify-content: space-between; gap: 16px; }
.pv-lbl { font-size: 10px; font-weight: 700; color: #64748b; letter-spacing: 0.6px; }
.pv-client-name { font-size: 15px; font-weight: 700; margin: 3px 0; }
.pv-muted { font-size: 11.5px; color: #475569; }
.a4-dates { text-align: right; font-size: 12px; display: flex; flex-direction: column; gap: 5px; }

.a4-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.a4-table th {
  text-align: left;
  padding: 9px 10px;
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 700;
  border-bottom: 1.5px solid #cbd5e1;
}
.a4-table td { padding: 9px 10px; border-bottom: 1px solid #e2e8f0; color: #1e293b; }
.a4-table th.num, .a4-table td.num { text-align: right; }

.a4-totals-wrap { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; margin-top: auto; }
.a4-notes-box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 12px; }
.pv-notes-text { font-size: 11.5px; color: #334155; white-space: pre-wrap; margin-top: 5px; line-height: 1.5; }

.a4-totals { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.tot-row { display: flex; justify-content: space-between; padding: 3px 0; color: #334155; }
.tot-row.grand {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
  border-top: 2px solid #0f172a;
  padding-top: 8px;
  margin-top: 4px;
}
.tot-row.balance { font-weight: 800; color: #0f766e; }

.a4-footer {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #64748b;
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}

/* Data Tables */
.table-wrap { overflow-x: auto; }
table.data-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data-tbl th, table.data-tbl td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.data-tbl th { color: var(--muted); font-size: 11px; text-transform: uppercase; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10.5px;
  font-weight: 700;
}
.st-Paid { background: rgba(16, 185, 129, 0.16); color: var(--emerald); }
.st-Overdue { background: rgba(244, 63, 94, 0.16); color: var(--rose); }
.st-Sent, .st-Advance { background: rgba(14, 165, 233, 0.16); color: var(--accent-2); }
.st-Draft { background: rgba(148, 163, 184, 0.16); color: var(--muted); }

/* Command Palette */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: grid;
  place-items: start center;
  padding-top: 110px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.cmd-box {
  width: min(520px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.cmd-box input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 14px 16px;
  font-size: 14px;
}
.cmd-list { display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; }
.cmd-item {
  padding: 11px 16px;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}
.cmd-item:hover { background: var(--surface-2); color: var(--accent); }

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #ecfdf5;
  border: 1px solid var(--accent);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; }

@media (max-width: 1080px) {
  .app-frame { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .studio-split, .dash-grid, .two-col-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Clean A4 PDF Print Rules */
@media print {
  body { background: #ffffff !important; }
  .sidebar, .view-header, .studio-editor, .modal-backdrop, .toast,
  #view-dashboard, #view-ledger, #view-clients, #view-expenses, #view-settings {
    display: none !important;
  }
  .app-frame, .workspace, #view-studio, .studio-split, .a4-stage {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: #ffffff !important;
    width: 100% !important;
    max-width: none !important;
  }
  .a4-sheet {
    box-shadow: none !important;
    padding: 12mm !important;
    min-height: auto !important;
  }
}

.tot-row[hidden], [hidden] { display: none !important; }
.lang-select { width: 100%; padding: 6px 8px; font-size: 11px; border-radius: 7px; }
