:root {
  --bg: #eef6fb;
  --bg-2: #e4eef6;
  --ink: #3b2418;
  --muted: #7a5c4a;
  --line: rgba(59, 36, 24, 0.12);
  --card: rgba(255, 252, 248, 0.92);
  --sidebar: #3b2418;
  --sidebar-2: #4a2e1f;
  --accent: #d4a017;
  --accent-2: #b8860b;
  --amber: #f0c419;
  --sky: #8ec8e8;
  --sky-2: #c9e6f5;
  --tan: #d4b896;
  --danger: #b42318;
  --good: #2f6b3a;
  --shadow: 0 18px 50px rgba(59, 36, 24, 0.12);
  --radius: 18px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Syne", "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 560px at 8% -8%, rgba(142, 200, 232, 0.55), transparent 55%),
    radial-gradient(900px 480px at 100% 0%, rgba(240, 196, 25, 0.22), transparent 52%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #fff8f0;
  padding: 22px 18px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 14px; border-bottom: 1px solid rgba(255,255,255,0.10); }
.brand-logo {
  width: 72px; height: 72px; border-radius: 16px; object-fit: contain;
  background: #fff; padding: 4px;
  box-shadow: 0 10px 24px rgba(212, 160, 23, 0.28);
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #f0c419, #d4a017);
  color: #3b2418;
  font-family: var(--display); font-weight: 800; letter-spacing: -0.04em;
}
.brand-name { font-family: var(--display); font-weight: 800; font-size: 1.2rem; letter-spacing: -0.03em; }
.brand-sub { font-size: 0.75rem; opacity: 0.7; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; padding-right: 4px; margin-right: -4px; }
.nav-section {
  margin: 14px 8px 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(240, 196, 25, 0.85);
}
.nav-link {
  padding: 11px 14px; border-radius: 12px; color: rgba(255,248,240,0.74);
  font-weight: 600; font-size: 0.92rem; transition: .18s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active {
  background: rgba(240, 196, 25, 0.22); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(240, 196, 25, 0.35);
}

/* Sidebar scrollbar — soft gold on brown */
.sidebar .nav {
  scrollbar-width: thin;
  scrollbar-color: rgba(240, 196, 25, 0.45) transparent;
}
.sidebar .nav::-webkit-scrollbar {
  width: 6px;
}
.sidebar .nav::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}
.sidebar .nav::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(240, 196, 25, 0.55), rgba(212, 160, 23, 0.35));
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: padding-box;
}
.sidebar .nav::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(240, 196, 25, 0.85), rgba(212, 160, 23, 0.6));
}
.sidebar .nav::-webkit-scrollbar-corner {
  background: transparent;
}

.sidebar-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.10); }
.user-chip { font-size: 0.82rem; opacity: 0.85; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 22px 28px 8px;
}
.page-title { margin: 0; font-family: var(--display); font-size: 1.7rem; letter-spacing: -0.04em; color: var(--ink); }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.menu-btn { display: none; border: 0; background: var(--card); width: 42px; height: 42px; border-radius: 12px; box-shadow: var(--shadow); }

