/* PROQAL BOOKS — Enterprise Accounting v3.0 */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f2;
  --line-2: #eff2f7;
  --brand: #0e9f6e;
  --brand-2: #057a55;
  --brand-soft: #def7ec;
  --accent: #6366f1;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --radius: 12px;
  --sidebar-bg: linear-gradient(180deg, #0b1320 0%, #111c2e 100%);
  --sidebar-fg: #cbd5e1;
  --sidebar-fg-active: #ffffff;
  --sidebar-active-bg: rgba(255,255,255,.08);
  --sidebar-hover-bg: rgba(255,255,255,.04);
}
body.dark {
  --bg: #0b1320;
  --panel: #131c2d;
  --panel-2: #0f1726;
  --ink: #e2e8f0;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --line: #1f2a3d;
  --line-2: #1a2438;
  --brand-soft: #064e3b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 1px 3px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ===== Login screen ===== */
.login-screen {
  position: fixed; inset: 0; background: linear-gradient(135deg, #0e9f6e 0%, #0b1320 100%);
  display: grid; place-items: center; z-index: 100;
}
.login-box {
  width: 100%; max-width: 420px; background: var(--panel); color: var(--ink);
  border-radius: 16px; padding: 36px 32px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 18px; letter-spacing: -.02em;
}
.login-title { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 12px; }
.login-box h2 { font-size: 18px; margin: 0 0 18px; font-weight: 700; }
.login-form .field { margin-bottom: 14px; }
.login-error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 16px; line-height: 1.5; }
.login-hint code { background: var(--line-2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ===== App layout ===== */
#app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; letter-spacing: -.02em;
}
.brand-title { font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; color: #fff; }
.brand-sub { font-size: 11px; opacity: .55; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; flex: 1; }
.nav-group { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .45; margin: 14px 10px 4px; }
.nav-group:first-child { margin-top: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  color: var(--sidebar-fg); text-decoration: none; font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-fg-active); }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-fg-active); font-weight: 600; }
.nav-item.active::before { content: ''; position: absolute; }
.ico { width: 16px; height: 16px; flex-shrink: 0; opacity: .85; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10.5px; color: var(--sidebar-fg); opacity: .7; }
.btn-icon { background: transparent; border: none; color: var(--sidebar-fg); cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 14px; }
.btn-icon:hover { background: var(--sidebar-hover-bg); color: #fff; }

/* ===== Main ===== */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 28px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.company { text-align: right; }
.company-name { font-weight: 600; font-size: 13px; }
.company-period { color: var(--muted); font-size: 11.5px; }

.view { padding: 22px 28px; max-width: 1400px; width: 100%; }

/* ===== Cards & KPIs ===== */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
}
.card-pad-tight { padding: 14px; }

.kpi-card { padding: 18px; }
.kpi-card .kpi-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-card .kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi-card .kpi-delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi-card.k-cash .kpi-icon { color: #0e9f6e; }
.kpi-card.k-ar   .kpi-icon { color: #6366f1; }
.kpi-card.k-ap   .kpi-icon { color: #f59e0b; }
.kpi-card.k-inv  .kpi-icon { color: #06b6d4; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 12px; }
.section-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.section-actions { display: flex; gap: 8px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
  font-family: inherit;
}
.btn:hover { border-color: #c8d0e0; background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--line-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px 14px; }

.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 10px; border: 1px solid var(--line); width: fit-content; margin-bottom: 14px; }
.tab {
  background: transparent; border: none; padding: 7px 14px;
  border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink-2); font-weight: 500;
}
.tab.active { background: var(--brand); color: #fff; font-weight: 600; }
.tab:hover:not(.active) { background: var(--line-2); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
table.table { width: 100%; border-collapse: collapse; background: var(--panel); }
table.table th, table.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
table.table th { background: var(--panel-2); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
table.table tr:last-child td { border-bottom: none; }
table.table td.num, table.table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table tr:hover td { background: var(--panel-2); }

/* ===== Forms ===== */
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  background: var(--panel); color: var(--ink); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand-soft); border-color: var(--brand);
}

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-open { background: #fef9c3; color: #854d0e; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-draft { background: var(--line-2); color: var(--ink-2); }
.badge-success { background: var(--brand-soft); color: var(--brand-2); }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 50; }
.modal-box { background: var(--panel); border-radius: 14px; min-width: 520px; max-width: 880px; width: 90%; max-height: 88vh; overflow: auto; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel-2); }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; font-size: 13px; font-weight: 500; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* ===== Utilities ===== */
.muted { color: var(--muted); }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--danger); }

/* Line items table inside modal */
.li-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.li-table th, .li-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 12px; }
.li-table input, .li-table select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; background: var(--panel); color: var(--ink); }
.li-table td.num input { text-align: right; }
.li-table .x { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 16px; }

.totals { margin-top: 14px; display: grid; grid-template-columns: 1fr 220px; gap: 6px 14px; }
.totals .label { color: var(--muted); }
.totals .val { text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line); padding-top: 8px; }

/* ===== Reports ===== */
.report { background: var(--panel); border-radius: var(--radius); padding: 24px; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.report h3 { margin: 0 0 4px; font-size: 18px; }
.report .report-meta { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }
.report table { width: 100%; border-collapse: collapse; }
.report td, .report th { padding: 7px 8px; }
.report .group td { font-weight: 700; background: var(--line-2); }
.report .total-row td { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 700; }

.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.chart-card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.chart-wrap { position: relative; height: 240px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Print */
@media print {
  .sidebar, .topbar { display: none; }
  #app { grid-template-columns: 1fr; }
  .view { padding: 0; }
  .card, .table-wrap, .report { box-shadow: none; border: 1px solid #ddd; }
}

/* Search bar */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.search-bar input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: var(--panel); color: var(--ink); }
.search-bar input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.search-bar .count { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Empty state */
.empty-state { background: var(--panel); border: 2px dashed var(--line); border-radius: 14px; padding: 40px 28px; text-align: center; }
.empty-state .icon { font-size: 36px; margin-bottom: 10px; }
.empty-state h3 { margin: 4px 0 6px; font-size: 16px; }
.empty-state p { color: var(--muted); margin: 0 0 16px; font-size: 13px; }
