/* ===== Accounts Assist — modern UI ===== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e6e8f0;
  --text: #1a1d29;
  --text-dim: #6b7280;
  --primary: #4f46e5;
  --primary-dim: #eef2ff;
  --success: #10b981;
  --success-dim: #ecfdf5;
  --danger: #ef4444;
  --danger-dim: #fef2f2;
  --warn: #f59e0b;
  --warn-dim: #fffbeb;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 250px;
}
[data-theme="dark"] {
  --bg: #0e1017;
  --surface: #171a23;
  --surface-2: #1e222e;
  --border: #262a37;
  --text: #e8eaf2;
  --text-dim: #9aa1b3;
  --primary: #7c74ff;
  --primary-dim: #23234a;
  --success-dim: #0f2a22;
  --danger-dim: #2a1517;
  --warn-dim: #2a2210;
  --shadow: none;
  --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; cursor: pointer; }
button { font-family: inherit; cursor: pointer; }

#app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 16px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; font-weight: 800; font-size: 20px;
  display: grid; place-items: center; flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; overflow-y: auto; }
.nav-group { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); padding: 12px 12px 4px; opacity: .7; }
.mini-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 6px 0 2px; }
.banner { background: var(--warn-dim); color: var(--warn); border: 1px solid var(--warn); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item .ico { font-size: 15px; width: 20px; text-align: center; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.theme-toggle {
  flex: none; width: 40px; height: 40px; padding: 0;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 17px; line-height: 1;
  display: grid; place-items: center;
}
.theme-toggle:hover { background: var(--border); }

/* ===== Main ===== */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; display: flex; justify-content: center;
  padding: 0 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner { display: flex; align-items: center; gap: 16px; width: 100%; max-width: 1320px; }
.topbar h1 { font-size: 19px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.menu-btn { display: none; background: none; border: none; font-size: 22px; color: var(--text); flex: none; }
.topbar-actions { display: flex; gap: 10px; flex: none; }
.content { padding: 28px; max-width: 1320px; width: 100%; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 13.5px;
  transition: filter .15s, background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); background: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

/* ===== Cards / grid ===== */
.grid { display: grid; gap: 18px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.kpi { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--text-dim); font-size: 13px; font-weight: 500; }
.kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 16px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.kpi-sub { font-size: 12.5px; color: var(--text-dim); }
.tint-primary { background: var(--primary-dim); color: var(--primary); }
.tint-success { background: var(--success-dim); color: var(--success); }
.tint-danger { background: var(--danger-dim); color: var(--danger); }
.tint-warn { background: var(--warn-dim); color: var(--warn); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 16px; font-weight: 700; }
.two-col { grid-template-columns: 1.6fr 1fr; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; font-size: 13.5px; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-dim); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--success-dim); color: var(--success); }
.badge-sent { background: var(--primary-dim); color: var(--primary); }
.badge-draft { background: var(--surface-2); color: var(--text-dim); }
.badge-overdue { background: var(--danger-dim); color: var(--danger); }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px; font-family: inherit; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,18,30,.5);
  display: grid; place-items: center; z-index: 60; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 620px;
  max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.x-btn { background: none; border: none; font-size: 22px; color: var(--text-dim); line-height: 1; }

/* line items */
.items-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 6px 0 10px; }
.items-table { width: 100%; min-width: 460px; margin: 0; }
.items-table th { padding: 6px 8px; }
.items-table td { padding: 4px; border: none; }
.items-table input { padding: 8px; }
.li-remove { color: var(--danger); background: none; border: none; font-size: 18px; }

/* ===== Charts ===== */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding: 10px 4px 0; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; align-items: flex-end; gap: 4px; height: 100%; width: 100%; justify-content: center; }
.bar { width: 16px; border-radius: 5px 5px 0 0; transition: height .4s ease; min-height: 3px; }
.bar-income { background: var(--primary); }
.bar-expense { background: #f59e0b; }
.bar-label { font-size: 11.5px; color: var(--text-dim); }
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12.5px; color: var(--text-dim); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.cat-list { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.cat-row .dot { flex: none; }
.cat-row .cat-name { flex: 1; }
.cat-row .cat-val { font-weight: 600; }

/* empty state */
.empty { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* toast */
.toast-host { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--success); border-radius: 10px;
  padding: 12px 16px; box-shadow: var(--shadow-lg); font-weight: 500;
  animation: slideIn .25s ease;
}
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* pl table */
.report-line { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.report-line.total { font-weight: 800; font-size: 15px; border-bottom: 2px solid var(--text); }
.report-line.sub { padding-left: 16px; color: var(--text-dim); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px; padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px;
}
.search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }

/* ===== Login ===== */
#loginOverlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, var(--primary-dim), var(--bg)); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 34px; width: 100%; max-width: 380px; text-align: center; }
.login-card h2 { font-size: 20px; font-weight: 800; }
.login-card .field { text-align: left; }
.login-err { background: var(--danger-dim); color: var(--danger); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }

/* ===== Sidebar footer ===== */
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .user-row { font-size: 13px; color: var(--text-dim); padding: 2px 4px 6px; font-weight: 600; }

/* ===== Customize toggles ===== */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.toggle-row:last-of-type { border-bottom: none; }
.toggle-row .ico { margin-right: 8px; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* ===== Report cards ===== */
.report-card { cursor: pointer; transition: transform .1s, box-shadow .15s; }
.report-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }

/* ===== Printable invoice ===== */
#printArea { display: none; }
@media print {
  body.printing #app, body.printing .modal-backdrop, body.printing .toast-host { display: none !important; }
  body.printing #printArea { display: block; }
}
.pinv { max-width: 720px; margin: 0 auto; padding: 24px; color: #111; font-size: 13px; }
.pinv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: 16px; }
.pinv-co { font-size: 20px; font-weight: 800; }
.pinv-title { font-size: 22px; font-weight: 800; text-align: right; letter-spacing: 1px; }
.pinv-muted { color: #666; font-weight: 400; font-size: 12px; }
.pinv-meta { display: flex; justify-content: space-between; margin: 22px 0; }
.pinv-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.pinv-table th { text-align: left; border-bottom: 1px solid #111; padding: 8px; font-size: 11px; text-transform: uppercase; }
.pinv-table td { padding: 8px; border-bottom: 1px solid #ddd; }
.pinv-table .r, .pinv .r { text-align: right; }
.pinv-total { display: flex; justify-content: space-between; font-size: 18px; font-weight: 800; margin-top: 16px; padding-top: 12px; border-top: 2px solid #111; }
.pinv-status { margin-top: 20px; color: #666; text-transform: capitalize; }

/* ===== Responsive ===== */
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .content { padding: 18px; }
}