.content { padding: 12px 28px 36px; }
.flash { margin: 0 28px 12px; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.flash.success { background: #e8f5ec; color: var(--good); }
.flash.error { background: #fdecec; color: var(--danger); }
.flash ul { margin: 0; padding-left: 18px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(142, 200, 232, 0.45), transparent 70%);
}
.kpi .label { color: var(--muted); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .value { font-family: var(--display); font-size: 1.45rem; margin-top: 8px; letter-spacing: -0.03em; }
.kpi .hint { margin-top: 6px; color: var(--muted); font-size: 0.82rem; }
.kpi.amber .value { color: #a67c00; }
.kpi.good .value { color: var(--good); }
.kpi.danger .value { color: var(--danger); }
a.kpi {
  display: block; text-decoration: none; color: inherit; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
a.kpi:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 160, 23, 0.45);
  box-shadow: 0 16px 36px rgba(59, 36, 24, 0.12);
}
a.kpi:hover .hint { color: #a67c00; font-weight: 700; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(201, 230, 245, 0.45), transparent);
}
.panel-head h2 { margin: 0; font-size: 1.05rem; font-family: var(--display); letter-spacing: -0.02em; }
.panel-body { padding: 16px 18px; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 720px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
table.data th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; background: rgba(59,36,24,0.03); }
table.data tr:hover td { background: rgba(142, 200, 232, 0.12); }
.num { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--danger); }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; cursor: pointer;
  transition: .15s ease;
}
.btn-primary {
  background: linear-gradient(135deg, #f0c419, #d4a017);
  color: #3b2418; box-shadow: 0 10px 22px rgba(212, 160, 23, 0.28);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-secondary { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,0.18); }
.btn-sm { padding: 7px 10px; font-size: 0.82rem; border-radius: 10px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 11px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(212, 160, 23, 0.55); box-shadow: 0 0 0 3px rgba(240, 196, 25, 0.18); }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.badge {
  display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700;
  background: rgba(142, 200, 232, 0.35); color: #2a5f7a;
}
.badge.warn { background: rgba(240, 196, 25, 0.25); color: #8a6500; }
.badge.danger { background: rgba(180,35,24,0.12); color: var(--danger); }

.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; }
.bar-track { height: 10px; border-radius: 999px; background: rgba(59,36,24,0.07); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8ec8e8, #5aa8d4); }
.bar-fill.exp { background: linear-gradient(90deg, #f0c419, #d4a017); }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(142, 200, 232, 0.35), transparent 50%),
    radial-gradient(700px 400px at 90% 80%, rgba(240, 196, 25, 0.2), transparent 45%),
    linear-gradient(145deg, #3b2418, #4a2e1f 55%, #5c3a28);
}
.login-card {
  width: min(440px, 100%); background: rgba(255,252,248,0.97); border-radius: 24px;
  padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,0.35);
}
.login-card h1 { font-family: var(--display); margin: 0 0 6px; letter-spacing: -0.04em; color: #3b2418; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-brand { display: flex; justify-content: center; margin-bottom: 22px; }
.login-brand img { width: 96px; height: 96px; object-fit: contain; }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; padding: 14px 18px; }
.pagination a, .pagination span {
  padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 700; font-size: 0.85rem;
}

.pl-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.pl-row:last-child { border-bottom: 0; }
.pl-row.total { font-family: var(--display); font-size: 1.15rem; font-weight: 800; }

.sidebar-backdrop { display: none; }

/* Invoice print */
.invoice-page { background: #dfeaf2; min-height: 100vh; padding: 24px; }
.invoice-sheet {
  max-width: 900px; margin: 0 auto; background: #fff; border-radius: 18px;
  padding: 32px; box-shadow: var(--shadow); color: #3b2418;
}
.invoice-top {
  display: flex; justify-content: space-between; gap: 24px; align-items: center;
  border-bottom: 2px solid #f0c419; padding-bottom: 18px; margin-bottom: 8px;
}
.invoice-brand { display: flex; align-items: center; }
.invoice-logo { width: 110px; height: auto; display: block; }
.invoice-meta { text-align: right; max-width: 58%; }
.invoice-title {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #3b2418;
}
.invoice-meta p {
  margin: 0 0 8px;
  font-size: 1.05rem;
  line-height: 1.5;
  color: #3b2418;
}
.invoice-billto {
  margin-top: 12px !important;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(240, 196, 25, 0.16);
  border: 1px solid rgba(212, 160, 23, 0.35);
  text-align: center;
}
.vendor-label {
  display: block;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a5c4a;
  margin-bottom: 4px;
}
.vendor-name {
  display: block;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: #3b2418;
  line-height: 1.25;
  text-align: center;
}
.vendor-meta {
  display: block;
  margin-top: 3px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: #5c4436;
  text-align: center;
}
.invoice-section-title {
  margin: 22px 0 10px;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #3b2418;
}
.invoice-table th,
.invoice-table td {
  font-size: 1rem;
  line-height: 1.45;
  padding: 12px 10px;
  vertical-align: top;
  color: #3b2418;
}
.invoice-table th {
  background: rgba(59,36,24,0.04);
}
.invoice-total-row td {
  background: rgba(240, 196, 25, 0.18);
  border-top: 2px solid rgba(212, 160, 23, 0.45);
  font-size: 1.02rem;
  padding-top: 14px;
  padding-bottom: 14px;
}

.invoice-bottom {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  margin-top: 14px;
  align-items: center;
}
.bank-box {
  margin-top: 0; padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #eef7fc, #fff8e6);
  border: 1px solid rgba(59,36,24,0.1);
}
.bank-title {
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase; color: #7a5c4a; margin-bottom: 6px;
}
.bank-box p { margin: 0 0 4px; font-size: 0.98rem; line-height: 1.4; color: #3b2418; }
.bank-contact { margin-top: 8px !important; }

.invoice-summary-box {
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sum-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 8px 0;
  font-size: 1rem;
  color: #3b2418;
  border-bottom: 1px dashed rgba(59,36,24,0.12);
}
.sum-row:last-of-type { border-bottom: 0; }
.sum-row strong { font-variant-numeric: tabular-nums; }

.remaining-card {
  margin-top: 0;
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  text-align: center;
  background: linear-gradient(145deg, #fff6d0 0%, #f0c419 55%, #d4a017 100%);
  border: 1px solid rgba(184, 134, 11, 0.4);
  box-shadow: 0 8px 18px rgba(212, 160, 23, 0.22);
}
.remaining-label {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #3b2418;
}
.remaining-amount {
  margin-top: 4px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(1.7rem, 3.6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.15;
  color: #1a100a;
  font-variant-numeric: tabular-nums;
}

.invoice-footer {
  margin-top: 14px;
  color: #7a5c4a;
  font-size: 0.95rem;
  line-height: 1.5;
}
.invoice-actions {
  max-width: 900px; margin: 0 auto 14px;
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
}
.invoice-sheet .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.invoice-sheet table.data { min-width: 560px; }

@media print {
  .invoice-actions, .no-print { display: none !important; }
  .invoice-page { background: #fff; padding: 0; }
  .invoice-sheet { box-shadow: none; border-radius: 0; max-width: none; padding: 12px; }
}

@media (max-width: 1100px) {
  .kpi-grid, .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40;
    transform: translateX(-105%); transition: .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  body:has(.sidebar.open) .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 30; }
  .menu-btn { display: inline-grid; place-items: center; }
  .content, .topbar, .flash { padding-left: 16px; padding-right: 16px; }
  .kpi-grid, .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.35rem; }

  .invoice-page { padding: 12px; }
  .invoice-sheet { padding: 18px 14px; border-radius: 14px; }
  .invoice-top { flex-direction: column; align-items: flex-start; }
  .invoice-meta { text-align: left; width: 100%; max-width: none; }
  .invoice-title { font-size: 1.55rem; }
  .invoice-logo { width: 84px; }
  .invoice-bottom { grid-template-columns: 1fr; gap: 12px; }
  .remaining-amount { font-size: 1.85rem; }
  .invoice-actions {
    justify-content: stretch;
  }
  .invoice-actions .btn { flex: 1 1 calc(50% - 6px); min-width: 140px; }
  .wa-phone-row {
    justify-content: stretch !important;
    max-width: none !important;
  }
  .wa-phone-row input { width: 100% !important; }
  .wa-status { text-align: left !important; max-width: none !important; }
  .invoice-sheet table.data th,
  .invoice-sheet table.data td { padding: 10px 8px; font-size: 0.85rem; }
}
