/* =====================================================================
   InvoiceFlow - UI stylesheet
   Dark sidebar + light/dark content area, fully responsive.
   ===================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --brand:        #4f46e5;
  --brand-600:    #4338ca;
  --brand-300:    #a5b4fc;
  --brand-soft:   rgba(79, 70, 229, .10);

  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #0ea5e9;

  /* sidebar */
  --sidebar-bg:      #111827;
  --sidebar-bg-2:    #0b1220;
  --sidebar-text:    #cbd5e1;
  --sidebar-muted:   #7c8aa3;
  --sidebar-active:  #4f46e5;
  --sidebar-hover:   rgba(255, 255, 255, .06);
  --sidebar-border:  rgba(255, 255, 255, .08);

  /* content - light */
  --bg:           #f4f6fb;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #eef2f7;
  --border:       #e2e8f0;
  --border-strong:#cbd5e1;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-soft:    #94a3b8;

  --shadow-sm:  0 1px 2px rgba(15, 23, 42, .06);
  --shadow:     0 2px 6px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg:  0 18px 45px rgba(15, 23, 42, .16);

  --radius:     14px;
  --radius-sm:  9px;
  --sidebar-w:  268px;
  --topbar-h:   68px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* ---------- Content dark mode ---------- */
[data-theme="dark"] {
  --bg:           #0b1120;
  --surface:      #131c2e;
  --surface-2:    #182238;
  --surface-3:    #1e2a42;
  --border:       #26324a;
  --border-strong:#35435e;
  --text:         #e8edf7;
  --text-muted:   #97a6c0;
  --text-soft:    #6f7f9c;
  --brand-soft:   rgba(129, 140, 248, .16);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .35);
  --shadow:     0 2px 8px rgba(0, 0, 0, .40);
  --shadow-lg:  0 18px 45px rgba(0, 0, 0, .55);
}

