/* ====================================================
   InvoiceFlow – style.css
   Premium dark-mode design with glassmorphism
   ==================================================== */

/* ---------- CSS Reset & Variables ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --bg-base:       #0d0f14;
  --bg-surface:    #13161e;
  --bg-card:       #1a1e2a;
  --bg-card-hover: #1e2330;
  --bg-input:      #111420;
  --bg-modal:      #161924;

  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,102,241,0.6);

  --accent:        #6366f1;
  --accent-2:      #8b5cf6;
  --accent-glow:   rgba(99,102,241,0.25);
  --accent-green:  #22c55e;
  --accent-amber:  #f59e0b;
  --accent-red:    #ef4444;
  --accent-blue:   #3b82f6;
  --accent-teal:   #14b8a6;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #475569;

  /* Spacing */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  22px;

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-collapsed-w: 64px;
}

/* ===================== LIGHT MODE ===================== */
body.light {
  --bg-base:       #f0f2f8;
  --bg-surface:    #ffffff;
  --bg-card:       #ffffff;
  --bg-card-hover: #f8f9ff;
  --bg-input:      #f4f5fb;
  --bg-modal:      #ffffff;

  --border:        rgba(0,0,0,0.09);
  --border-focus:  rgba(99,102,241,0.5);

  --text-primary:  #1e2330;
  --text-secondary:#4a5568;
  --text-muted:    #9aa5b4;
}

body.light ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); }
body.light thead { background: rgba(0,0,0,0.03); }
body.light tbody tr:hover { background: rgba(0,0,0,0.02); }
body.light .modal { box-shadow: 0 24px 80px rgba(0,0,0,0.18); }
body.light .toast { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
body.light select option { background: #fff; }

html { font-size: 15px; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  transition: background 0.25s, color 0.25s;
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 99px; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

/* Collapsed sidebar */
body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-w); }
body.sidebar-collapsed .brand-name {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
}
body.sidebar-collapsed .nav-item span {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}
body.sidebar-collapsed .sidebar-footer { opacity: 0; pointer-events: none; height: 0; padding: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 22px 0 18px; gap: 0; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 12px 0; gap: 0; }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed-w); }

.brand-name { transition: opacity 0.2s, max-width 0.25s cubic-bezier(0.4,0,0.2,1); max-width: 200px; overflow: hidden; white-space: nowrap; }
.sidebar-footer { transition: opacity 0.2s, height 0.25s, padding 0.25s; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.18s ease;
  overflow: hidden;
  white-space: nowrap;
}

.nav-item span {
  max-width: 200px;
  overflow: hidden;
  transition: max-width 0.25s cubic-bezier(0.4,0,0.2,1), opacity 0.2s;
  white-space: nowrap;
}

.nav-item svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  transition: all 0.18s;
}

.nav-item:hover {
  background: rgba(99,102,241,0.1);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.25), rgba(139,92,246,0.15));
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,0.25);
}

.nav-item.active svg { color: #a5b4fc; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.company-mini {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-version {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===================== MAIN CONTENT ===================== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s cubic-bezier(0.4,0,0.2,1);
  overflow-x: hidden;
  min-width: 0;
}

/* ===================== TOPBAR ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* sidebar + theme toggle buttons in topbar */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.icon-btn svg { width: 18px; height: 18px; }

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ===================== VIEW CONTAINER ===================== */
.view-container {
  flex: 1;
  padding: 28px 32px;
}

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99,102,241,0.45);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239,68,68,0.25);
}

.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-success {
  background: rgba(34,197,94,0.15);
  color: var(--accent-green);
  border: 1px solid rgba(34,197,94,0.25);
}

.btn-success:hover { background: rgba(34,197,94,0.25); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon { padding: 8px; }

/* ===================== CARDS ===================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.card-sm { padding: 16px; }

/* ===================== DASHBOARD ===================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

/* Dashboard two-column recent tables */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  min-width: 0;
}

