:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --green: #059669;
  --green-bg: #ecfdf5;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --blue-bg: #eff6ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; padding: 6px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; font-weight: 800; font-size: 18px;
}
.brand-name { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  color: #cbd5e1; padding: 9px 11px; border-radius: 9px;
  font-size: .92rem; font-weight: 500;
}
.side-nav a span { width: 20px; text-align: center; }
.side-nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.side-nav a.active { background: rgba(99,102,241,.28); color: #fff; }
.logout-form { margin-top: 12px; }
.btn-ghost {
  background: transparent; border: 1px solid rgba(255,255,255,.2);
  color: #cbd5e1; padding: 8px 12px; border-radius: 9px; cursor: pointer; font: inherit;
}
.btn-ghost:hover { background: rgba(255,255,255,.08); color: #fff; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none;
  align-items: center; gap: 12px;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 12px 16px; position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 700; flex: 1; }
.topbar-user { font-size: .85rem; color: var(--muted); }
.menu-btn {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 38px; font-size: 18px; cursor: pointer;
}
.content { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 10px; font-size: .88rem; color: var(--muted); }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* metric cards */
.metric { padding: 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.metric .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.metric .value { font-size: 1.35rem; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.metric .sub { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.metric.green .value { color: var(--green); }
.metric.red .value { color: var(--red); }
.metric.amber .value { color: var(--amber); }
.metric.primary .value { color: var(--primary); }

.hero-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .hero-metrics { grid-template-columns: repeat(2, 1fr); } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #f8fafc; }
table.data td.right, table.data th.right { text-align: right; }
.t-amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-green { color: var(--green); font-weight: 600; }
.t-red { color: var(--red); font-weight: 600; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; letter-spacing: .01em; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--primary); }
.badge-gray { background: #f1f5f9; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 15px; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-size: .9rem;
}
.btn:hover { text-decoration: none; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-green:hover { background: #047857; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 6px 10px; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-ghost.btn-block { border-color: rgba(255,255,255,.2); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .84rem; font-weight: 600; color: #334155; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text);
  background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
textarea { min-height: 70px; resize: vertical; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.checkbox input { width: auto; }

/* line items editor */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; padding: 6px; }
.items-table td { padding: 4px 6px; }
.items-table input, .items-table select { padding: 8px 9px; }
.items-table .col-qty { width: 90px; }
.items-table .col-price { width: 120px; }
.items-table .col-del { width: 42px; }
.items-table .line-total { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-del { background: #fff; border: 1px solid #fecaca; color: var(--red); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }
.totals-box { margin-left: auto; width: 100%; max-width: 320px; margin-top: 12px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .92rem; }
.totals-box .row.grand { border-top: 2px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 1.1rem; font-weight: 800; }

/* ---------- flash / alerts ---------- */
.flash {
  background: var(--green-bg); border: 1px solid #a7f3d0; color: #065f46;
  padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-size: .9rem;
}
.flash-error { background: var(--red-bg); border-color: #fecaca; color: #991b1b; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: .88rem; }
.alert-amber { background: var(--amber-bg); border: 1px solid #fde68a; color: #92400e; }
.alert-red { background: var(--red-bg); border: 1px solid #fecaca; color: #991b1b; }
.alert-blue { background: var(--blue-bg); border: 1px solid #bfdbfe; color: #1e40af; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: .8rem; color: var(--muted); }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 42px; margin-bottom: 12px; }

/* ---------- dashboard specific ---------- */
.dash-split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 900px) { .dash-split { grid-template-columns: 1fr; } }
.mini-stats { display: flex; gap: 18px; flex-wrap: wrap; }
.mini-stat .n { font-size: 1.25rem; font-weight: 800; }
.mini-stat .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1000px 500px at 50% -10%, #e0e7ff, transparent), var(--bg); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; }
.login-brand { margin-bottom: 10px; }
.login-card h1 { font-size: 1.4rem; }
.login-card .form { margin-top: 18px; }

/* ---------- bottom nav / mobile menu ---------- */
.bottomnav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: #fff; border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(15,23,42,.06);
}
.bottomnav a, .bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .68rem; color: var(--muted); padding: 6px 2px; border: none; background: none;
  font-family: inherit; cursor: pointer; border-radius: 8px; text-align: center;
}
.bottomnav a span, .bottomnav button span { font-size: 1.15rem; }
.bottomnav a.active, .bottomnav button.active { color: var(--primary); font-weight: 700; }

.mobile-menu { display: none; position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.5); }
.mobile-menu.open { display: flex; justify-content: flex-end; }
.mobile-menu-panel { background: #fff; width: min(320px, 88vw); height: 100%; padding: 18px; display: flex; flex-direction: column; overflow-y: auto; }
.mobile-menu-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mobile-menu-head button { background: none; border: none; font-size: 20px; cursor: pointer; }
.mobile-menu-links { display: flex; flex-direction: column; flex: 1; }
.mobile-menu-links a { padding: 11px 8px; border-radius: 8px; color: var(--text); font-weight: 500; }
.mobile-menu-links a:hover { background: var(--bg); text-decoration: none; }
.mobile-menu .btn { margin-top: 12px; color: var(--text); border-color: var(--line); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .bottomnav { display: flex; }
  .content { padding: 16px 16px 90px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
  .card { padding: 15px; }
  table.data { font-size: .84rem; }
  table.data th, table.data td { padding: 8px 7px; }
  .items-table .col-price { width: 92px; }
  .items-table .col-qty { width: 68px; }
}

/* ---------- invoice / print ---------- */
.invoice-sheet { background: #fff; max-width: 800px; margin: 0 auto; padding: 36px; border: 1px solid var(--line); border-radius: 14px; }
.inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #0f172a; padding-bottom: 16px; margin-bottom: 20px; }
.inv-head h2 { margin: 0; font-size: 1.5rem; }
.inv-meta { text-align: right; font-size: .86rem; }
.inv-parties { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.inv-parties .box { flex: 1; }
.inv-parties .lbl { font-size: .72rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; font-weight: 700; margin-bottom: 4px; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.inv-table th { background: #f1f5f9; text-align: left; padding: 9px; font-size: .76rem; text-transform: uppercase; color: #334155; }
.inv-table td { padding: 9px; border-bottom: 1px solid var(--line); }
.inv-totals { margin-left: auto; width: 280px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 5px 0; }
.inv-totals .grand { border-top: 2px solid #0f172a; margin-top: 6px; padding-top: 8px; font-weight: 800; font-size: 1.1rem; }
.inv-footer { margin-top: 30px; font-size: .78rem; color: var(--muted); text-align: center; }
.no-print { }

@media print {
  .sidebar, .topbar, .bottomnav, .mobile-menu, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .invoice-sheet { border: none; border-radius: 0; padding: 0; max-width: none; box-shadow: none; }
  a { color: #000; text-decoration: none; }
}