/* light sidebar option */
[data-sidebar="light"] .sidebar {
  --sidebar-bg:     #ffffff;
  --sidebar-bg-2:   #f6f7fb;
  --sidebar-text:   #334155;
  --sidebar-muted:  #94a3b8;
  --sidebar-border: #e6eaf2;
  --sidebar-hover:  rgba(15, 23, 42, .05);
}
[data-sidebar="light"] .sidebar .brand-mark { background: var(--brand); }
[data-sidebar="light"] .sidebar .nav-link.is-active { color: var(--brand); }
[data-sidebar="midnight"] .sidebar {
  --sidebar-bg:     #0f172a;
  --sidebar-bg-2:   #080d1a;
  --sidebar-active: #7c3aed;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

.text-muted  { color: var(--text-muted); }
.text-soft   { color: var(--text-soft); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.nowrap      { white-space: nowrap; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-warning{ color: var(--warning); }
.mono        { font-family: var(--mono); font-size: .9em; }
.small       { font-size: .84rem; }
.tiny        { font-size: .76rem; }
.bold        { font-weight: 650; }
.mt-0{margin-top:0}.mt-1{margin-top:.4rem}.mt-2{margin-top:.8rem}.mt-3{margin-top:1.4rem}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:.4rem}.mb-2{margin-bottom:.8rem}.mb-3{margin-bottom:1.4rem}
.flex{display:flex}.between{justify-content:space-between}.center{align-items:center}
.gap-1{gap:.4rem}.gap-2{gap:.8rem}.gap-3{gap:1.4rem}.wrap{flex-wrap:wrap}
.grow{flex:1 1 auto; min-width:0}

/* =====================================================================
   Layout shell
   ===================================================================== */
.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  z-index: 60;
  transition: transform .26s cubic-bezier(.4, 0, .2, 1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  height: var(--topbar-h);
  padding: 0 1.05rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex: 0 0 auto;
}
.brand-mark {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff;
  font-weight: 800;
  font-size: .95rem;
  letter-spacing: .02em;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .38);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong {
  color: #fff;
  font-size: .95rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-sidebar="light"] .brand-text strong { color: var(--text); }
.brand-text small {
  color: var(--sidebar-muted);
  font-size: .71rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-close {
  display: none;
  margin-left: auto;
  background: none; border: 0;
  color: var(--sidebar-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: .9rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .18rem;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .13);
  border-radius: 6px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .78rem;
  padding: .62rem .8rem;
  border-radius: 10px;
  color: var(--sidebar-text);
  font-size: .885rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.nav-link i { font-size: 1.02rem; width: 20px; text-align: center; flex: 0 0 20px; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
[data-sidebar="light"] .nav-link:hover { color: var(--text); }
.nav-link.is-active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .34);
}
.nav-link span { flex: 1 1 auto; }
.nav-badge {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  text-align: center;
}

.sidebar-footer {
  flex: 0 0 auto;
  padding: .85rem .8rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.renewal-meter {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  padding: .7rem .8rem;
}
.renewal-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .76rem;
  color: var(--sidebar-muted);
  margin-bottom: .45rem;
}
.renewal-meter-head strong { color: #fff; font-size: 1.05rem; }
.meter-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.meter-track span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--warning), var(--danger));
  border-radius: 999px;
}
.meter-link {
display: block;
margin-top: .5rem;
font-size: .75rem;
color: var(--brand-300);
font-weight: 600;
}
/* The "Run billing now" control is a POST form, not a link */
.meter-form { margin: 0; }
.meter-form .meter-link {
margin-top: .5rem;
padding: 0;
border: 0;
background: none;
text-align: left;
cursor: pointer;
font-family: inherit;
}
[data-sidebar="light"] .meter-link { color: var(--brand); }

.user-chip { display: flex; align-items: center; gap: .6rem; }
.avatar {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff;
  font-size: .74rem;
  font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.user-meta strong {
  font-size: .83rem; color: #fff; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-sidebar="light"] .user-meta strong { color: var(--text); }
.user-meta small { font-size: .7rem; color: var(--sidebar-muted); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.sidebar .icon-btn {
  background: transparent;
  border-color: var(--sidebar-border);
  color: var(--sidebar-muted);
}
.sidebar .icon-btn:hover { background: var(--sidebar-hover); color: #fff; }
[data-sidebar="light"] .sidebar .icon-btn:hover { color: var(--text); }

.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

/* ---------- Main column ---------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: var(--topbar-h);
  padding: .7rem 1.4rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h1 {
  font-size: 1.28rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title p {
  margin: .1rem 0 0;
  font-size: .8rem;
  color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: .55rem; flex: 0 0 auto; }

.menu-toggle { display: none; }

.search-form {
  position: relative;
  display: flex;
  align-items: center;
}
.search-form i {
  position: absolute; left: .7rem;
  color: var(--text-soft);
  font-size: .88rem;
  pointer-events: none;
}
.search-form input {
  width: 232px;
  padding: .5rem .7rem .5rem 2.05rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: .855rem;
  transition: width .2s, border-color .15s, background .15s;
}
.search-form input:focus {
  width: 272px;
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}

.theme-toggle .theme-icon-light { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-light  { display: block; }
[data-theme="dark"] .theme-toggle .theme-icon-dark   { display: none; }

.content {
  flex: 1 1 auto;
  padding: 1.4rem;
  max-width: 1560px;
  width: 100%;
}

.app-footer {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: .78rem;
}
.app-footer .dot { opacity: .6; }

/* =====================================================================
   Cards
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  flex-wrap: wrap;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: .97rem; font-weight: 650; }
.card-head p  { margin: .15rem 0 0; font-size: .78rem; color: var(--text-muted); }
.card-body { padding: 1.15rem; }
.card-body.tight { padding: .6rem; }
.card-foot {
  padding: .8rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .82rem;
}

/* ---------- KPI tiles ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(212px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .18s, box-shadow .18s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::after {
  content: "";
  position: absolute; inset: 0 0 auto 0;
  height: 3px;
  background: var(--kpi-accent, var(--brand));
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.kpi-label {
  font-size: .715rem;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  font-size: .95rem;
  background: var(--kpi-soft, var(--brand-soft));
  color: var(--kpi-accent, var(--brand));
  flex: 0 0 34px;
}
.kpi-value {
  margin-top: .55rem;
  font-size: 1.62rem;
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: 1.15;
}
.kpi-sub { margin-top: .3rem; font-size: .77rem; color: var(--text-muted); }
.kpi-delta { font-weight: 650; }
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

.kpi.kpi-brand    { --kpi-accent: var(--brand);   --kpi-soft: rgba(79,70,229,.12); }
.kpi.kpi-success  { --kpi-accent: var(--success); --kpi-soft: rgba(16,185,129,.14); }
.kpi.kpi-warning  { --kpi-accent: var(--warning); --kpi-soft: rgba(245,158,11,.15); }
.kpi.kpi-danger   { --kpi-accent: var(--danger);  --kpi-soft: rgba(239,68,68,.13); }
.kpi.kpi-info     { --kpi-accent: var(--info);    --kpi-soft: rgba(14,165,233,.13); }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-aside   { grid-template-columns: minmax(0, 1fr) minmax(0, 340px); }
@media (max-width: 1100px) {
  .grid-sidebar, .grid-aside { grid-template-columns: 1fr; }
}

/* =====================================================================
   Charts (pure CSS/SVG - no external dependency)
   ===================================================================== */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: .55rem;
  height: 220px;
  padding: .5rem .2rem 0;
}
.chart-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  min-width: 0;
  height: 100%;
}
.chart-stack { display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.chart-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: opacity .15s;
  position: relative;
}
.chart-bar.revenue { background: linear-gradient(180deg, #6366f1, #4f46e5); }
.chart-bar.costs   { background: linear-gradient(180deg, #fb923c, #f97316); border-radius: 0 0 4px 4px; }
.chart-col:hover .chart-bar { opacity: .78; }
.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: .5rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
  font-size: .7rem;
  color: var(--text-soft);
}
.chart-labels { display: flex; gap: .55rem; margin-top: .55rem; flex-wrap: wrap; }
.chart-legend {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .76rem; color: var(--text-muted);
}
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.progress {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span {
  display: block; height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width .3s;
}
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }
.progress.danger  > span { background: var(--danger); }

/* ---------- Donut ---------- */
.donut-wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.donut {
  width: 132px; height: 132px;
  flex: 0 0 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}
.donut::after {
  content: "";
  position: absolute;
  inset: 20px;
  background: var(--surface);
  border-radius: 50%;
}
.donut-center {
  position: relative;
  z-index: 1;
  text-align: center;
  font-size: .72rem;
  color: var(--text-muted);
}
.donut-center strong { display: block; font-size: 1.05rem; color: var(--text); }

/* =====================================================================
   Tables
   ===================================================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .865rem;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: .62rem .8rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .705rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}
.table thead th a { color: inherit; }
.table thead th a:hover { color: var(--text); text-decoration: none; }
.table tbody td {
  padding: .68rem .8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td {
  padding: .68rem .8rem;
  background: var(--surface-2);
  border-top: 2px solid var(--border);
  font-weight: 650;
}
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }

.cell-main { font-weight: 600; }
.cell-sub  { font-size: .755rem; color: var(--text-muted); }

.ident {
  display: flex; align-items: center; gap: .55rem;
  min-width: 0;
}
.ident .avatar { width: 32px; height: 32px; flex: 0 0 32px; font-size: .7rem; }
.ident-text { min-width: 0; }
.ident-text strong {
  display: block;
  font-size: .865rem;
  font-weight: 620;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ident-text small {
  display: block;
  color: var(--text-muted);
  font-size: .74rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .715rem;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success { background: rgba(16,185,129,.14); color: #059669; }
.badge-warning { background: rgba(245,158,11,.16); color: #b45309; }
.badge-danger  { background: rgba(239,68,68,.14);  color: #dc2626; }
.badge-info    { background: rgba(14,165,233,.14); color: #0284c7; }
.badge-muted   { background: var(--surface-3);     color: var(--text-muted); }
.badge-brand   { background: var(--brand-soft);     color: var(--brand); }
.badge-no-dot::before { display: none; }

[data-theme="dark"] .badge-success { color: #34d399; }
[data-theme="dark"] .badge-warning { color: #fbbf24; }
[data-theme="dark"] .badge-danger  { color: #f87171; }
[data-theme="dark"] .badge-info    { color: #38bdf8; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .52rem .95rem;
  border: 1px solid transparent;
  border-radius: 9px;
  font-family: inherit;
  font-size: .845rem;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }
.btn-sm  { padding: .32rem .62rem; font-size: .78rem; border-radius: 7px; }
.btn-lg  { padding: .68rem 1.3rem; font-size: .93rem; }
.btn-block { display: flex; width: 100%; }

/* Icon-only buttons (the per-row actions) carry no text, so padding alone
   leaves a lopsided box. Lock them to a square that matches .icon-btn and
   centre the glyph. */
.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
}
.btn-icon.btn-sm { width: 30px; height: 30px; min-width: 30px; }
.btn-icon i { font-size: .95rem; line-height: 1; }
.btn-icon.btn-sm i { font-size: .85rem; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { background: var(--surface-3); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
/* WhatsApp brand green, kept in the same slot as the other action buttons */
.btn-whatsapp { background: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1da851; color: #fff; }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }

.btn-group { display: inline-flex; gap: .35rem; flex-wrap: wrap; }

/* =====================================================================
   Forms
   ===================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.field { display: flex; flex-direction: column; gap: .34rem; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field.span-full { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .field.span-2 { grid-column: span 1; }
}

.field label {
  font-size: .775rem;
  font-weight: 620;
  color: var(--text);
}
.field label .req { color: var(--danger); margin-left: .15rem; }
.field .hint { font-size: .72rem; color: var(--text-soft); }
.field .err  { font-size: .74rem; color: var(--danger); font-weight: 550; }

.input, .field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field input[type=date], .field input[type=month],
.field input[type=tel], .field input[type=url], .field select, .field textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: .875rem;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field input[readonly], .field input:disabled, .field select:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: not-allowed;
}
.field input.is-error, .field select.is-error, .field textarea.is-error {
  border-color: var(--danger);
}
.field input[type=color] { padding: .2rem; height: 40px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  cursor: pointer;
  font-size: .86rem;
  user-select: none;
}
.check input[type=checkbox], .check input[type=radio] {
  width: 17px; height: 17px;
  margin: .12rem 0 0;
  accent-color: var(--brand);
  cursor: pointer;
  flex: 0 0 auto;
}
.check span small { display: block; color: var(--text-muted); font-size: .74rem; }

.input-group { display: flex; align-items: stretch; }
.input-group .prefix {
  display: grid; place-items: center;
  padding: 0 .65rem;
  border: 1px solid var(--border-strong);
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 600;
}
.input-group input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important; }

fieldset.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1rem;
}
fieldset.group > legend {
  padding: 0 .45rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .7rem;
  padding: .9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.filters .field { min-width: 148px; }

/* ---------- Line item repeater (invoice editor) ---------- */
.items-table input, .items-table select {
  padding: .42rem .55rem;
  font-size: .82rem;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
.items-table input:focus, .items-table select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.items-table td { padding: .35rem .4rem; }
.line-total { font-weight: 650; font-variant-numeric: tabular-nums; }

/* =====================================================================
   Misc UI
   ===================================================================== */
.empty-state { padding: 2.6rem 1.2rem; text-align: center; }
.empty-state i {
  font-size: 2.1rem;
  color: var(--text-soft);
  opacity: .5;
  display: block;
  margin-bottom: .6rem;
}
.empty-state h3 { font-size: .98rem; margin-bottom: .25rem; }
.empty-state p  { margin: 0 0 1rem; color: var(--text-muted); font-size: .85rem; }

.alert {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: .855rem;
  margin-bottom: 1rem;
}
.alert i { font-size: 1rem; flex: 0 0 auto; margin-top: .1rem; }
.alert-success { background: rgba(16,185,129,.10); border-color: rgba(16,185,129,.32); color: #047857; }
.alert-danger  { background: rgba(239,68,68,.09);  border-color: rgba(239,68,68,.30); color: #b91c1c; }
.alert-warning { background: rgba(245,158,11,.11); border-color: rgba(245,158,11,.33); color: #b45309; }
.alert-info    { background: rgba(14,165,233,.10); border-color: rgba(14,165,233,.30); color: #0369a1; }
[data-theme="dark"] .alert-success { color: #34d399; }
[data-theme="dark"] .alert-danger  { color: #fca5a5; }
[data-theme="dark"] .alert-warning { color: #fcd34d; }
[data-theme="dark"] .alert-info    { color: #7dd3fc; }

.flash-stack {
  position: fixed;
  top: calc(var(--topbar-h) + .6rem);
  right: 1.1rem;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  max-width: min(400px, calc(100vw - 2rem));
}
.flash {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .75rem .85rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: .855rem;
  animation: slideIn .28s cubic-bezier(.4, 0, .2, 1) both;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(22px); }
  to   { opacity: 1; transform: translateX(0); }
}
.flash i { font-size: 1rem; flex: 0 0 auto; margin-top: .1rem; }
.flash span { flex: 1 1 auto; }
.flash-close {
  background: none; border: 0;
  color: var(--text-soft);
  font-size: 1.15rem; line-height: 1;
  cursor: pointer; padding: 0 .1rem;
}
.flash-success { border-left: 3px solid var(--success); }
.flash-success i { color: var(--success); }
.flash-danger  { border-left: 3px solid var(--danger); }
.flash-danger i { color: var(--danger); }
.flash-warning { border-left: 3px solid var(--warning); }
.flash-warning i { color: var(--warning); }
.flash-info    { border-left: 3px solid var(--info); }
.flash-info i { color: var(--info); }
.flash.is-hiding { animation: slideOut .22s ease forwards; }
@keyframes slideOut {
  to { opacity: 0; transform: translateX(22px); }
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  flex-wrap: wrap;
  padding: .8rem 1.15rem;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--text-muted);
}
.pagination .pages { display: flex; gap: .25rem; flex-wrap: wrap; }
.page-link {
  min-width: 32px;
  height: 32px;
  padding: 0 .5rem;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
}
.page-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.page-link.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.page-link.is-disabled { opacity: .45; pointer-events: none; }

.tabs {
  display: flex;
  gap: .15rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  overflow-x: auto;
}
.tab {
  padding: .6rem .9rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: .865rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1.1rem; font-size: .865rem; }
.detail-list dt { color: var(--text-muted); font-size: .8rem; }
.detail-list dd { margin: 0; font-weight: 550; }

.kv-rows > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .42rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: .865rem;
}
.kv-rows > div:last-child { border-bottom: 0; }
.kv-rows .k { color: var(--text-muted); }
.kv-rows .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.kv-rows .total-row {
  border-top: 2px solid var(--border);
  border-bottom: 0;
  margin-top: .3rem;
  padding-top: .6rem;
  font-size: 1.02rem;
}
.kv-rows .total-row .v { color: var(--brand); font-weight: 700; }

/* ---------- Timeline / feed ---------- */
.feed { display: flex; flex-direction: column; }
.feed-item {
  display: flex;
  gap: .75rem;
  padding: .68rem 0;
  border-bottom: 1px solid var(--border);
}
.feed-item:last-child { border-bottom: 0; padding-bottom: 0; }
.feed-item:first-child { padding-top: 0; }
.feed-icon {
  width: 32px; height: 32px; flex: 0 0 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: .85rem;
}
.feed-text { flex: 1 1 auto; min-width: 0; font-size: .855rem; }
.feed-text strong { font-weight: 600; }
.feed-time { font-size: .72rem; color: var(--text-soft); white-space: nowrap; }

/* ---------- Payment method chips (bKash etc.) ---------- */
.pay-methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .8rem; }
.pay-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.pay-logo {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  font-weight: 800;
  font-size: .74rem;
  color: #fff;
  background: #e2136e; /* bKash brand pink as default */
}
.pay-logo.nagad   { background: #ec1c24; }
.pay-logo.rocket  { background: #8b2985; }
.pay-logo.bank    { background: #2563eb; }
.pay-logo.card    { background: #0f766e; }
.pay-logo.other   { background: var(--text-muted); }
.pay-meta strong { display: block; font-size: .875rem; }
.pay-meta small  { display: block; color: var(--text-muted); font-size: .76rem; }
.pay-number {
  font-family: var(--mono);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .02em;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1rem;
  animation: fadeIn .18s ease;
}
/* The UA rule for [hidden] is display:none, but an author class selector of
   equal specificity wins on source order, which left the modal permanently
   on screen. Re-assert it with higher specificity. */
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: min(560px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: popIn .2s cubic-bezier(.4, 0, .2, 1);
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.96) translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .95rem 1.15rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1rem; }
.modal-head .icon-btn { border: 0; background: transparent; font-size: 1.35rem; }
.modal-body { padding: 1.15rem; overflow-y: auto; }

/* ---------- Print / invoice document ---------- */
.doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 900px;
  margin: 0 auto;
}
.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 1.6rem;
  flex-wrap: wrap;
  padding-bottom: 1.3rem;
  border-bottom: 2px solid var(--border);
}
.doc-company h2 { font-size: 1.3rem; }
.doc-company p  { margin: .2rem 0 0; font-size: .84rem; color: var(--text-muted); }
.doc-company .doc-name-bangla { font-size: 1rem; color: var(--text); font-weight: 600; }
.doc-company .doc-shop-name { font-size: .84rem; color: var(--text); }

/* Bismillah line, centred above the invoice header */
.doc-bismillah {
margin: 0 0 1.1rem;
text-align: center;
font-size: 1.05rem;
font-weight: 600;
color: var(--text);
letter-spacing: .01em;
}
.doc-meta { text-align: right; }
.doc-meta h1 { font-size: 1.5rem; letter-spacing: .02em; }
.doc-meta .doc-num {
  font-family: var(--mono);
  font-size: .9rem;
  color: var(--brand);
  font-weight: 600;
}
.doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.6rem;
  padding: 1.3rem 0;
}
.doc-party h4 {
  font-size: .71rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.doc-party p { margin: 0; font-size: .875rem; line-height: 1.6; }
.doc-totals { margin-left: auto; width: min(320px, 100%); margin-top: 1.2rem; }
.doc-terms {
margin-top: 1.8rem;
padding-top: 1.1rem;
border-top: 1px solid var(--border);
font-size: .82rem;
color: var(--text-muted);
}
/* Authorised signatory, printed above the terms */
.doc-signature {
margin-top: 1.8rem;
display: flex;
justify-content: flex-end;
}
.doc-signature-rule {
width: 200px;
border-top: 1px solid var(--text-muted);
margin-bottom: .35rem;
}
.doc-signature-text {
width: 200px;
text-align: center;
font-size: .82rem;
color: var(--text-muted);
}
.doc-signature-text strong { display: block; color: var(--text); }
.doc-signature-text span { display: block; }
/* Global clauses from Settings -> Terms & Conditions */.doc-terms-global {
margin-top: 1rem;
padding: .85rem 1rem;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--surface-3);
}
.doc-terms-global h4 { margin-top: 0; }
.doc-watermark {
  position: relative;
  overflow: hidden;
}
.doc-watermark::after {
  content: attr(data-watermark);
  position: absolute;
  top: 42%; left: 50%;
  transform: translate(-50%, -50%) rotate(-32deg);
  font-size: 5.5rem;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--danger);
  opacity: .07;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- Login ---------- */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-aside {
  background: linear-gradient(150deg, #1e1b4b 0%, #312e81 45%, #4f46e5 100%);
  color: #fff;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.auth-aside::before,
.auth-aside::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .07);
}
.auth-aside::before { width: 380px; height: 380px; top: -110px; right: -110px; }
.auth-aside::after  { width: 280px; height: 280px; bottom: -80px; left: -70px; }
.auth-aside h2 { font-size: 1.85rem; line-height: 1.3; margin-bottom: .9rem; }
.auth-aside p  { color: rgba(255,255,255,.78); max-width: 42ch; margin: 0; }
.auth-features {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  position: relative;
  z-index: 1;
}
.auth-feature { display: flex; align-items: center; gap: .7rem; font-size: .9rem; color: rgba(255,255,255,.92); }
.auth-feature i { color: #a5b4fc; font-size: 1.05rem; }
.auth-main {
  display: grid;
  place-items: center;
  padding: 2rem;
  background: var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff;
  font-weight: 800;
  font-size: 1.15rem;
  margin-bottom: 1.1rem;
}
.auth-card h1 { font-size: 1.45rem; margin-bottom: .3rem; }
.auth-card > p { color: var(--text-muted); font-size: .88rem; margin: 0 0 1.5rem; }
.auth-foot { margin-top: 1.4rem; text-align: center; font-size: .78rem; color: var(--text-soft); }

/* ---------- Utilities ---------- */
.divider { height: 1px; background: var(--border); margin: 1.1rem 0; border: 0; }
.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  padding: .9rem 0 0;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: .42rem 0; border-bottom: 1px solid var(--border); font-size: .855rem; }
.list-plain li:last-child { border-bottom: 0; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1200px) {
  .search-form input { width: 180px; }
  .search-form input:focus { width: 210px; }
}

@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar-close { display: block; }
  .menu-toggle { display: inline-grid; }
  .main { margin-left: 0; }
  .doc-parties { grid-template-columns: 1fr; gap: 1.1rem; }
  .doc-meta { text-align: left; }
}

@media (max-width: 768px) {
  body { font-size: 14.5px; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem .9rem; gap: .6rem; }
  .topbar-title h1 { font-size: 1.1rem; }
  .topbar-title p { display: none; }
  .search-form { display: none; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: .52rem .7rem; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: .7rem; }
  .kpi { padding: .85rem .9rem; }
  .kpi-value { font-size: 1.32rem; }
  .flash-stack { left: .7rem; right: .7rem; max-width: none; }
  .doc { padding: 1.15rem; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .chart-bars { height: 165px; }
  .donut { width: 112px; height: 112px; flex: 0 0 112px; }
  .donut::after { inset: 17px; }
  .app-footer { justify-content: center; }
}

@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .card-head { padding: .85rem; }
  .card-body { padding: .9rem; }
  .form-grid { grid-template-columns: 1fr; }
  .filters { padding: .75rem .85rem; }
  .filters .field { min-width: 100%; }
  .table thead { display: none; }
  .table.table-stack tbody tr {
    display: block;
    border-bottom: 1px solid var(--border);
    padding: .5rem 0;
  }
  .table.table-stack tbody td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border: 0;
    padding: .2rem .85rem;
    text-align: right;
  }
  .table.table-stack tbody td::before {
    content: attr(data-label);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    text-align: left;
  }
  .table.table-stack tbody td.col-actions { justify-content: flex-end; }
  .table.table-stack tbody td.col-actions::before { display: none; }
}

/* =====================================================================
   Print
   ===================================================================== */
@media print {
  .sidebar, .topbar, .app-footer, .flash-stack, .sidebar-backdrop,
  .no-print, .pagination, .filters, .btn, .card-foot { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body, .card, .doc { background: #fff !important; color: #000 !important; }
  .card { border: 0; box-shadow: none; }
  .doc { padding: 0; max-width: none; border: 0; }
  .table thead th { background: #f3f4f6 !important; color: #000 !important; }
  .table tbody td { border-color: #ddd !important; }
  a { color: #000 !important; text-decoration: none; }
  @page { margin: 14mm; size: A4; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}