.dash-grid > * {
  min-width: 0;
  overflow: auto;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s, border-color 0.18s;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-card.indigo::before  { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.kpi-card.green::before   { background: linear-gradient(90deg, #22c55e, #16a34a); }
.kpi-card.amber::before   { background: linear-gradient(90deg, #f59e0b, #d97706); }
.kpi-card.blue::before    { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.kpi-card.teal::before    { background: linear-gradient(90deg, #14b8a6, #0d9488); }

.kpi-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.12); }

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kpi-value {
  font-size: clamp(1.1rem, 2vw, 1.8rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ===================== SECTION HEADER ===================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===================== TABLE ===================== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

thead {
  background: rgba(255,255,255,0.03);
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.14s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }

tbody td {
  padding: 13px 16px;
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody td:first-child { color: var(--text-primary); font-weight: 500; }

.td-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
}

.badge-draft    { background: rgba(100,116,139,0.2); color: #94a3b8; }
.badge-draft::before { background: #64748b; }
.badge-sent     { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-sent::before { background: #3b82f6; }
.badge-paid     { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-paid::before { background: #22c55e; }
.badge-overdue  { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-overdue::before { background: #ef4444; }
.badge-accepted { background: rgba(20,184,166,0.15); color: #2dd4bf; }
.badge-accepted::before { background: #14b8a6; }
.badge-declined { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-declined::before { background: #ef4444; }
.badge-converted{ background: rgba(139,92,246,0.15); color: #c084fc; }
.badge-converted::before { background: #8b5cf6; }
.badge-expired  { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-expired::before { background: #f59e0b; }

/* ===================== FILTERS ===================== */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===================== FORMS ===================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="search"],
textarea,
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 14px;
  width: 100%;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { resize: vertical; min-height: 80px; }

select option { background: var(--bg-modal); }

/* Logo upload */
.logo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.logo-upload-area:hover, .logo-upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.05);
}

.logo-upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.logo-preview {
  max-height: 80px;
  max-width: 200px;
  object-fit: contain;
  display: block;
  margin: 0 auto 10px;
  border-radius: var(--radius-sm);
}

.logo-upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===================== LINE ITEMS ===================== */
.line-items-header {
  display: grid;
  grid-template-columns: 2.5fr 1fr 1fr 1fr auto;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.line-items-header span {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.line-item-row {
  display: grid;
  grid-template-columns: 2.5fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.line-item-total {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
}

.line-item-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  display: flex;
  align-items: center;
}

.line-item-del:hover { color: var(--accent-red); background: rgba(239,68,68,0.1); }
.line-item-del svg { width: 16px; height: 16px; }

/* Totals section */
.totals-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.total-row {
  display: flex;
  gap: 24px;
  justify-content: flex-end;
  align-items: center;
  min-width: 300px;
}

.total-row .total-label {
  font-size: 0.83rem;
  color: var(--text-secondary);
  flex: 1;
  text-align: right;
}

.total-row .total-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 100px;
  text-align: right;
}

.total-row.grand {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.total-row.grand .total-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.total-row.grand .total-value {
  font-size: 1.1rem;
  color: #a5b4fc;
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: modalIn 0.22s ease;
}

.modal.modal-wide { max-width: 880px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}

.modal-close svg { width: 18px; height: 18px; }
.modal-close:hover { background: rgba(239,68,68,0.15); color: var(--accent-red); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ===================== TOAST ===================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 260px;
  animation: toastIn 0.25s ease;
  color: var(--text-primary);
}

.toast-success { border-color: rgba(34,197,94,0.4); }
.toast-success .toast-icon { color: var(--accent-green); }
.toast-error   { border-color: rgba(239,68,68,0.4); }
.toast-error .toast-icon   { color: var(--accent-red); }
.toast-info    { border-color: rgba(99,102,241,0.4); }
.toast-info .toast-icon    { color: #a5b4fc; }

.toast-icon svg { width: 18px; height: 18px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===================== EMPTY STATE ===================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p { font-size: 0.85rem; }

/* ===================== SETTINGS ===================== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 700px) {
  .settings-grid { grid-template-columns: 1fr; }
}

/* ===================== DOCUMENT VIEW (PRINT) ===================== */
.doc-view {
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.doc-header {
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.1));
  border-bottom: 1px solid var(--border);
  padding: 36px 40px 28px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.doc-logo {
  max-height: 64px;
  max-width: 180px;
  object-fit: contain;
  display: block;
  margin-bottom: 8px;
}

.doc-company-name {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.doc-logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #a5b4fc, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.doc-company-info { font-size: 0.83rem; color: var(--text-secondary); line-height: 1.6; }

.doc-meta { text-align: right; }

.doc-type-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(139,92,246,0.2));
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,0.3);
}

.doc-number {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
}

.doc-dates { font-size: 0.82rem; color: var(--text-secondary); margin-top: 6px; line-height: 1.8; }

.doc-body { padding: 32px 40px; }

.doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.doc-party-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.doc-party-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.doc-party-details {
  font-size: 0.83rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-line;
}

.doc-table-wrap { border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); margin-bottom: 24px; }

.doc-table th { background: rgba(255,255,255,0.04); }

.doc-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}

.doc-notes {
  margin-top: 28px;
  padding: 16px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.doc-notes-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 6px; }
.doc-notes-text { font-size: 0.85rem; color: var(--text-secondary); white-space: pre-line; }

.doc-footer-strip {
  padding: 16px 40px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Signature area */
.doc-signature {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 40px;
}

.signature-box {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===================== PRINT AREA ===================== */
.print-area { display: none; }

/* ===================== MISC ===================== */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* Number chips */
.doc-number-chip {
  font-family: 'Inter', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
  background: rgba(99,102,241,0.15);
  color: #a5b4fc;
  letter-spacing: 0.02em;
}

/* Items catalog cards */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: all 0.18s;
}

.item-card:hover { border-color: rgba(99,102,241,0.3); transform: translateY(-2px); }

.item-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.item-card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
  min-height: 20px;
}

.item-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-unit-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  background: rgba(255,255,255,0.07);
  border-radius: 99px;
  color: var(--text-secondary);
}

.item-price {
  font-size: 1rem;
  font-weight: 700;
  color: #a5b4fc;
}

/* ===================== OI-DOC: INVOICE HOME AESTHETIC ===================== */
/*
  All classes prefixed "oi-" are used exclusively for the document
  preview/print output (buildDocHTML). They intentionally use fixed
  light-theme colours so the printed PDF always looks correct regardless of
  whether the app is in dark or light mode.
*/

/* ─────────────────────────────────────────────────────────────────────────────
   OI-DOC layout strategy:
   • Screen preview: fixed 794px (A4 at 96dpi) centred in a grey modal wrapper
   • Print / PDF:    width:210mm fills the real A4 page; @page margin:0 gives us
                     full control and hides browser URL/date headers
   Content padding (15mm ≈ 57px) acts as the page margin in both contexts.
───────────────────────────────────────────────────────────────────────────── */
.oi-doc {
  background: #fff;
  color: #1a2340;
  font-family: Arial, 'Helvetica Neue', sans-serif;
  width: 794px;          /* A4 @ 96 dpi for screen preview */
  min-height: 1123px;    /* A4 height @ 96 dpi */
  margin: 0 auto;
  border: none;
  border-radius: 0;
  box-shadow: 0 6px 36px rgba(0,0,0,0.35);
  overflow: visible;
  position: relative;
  box-sizing: border-box;
}

/* Wrapper: grey "desk" behind the white A4 sheet in the modal */
.oi-doc-wrap {
  background: #60606e;
  padding: 28px 20px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Top header row ──
   Padding = 15mm ≈ 57px horizontally, 12mm ≈ 45px vertical
   This acts as the page margin when @page margin is 0 */
.oi-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 45px 57px 24px;
  border-bottom: 2px solid #1a2340;
}

.oi-top-left { flex: 1; }

.oi-title {
  font-size: 3rem;
  font-weight: 900;
  color: #1a2340;
  line-height: 1;
  margin-bottom: 10px;
  letter-spacing: -1px;
}

.oi-company-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1a2340;
  margin-bottom: 4px;
}

.oi-company-addr {
  font-size: 0.83rem;
  color: #e07b00;  /* orange – matches original */
}

.oi-top-right {
  flex-shrink: 0;
  text-align: right;
  max-width: 180px;
}

.oi-logo {
  max-height: 90px;
  max-width: 180px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin-left: auto;
  border-radius: 4px;
}

.oi-shipping-label {
  margin-top: 10px;
  font-size: 0.75rem;
  color: #475569;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.oi-shipping-addr {
  margin-top: 6px;
  font-size: 0.84rem;
  color: #1a2340;
  line-height: 1.4;
}

/* ── Bill To / Doc Info row ── */
.oi-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 57px;
  gap: 24px;
}

.oi-bill-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #1a58c8;  /* blue */
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.oi-bill-name {
  font-size: 0.92rem;
  color: #1a2340;
  margin-bottom: 2px;
}

.oi-bill-addr {
  font-size: 0.82rem;
  color: #e07b00;  /* orange */
  line-height: 1.6;
}

.oi-docinfo {
  text-align: right;
  min-width: 240px;
}

.oi-docinfo-row {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  margin-bottom: 4px;
  align-items: baseline;
}

.oi-di-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #1a58c8;  /* blue */
  letter-spacing: 0.03em;
  text-align: right;
}

.oi-di-val {
  font-size: 0.88rem;
  color: #1a2340;
  min-width: 80px;
  text-align: right;
}

/* ── Line-items table ── */
.oi-table-wrap {
  padding: 0 57px;
  margin-bottom: 0;
}

.oi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.oi-table thead tr {
  background: #1a2340;
}

.oi-table thead th {
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 10px 12px;
  border: none;
}

.oi-th-qty    { width: 60px;  text-align: center; }
.oi-th-desc   { text-align: left; }
.oi-th-price  { width: 130px; text-align: right; }
.oi-th-amount { width: 130px; text-align: right; }

.oi-table tbody tr {
  border-bottom: 1px solid #ebebeb;
}

.oi-table tbody tr:last-child { border-bottom: none; }

.oi-td-qty {
  text-align: center;
  color: #1a2340;
  padding: 10px 12px;
  vertical-align: top;
}

.oi-td-desc {
  color: #e07b00; /* orange for descriptions, matching original */
  padding: 10px 12px;
  vertical-align: top;
  line-height: 1.5;
}

.oi-td-price {
  text-align: right;
  color: #1a2340;
  padding: 10px 12px;
  vertical-align: top;
}

.oi-td-amount {
  text-align: right;
  color: #1a2340;
  font-weight: 500;
  padding: 10px 12px;
  vertical-align: top;
}

/* ── Totals ── */
.oi-totals {
  padding: 10px 57px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.oi-sub-row {
  display: flex;
  gap: 40px;
  justify-content: flex-end;
  font-size: 0.87rem;
  color: #1a2340;
  min-width: 340px;
}

.oi-sub-row span:first-child {
  text-align: right;
  flex: 1;
}

.oi-sub-row span:last-child {
  min-width: 110px;
  text-align: right;
}

.oi-total-row {
  display: flex;
  gap: 40px;
  justify-content: flex-end;
  align-items: center;
  min-width: 340px;
  border-top: 2px solid #1a2340;
  margin-top: 4px;
  padding-top: 8px;
}

.oi-total-row span:first-child {
  font-size: 1.3rem;
  font-weight: 800;
  color: #1a2340;
  text-align: right;
  flex: 1;
}

.oi-total-row span:last-child {
  font-size: 1.6rem;
  font-weight: 900;
  color: #1a58c8;   /* big blue total */
  min-width: 140px;
  text-align: right;
}

/* ── Notes ── */
.oi-notes {
  padding: 0 57px 20px;
  font-size: 0.82rem;
  color: #555;
  white-space: pre-line;
}

/* ── Footer (Thank you + bank) ── */
.oi-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 57px;
  border-top: 1px solid #e0e0e0;
  gap: 24px;
}

.oi-thankyou {
  font-size: 2rem;
  font-weight: 700;
  color: #1a58c8;
  font-style: italic;
}

.oi-bank {
  font-size: 0.78rem;
  color: #1a2340;
  text-align: right;
  line-height: 1.8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.oi-footer-simple {
  padding: 16px 57px;
  border-top: 1px solid #e0e0e0;
  font-size: 0.8rem;
  color: #888;
  text-align: center;
}

/* ===================== @MEDIA PRINT ===================== */
@media print {
  /* Hide the entire app UI; only the invisible print-area div renders */
  body > * { display: none !important; }

  .print-area {
    display: block !important;
    background: #fff !important;
    margin: 0;
    padding: 0;
  }

  /* Strip wrapper chrome – the oi-doc becomes the page itself */
  .print-area .oi-doc-wrap {
    background: none !important;
    padding: 0 !important;
    display: block !important;
  }

  .print-area .oi-doc {
    /* Use real mm units so the browser never has to scale */
    width: 210mm !important;
    min-height: auto !important;
    box-shadow: none !important;
    margin: 0 !important;
    border: none !important;
  }

  /* Force ALL background colours and images to print as designed */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Preserve brand colours */
  .oi-title         { color: #1a2340 !important; }
  .oi-company-name  { color: #1a2340 !important; }
  .oi-company-addr  { color: #e07b00 !important; }
  .oi-bill-label    { color: #1a58c8 !important; }
  .oi-bill-name     { color: #1a2340 !important; }
  .oi-bill-addr     { color: #e07b00 !important; }
  .oi-di-label      { color: #1a58c8 !important; }
  .oi-di-val        { color: #1a2340 !important; }
  .oi-td-qty        { color: #1a2340 !important; }
  .oi-td-desc       { color: #e07b00 !important; }
  .oi-td-price      { color: #1a2340 !important; }
  .oi-td-amount     { color: #1a2340 !important; }
  .oi-thankyou      { color: #1a58c8 !important; }
  .oi-bank          { color: #1a2340 !important; }
  .oi-total-row span:first-child { color: #1a2340 !important; }
  .oi-total-row span:last-child  { color: #1a58c8 !important; }

  /* Navy table header must print as navy */
  .oi-table thead tr {
    background: #1a2340 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .oi-table thead th { color: #fff !important; }

  /* @page: zero margin → no browser URL / date headers in the printout.
     The 15mm breathing room comes from the document's own padding (57px ≈ 15mm). */
  @page {
    size: A4 portrait;
    margin: 0;
  }
}

/* ===================== @MEDIA PRINT + MOBILE ===================== */
@media print and (max-width: 768px) {
  /* Ensure document prints at full width with correct scaling */
  .print-area .oi-doc {
    width: 210mm !important;
  }

  /* Match desktop footer layout even on small screens */
  .print-area .oi-footer {
    flex-direction: row !important;
    justify-content: space-between !important;
    text-align: left !important;
    gap: 24px !important;
    padding: 28px 57px !important;
  }

  .print-area .oi-thankyou {
    font-size: 2rem !important;
    text-align: left !important;
  }

  .print-area .oi-bank {
    text-align: right !important;
  }

  /* Optimize font sizes for small screen printing */
  .print-area .oi-title {
    font-size: 2.5rem !important;
  }

  .print-area .oi-company-name {
    font-size: 0.9rem !important;
  }

  .print-area .oi-table {
    font-size: 0.85rem !important;
  }

  .print-area .oi-top {
    padding: 30px 40px 20px !important;
  }

  .print-area .oi-meta-row {
    padding: 15px 40px !important;
  }
}

/* ===================== MOBILE NAV OVERLAY ===================== */
#mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99; /* just below sidebar (z-index: 100) */
  backdrop-filter: blur(2px);
}

body.mobile-nav-open #mobile-nav-overlay { display: block; }

/* ===================== @MEDIA MOBILE (≤768px) ===================== */
@media (max-width: 768px) {

  /* ── Sidebar: hidden off-screen; slides in as overlay when open ── */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1), width 0.25s cubic-bezier(0.4,0,0.2,1);
    width: var(--sidebar-w) !important; /* always full-width on mobile, never collapsed */
    z-index: 100;
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
  }

  /* When collapsed class is set on desktop, mobile must ignore it */
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w) !important; }
  body.sidebar-collapsed .brand-name { opacity: 1; max-width: 200px; pointer-events: auto; }
  body.sidebar-collapsed .nav-item span { opacity: 1; max-width: 200px; pointer-events: auto; }
  body.sidebar-collapsed .sidebar-footer { opacity: 1; pointer-events: auto; height: auto; padding: 16px 20px; overflow: visible; }
  body.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding: 22px 20px 18px; gap: 10px; }
  body.sidebar-collapsed .nav-item { justify-content: flex-start; padding: 10px 12px; gap: 10px; }

  /* ── Main content: no left margin on mobile ── */
  .main-content {
    margin-left: 0 !important;
  }

  /* ── Topbar ── */
  .topbar {
    padding: 12px 16px;
    gap: 8px;
  }

  .page-title {
    font-size: 1.05rem;
  }

  .topbar-left { gap: 8px; }

  /* Stack topbar-actions below on very small screens if needed */
  .topbar > div:last-child {
    gap: 6px;
  }

  /* ── View container: tighter padding ── */
  .view-container {
    padding: 16px;
  }

  /* ── Filter buttons: responsive styling ── */
  .filter-bar {
    gap: 6px;
    margin-bottom: 16px;
  }

  .filter-btn {
    padding: 5px 11px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── KPI grid: 2 columns minimum ── */
  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
  }

  .kpi-card { padding: 16px; }
  .kpi-value { font-size: clamp(1rem, 4vw, 1.5rem); }

  /* ── Dashboard: stack two-column grid ── */
  .dash-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  /* ── Settings grid: already 1-col at 700px via existing rule ── */

  /* ── Items grid: single column on small screens ── */
  .items-grid {
    grid-template-columns: 1fr;
  }

  /* ── Line items form: switch from 5-col grid to wrapped flex ── */
  .line-items-header {
    display: none; /* replaced by inline labels in the card layout */
  }

  .line-item-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    margin-bottom: 10px;
    position: relative;
  }

  /* Description + item select take full width */
  .line-item-row > div:first-child {
    width: 100%;
    order: 1;
  }

  /* Unit field */
  .line-item-row .li-unit {
    flex: 1 1 80px;
    max-width: 100px;
    order: 2;
  }

  /* Qty field */
  .line-item-row .li-qty {
    flex: 1 1 70px;
    max-width: 90px;
    order: 3;
  }

  /* Price field */
  .line-item-row .li-price {
    flex: 1 1 100px;
    order: 4;
  }

  /* Delete button floats to top-right corner */
  .line-item-del {
    position: absolute;
    top: 8px;
    right: 8px;
    order: 5;
  }

  /* Totals section: remove fixed min-width */
  .total-row {
    min-width: 0;
    width: 100%;
    justify-content: space-between;
    gap: 12px;
  }

  .total-row .total-label { text-align: left; flex: 1; }
  .total-row .total-value { min-width: 80px; }

  /* ── Toast: full-width at bottom ── */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 16px;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }

  /* ── Modal: near-full-screen ── */
  .modal-overlay {
    padding: 8px;
    align-items: center; /* center modal for better document view */
  }

  .modal,
  .modal.modal-wide {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg);
  }

  .modal-header { padding: 16px 18px; }
  .modal-body {
    padding: 12px 0; /* reduce padding on sides to maximize content width */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-body.no-padding { padding: 0; } /* for document preview */

  .modal-footer {
    padding: 12px 18px;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Stack modal footer buttons on very small screens */
  .modal-footer .btn { flex: 1; justify-content: center; min-width: 100px; }

  /* ── Document (A4) preview: responsive layout for mobile ── */
  .oi-doc-wrap {
    padding: 12px;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: #60606e;
  }

  .oi-doc {
    /* Use max-width instead of transform for better readability on mobile */
    width: 100%;
    max-width: 100% !important;
    min-height: auto !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2) !important;
    margin: 0 auto !important;
    /* Scale font sizes down proportionally for mobile */
    font-size: 12px;
  }

  /* Mobile-adjusted typography for document elements */
  .oi-title {
    font-size: 1.8rem;
  }

  .oi-company-name {
    font-size: 0.85rem;
  }

  .oi-company-addr {
    font-size: 0.75rem;
  }

  .oi-top {
    padding: 24px 20px 16px;
    flex-direction: column;
    gap: 16px;
  }

  .oi-meta-row {
    padding: 12px 20px;
    flex-direction: column;
    gap: 16px;
  }

  .oi-docinfo {
    text-align: left;
    min-width: auto;
  }

  .oi-docinfo-row {
    justify-content: flex-start;
  }

  .oi-di-label,
  .oi-di-val {
    text-align: left;
  }

  .oi-table-wrap {
    padding: 0 20px;
  }

  .oi-table {
    font-size: 0.75rem;
  }

  .oi-table thead th {
    padding: 6px 8px;
  }

  .oi-td-qty,
  .oi-td-desc,
  .oi-td-price,
  .oi-td-amount {
    padding: 6px 8px;
  }

  .oi-totals {
    padding: 8px 20px 16px;
  }

  .oi-sub-row,
  .oi-total-row {
    min-width: auto;
    gap: 16px;
  }

  .oi-total-row span:last-child {
    font-size: 1.2rem;
  }

  .oi-notes {
    padding: 0 20px 16px;
    font-size: 0.72rem;
  }

  .oi-footer {
    padding: 16px 20px;
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .oi-thankyou {
    font-size: 1.2rem;
  }

  .oi-bank {
    font-size: 0.7rem;
    text-align: center;
  }

  .oi-footer-simple {
    padding: 12px 20px;
    font-size: 0.7rem;
  }

  .oi-logo {
    max-height: 50px;
    max-width: 120px;
  }

  /* ── Topbar actions: wrap if multiple buttons ── */
  .topbar-actions {
    flex-wrap: wrap;
  }

  /* Shrink "New Invoice" style buttons slightly on mobile */
  .topbar-actions .btn {
    padding: 7px 12px;
    font-size: 0.8rem;
  }

  /* ── Filter bar already wraps via flex-wrap: wrap ── */

  /* ── Reduce empty-state padding ── */
  .empty-state { padding: 40px 16px; }

  /* ── Section header: allow wrapping ── */
  .section-header { flex-wrap: wrap; gap: 8px; }
}

/* Extra-small screens (phones < 400px) */
@media (max-width: 400px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Filter buttons: ultra-compact on tiny screens ── */
  .filter-bar {
    gap: 4px;
    margin-bottom: 12px;
  }

  .filter-btn {
    padding: 4px 9px;
    font-size: 0.7rem;
  }

  /* Further optimize document for tiny screens */
  .oi-doc {
    font-size: 11px;
  }

  .oi-title {
    font-size: 1.4rem;
  }

  .oi-top {
    padding: 16px 16px 12px;
  }

  .oi-meta-row {
    padding: 8px 16px;
  }

  .oi-table-wrap {
    padding: 0 16px;
  }

  .oi-totals {
    padding: 6px 16px 12px;
  }

  .topbar-actions .btn span {
    display: none; /* hide button text, show only icon */
  }
}

/* ===================== REVENUE VIEW ===================== */
.rev-branch-group {
  margin-bottom: 32px;
}

.rev-branch-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.06));
  border: 1px solid rgba(99,102,241,0.25);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.rev-branch-header svg {
  width: 17px; height: 17px;
  color: #a5b4fc;
  flex-shrink: 0;
}

.rev-branch-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.rev-branch-count {
  font-size: 0.73rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
}

/* Table directly below branch header – merge borders */
.rev-table-wrap {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
}

/* Branch total row */
.rev-branch-total {
  background: rgba(99,102,241,0.05);
  border-top: 2px solid rgba(99,102,241,0.2) !important;
}

.rev-branch-total td {
  padding: 11px 16px;
}

.rev-bt-label {
  text-align: right;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.rev-num-cell {
  text-align: right;
  font-weight: 700;
  font-size: 0.88rem;
}

/* Expense input inside table cell */
.rev-expense-cell {
  padding: 6px 10px !important;
}

.rev-expense-input {
  max-width: 118px;
  width: 100%;
  text-align: right;
  padding: 6px 10px !important;
  font-size: 0.84rem !important;
  min-height: unset;
}

/* Grand Totals grid */
.rev-grand-totals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 14px;
  margin-top: 36px;
  padding-top: 28px;
  border-top: 2px solid var(--border);
}

.rev-gt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s, border-color 0.18s;
}

.rev-gt-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.rev-gt-card.indigo::before { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.rev-gt-card.amber::before  { background: linear-gradient(90deg, #f59e0b, #d97706); }
.rev-gt-card.blue::before   { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.rev-gt-card.red::before    { background: linear-gradient(90deg, #ef4444, #dc2626); }
.rev-gt-card.green::before  { background: linear-gradient(90deg, #22c55e, #16a34a); }

.rev-gt-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.12); }

.rev-gt-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.rev-gt-value {
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Light mode tweaks */
body.light .rev-branch-header {
  background: linear-gradient(135deg, rgba(99,102,241,0.07), rgba(139,92,246,0.04));
  border-color: rgba(99,102,241,0.18);
}

body.light .rev-branch-total {
  background: rgba(99,102,241,0.04);
  border-top-color: rgba(99,102,241,0.15) !important;
}

/* Responsive */
@media (max-width: 900px) {
  .rev-grand-totals {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

/* PDF Export Mode Styles (Matches Print View) */
.pdf-export-mode .oi-doc { box-shadow: none !important; padding: 20px 40px !important; margin: 0 !important; max-width: 800px !important; width: 800px !important; border: none !important; }
.pdf-export-mode { position: absolute; top: 0; left: 0; z-index: -1000; background: #fff; width: 800px; }

/* GLOBAL PRINT-AREA STYLES (for html2canvas) */
.print-area { background: #fff !important; margin: 0; padding: 0; width: 800px !important; box-sizing: border-box; }
.print-area .oi-doc-wrap { background: none !important; padding: 0 !important; display: block !important; }
.print-area .oi-doc { width: 100% !important; min-height: auto !important; box-shadow: none !important; margin: 0 !important; border: none !important; padding: 0 !important; }
.print-area * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
.print-area .oi-title { color: #1a2340 !important; }
.print-area .oi-company-name { color: #1a2340 !important; }
.print-area .oi-company-addr { color: #e07b00 !important; }
.print-area .oi-bill-label { color: #1a58c8 !important; }
.print-area .oi-bill-name { color: #1a2340 !important; }
.print-area .oi-bill-addr { color: #e07b00 !important; }
.print-area .oi-di-label { color: #1a58c8 !important; }
.print-area .oi-di-val { color: #1a2340 !important; }
.print-area .oi-td-qty { color: #1a2340 !important; }
.print-area .oi-td-desc { color: #e07b00 !important; }
.print-area .oi-td-price { color: #1a2340 !important; }
.print-area .oi-td-amount { color: #1a2340 !important; }
.print-area .oi-thankyou { color: #1a58c8 !important; }
.print-area .oi-bank { color: #1a2340 !important; }
.print-area .oi-total-row span:first-child { color: #1a2340 !important; }
.print-area .oi-total-row span:last-child { color: #1a58c8 !important; }
.print-area .oi-footer { flex-direction: row !important; justify-content: space-between !important; text-align: left !important; gap: 24px !important; padding: 28px 57px !important; }
.print-area .oi-thankyou { font-size: 2rem !important; text-align: left !important; }
.print-area .oi-bank { text-align: right !important; }
.print-area .oi-title { font-size: 2.5rem !important; }
.print-area .oi-company-name { font-size: 0.9rem !important; }
.print-area .oi-table { font-size: 0.85rem !important; }
.print-area .oi-top { padding: 30px 40px 20px !important; }
.print-area .oi-meta-row { padding: 15px 40px !important; }
