/* ═══════════════════════════════════════════════════════════════
   RA BILL MANAGER PRO — Design System
   ═══════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Colors */
  --bg:         #080c12;
  --surface-0:  #0d1117;
  --surface-1:  #131920;
  --surface-2:  #1a2233;
  --surface-3:  #1f2b40;
  --surface-4:  #263145;

  --border:     rgba(255,255,255,0.06);
  --border-2:   rgba(255,255,255,0.12);
  --border-3:   rgba(255,255,255,0.20);

  --text-1:     #eef2f7;
  --text-2:     #8fa3bf;
  --text-3:     #4d6380;
  --text-4:     #2d3d55;

  --accent:     #f59e0b;
  --accent-2:   #fbbf24;
  --accent-3:   #fcd34d;
  --accent-dim: rgba(245,158,11,0.12);
  --accent-glow:rgba(245,158,11,0.25);

  --green:      #10b981;
  --green-2:    #34d399;
  --green-dim:  rgba(16,185,129,0.12);
  --green-glow: rgba(16,185,129,0.25);

  --red:        #f43f5e;
  --red-2:      #fb7185;
  --red-dim:    rgba(244,63,94,0.12);

  --blue:       #3b82f6;
  --blue-2:     #60a5fa;
  --blue-dim:   rgba(59,130,246,0.12);

  --purple:     #8b5cf6;
  --purple-dim: rgba(139,92,246,0.12);

  --teal:       #06b6d4;
  --teal-dim:   rgba(6,182,212,0.12);

  /* Typography */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Geometry */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow:     0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 48px rgba(0,0,0,0.6);
  --shadow-xl:  0 24px 80px rgba(0,0,0,0.7);

  /* Sidebar */
  --sidebar-w: 256px;
  --header-h:  60px;

  /* Quick Actions */
  --qa-bg:      rgba(255,255,255,0.03);
  --qa-border:  rgba(255,255,255,0.06);
}

/* ─── RESET ─── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { font-size:16px; -webkit-font-smoothing:antialiased; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}
a { text-decoration: none; color: inherit; }
button { font-family: var(--font-sans); cursor: pointer; }
input, textarea, select { font-family: var(--font-sans); }
img { max-width: 100%; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ═══════════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════════ */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.brand-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, #d97706 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px var(--accent-glow);
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-name { font-size: 0.88rem; font-weight: 700; color: var(--text-1); white-space: nowrap; }
.brand-sub  { font-size: 0.68rem; color: var(--text-3); margin-top: 1px; }

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

.nav-section-label {
  font-size: 0.62rem; font-weight: 700; color: var(--text-4);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 10px 10px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 0.83rem; font-weight: 500; color: var(--text-2);
  background: none; border: none; width: 100%; text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative; white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 2px;
  background: var(--accent);
}
.nav-item .nav-icon { flex-shrink: 0; opacity: 0.7; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  font-size: 0.65rem; font-weight: 700;
  background: var(--surface-3); color: var(--text-3);
  padding: 2px 7px; border-radius: 20px;
  transition: background 0.2s, color 0.2s;
}
.nav-item.active .nav-badge { background: var(--accent-dim); color: var(--accent); }

.quick-actions-box {
  margin: 8px 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.02);
}
.qa-header {
  font-size: 0.58rem; font-weight: 800; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding-left: 2px; margin-bottom: -2px;
  display: flex; align-items: center; justify-content: space-between;
}
.quick-actions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.qa-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.74rem;
  font-weight: 500;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  width: 100%;
}
.qa-item:hover {
  background: var(--surface-3);
  color: var(--text-1);
  border-color: var(--border-3);
  transform: translateX(3px);
  box-shadow: -3px 0 0 -1px var(--qa-accent, var(--accent));
}
.qa-item:active { transform: translateX(1px); }

.qa-item-icon {
  width: 20px; height: 20px;
  background: var(--surface-2);
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--qa-accent, var(--accent));
  transition: all 0.15s;
  flex-shrink: 0;
}
.qa-item-icon svg { width: 11px; height: 11px; }
.qa-item:hover .qa-item-icon {
  background: var(--qa-accent, var(--accent));
  color: #1a0e00;
  scale: 1;
}

/* Category Colors */
.qa-blue   { --qa-accent: var(--blue);   }
.qa-amber   { --qa-accent: var(--accent); }
.qa-green  { --qa-accent: var(--green);  }
.qa-purple { --qa-accent: var(--purple); }
.qa-cyan   { --qa-accent: var(--teal);   }

.sync-pulse {
  position: relative;
}
@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245,158,11,0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(245,158,11,0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245,158,11,0); }
}


/* ─── MAIN CONTENT ─── */
.main-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ─── TOP BAR ─── */
.topbar {
  height: var(--header-h);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px; flex-shrink: 0;
}
.topbar-title-wrap { flex: 1; min-width: 0; }
.topbar-title    { font-size: 1.05rem; font-weight: 700; color: var(--text-1); }
.topbar-subtitle { font-size: 0.75rem; color: var(--text-3); margin-top: 1px; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  width: 260px; transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-bar input {
  background: none; border: none; outline: none;
  font-size: 0.83rem; color: var(--text-1); width: 100%;
}
.search-bar input::placeholder { color: var(--text-3); }
.search-icon { color: var(--text-3); flex-shrink: 0; }

/* ─── VIEWS ─── */
.view-panel { display: none; flex: 1; overflow-y: auto; flex-direction: column; }
.view-panel.active { display: flex; }

/* ─── VIEW CONTENT ─── */
.view-content { padding: 24px; flex: 1; }
.view-content-split {
  display: flex; flex: 1; overflow: hidden;
}
.content-main { flex: 1; overflow-y: auto; padding: 24px; }
.content-aside {
  width: 320px; flex-shrink: 0;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  overflow-y: auto; padding: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 0.83rem; font-weight: 600; border: none;
  cursor: pointer; transition: all 0.18s; white-space: nowrap;
  text-decoration: none; line-height: 1;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent); color: #1a0e00;
}
.btn-primary:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-3); color: var(--text-1); border-color: var(--border-2); }

.btn-ghost {
  background: none; color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border-2); }

.btn-danger {
  background: var(--red-dim); color: var(--red);
  border: 1px solid rgba(244,63,94,0.2);
}
.btn-danger:hover { background: rgba(244,63,94,0.2); }

.btn-success {
  background: var(--green-dim); color: var(--green);
  border: 1px solid rgba(16,185,129,0.2);
}
.btn-success:hover { background: rgba(16,185,129,0.22); }

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-xs { padding: 4px 8px; font-size: 0.73rem; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ═══════════════════════════════════════════════════════════════
   CARDS & SURFACES
   ═══════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: var(--border-2); }
.card-elevated { box-shadow: var(--shadow); }

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 0.88rem; font-weight: 600; color: var(--text-1); }
.card-body { padding: 16px 18px; }

/* ─── STAT CARDS ─── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 24px; }
@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2,1fr); } }

.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}
.stat-card::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: transparent;
  transition: background 0.2s;
}
.stat-card:hover { border-color: var(--border-2); transform: translateY(-1px); box-shadow: var(--shadow); }

.stat-card-accent::after  { background: var(--accent); }
.stat-card-green::after   { background: var(--green); }
.stat-card-red::after     { background: var(--red); }
.stat-card-blue::after    { background: var(--blue); }
.stat-card-purple::after  { background: var(--purple); }

.stat-icon {
  width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px; font-size: 1.1rem;
}
.stat-icon-accent  { background: var(--accent-dim); }
.stat-icon-green   { background: var(--green-dim); }
.stat-icon-red     { background: var(--red-dim); }
.stat-icon-blue    { background: var(--blue-dim); }
.stat-icon-purple  { background: var(--purple-dim); }

.stat-label { font-size: 0.7rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 6px; }
.stat-value { font-size: 1.65rem; font-weight: 800; font-family: var(--font-mono); color: var(--text-1); line-height: 1; }
.stat-value.accent  { color: var(--accent); }
.stat-value.green   { color: var(--green); }
.stat-value.red     { color: var(--red); }
.stat-value.blue    { color: var(--blue); }
.stat-meta { font-size: 0.72rem; color: var(--text-3); margin-top: 6px; }
.stat-trend { display: flex; align-items: center; gap: 4px; font-size: 0.72rem; margin-top: 6px; }
.stat-trend.up   { color: var(--green); }
.stat-trend.down { color: var(--red); }

/* ─── WORK ORDER CARDS ─── */
.wo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.wo-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}
.wo-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
  transform: scaleY(0); transform-origin: center;
  transition: transform 0.2s;
}
.wo-card:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.wo-card:hover::before { transform: scaleY(1); }

.wo-card-number { font-size: 0.68rem; font-weight: 700; font-family: var(--font-mono); color: var(--accent); letter-spacing: 0.08em; margin-bottom: 4px; }
.wo-card-name   { font-size: 0.93rem; font-weight: 700; color: var(--text-1); margin-bottom: 2px; }
.wo-card-client { font-size: 0.75rem; color: var(--text-2); margin-bottom: 12px; }

.progress-bar-wrap { margin: 10px 0 12px; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--text-3); margin-bottom: 4px; }
.progress-bar { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--green), var(--green-2)); transition: width 0.6s ease; }

.wo-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 0.68rem; font-weight: 600;
  padding: 3px 9px; border-radius: 20px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.chip-accent  { background: var(--accent-dim);  color: var(--accent);  border-color: rgba(245,158,11,0.2); }
.chip-green   { background: var(--green-dim);   color: var(--green);   border-color: rgba(16,185,129,0.2); }
.chip-blue    { background: var(--blue-dim);    color: var(--blue);    border-color: rgba(59,130,246,0.2); }
.chip-red     { background: var(--red-dim);     color: var(--red);     border-color: rgba(244,63,94,0.2); }
.chip-purple  { background: var(--purple-dim);  color: var(--purple);  border-color: rgba(139,92,246,0.2); }
.chip-teal    { background: var(--teal-dim);    color: var(--teal);    border-color: rgba(6,182,212,0.2); }

/* ─── CLIENT CARDS ─── */
.client-list { display: flex; flex-direction: column; gap: 10px; }
.client-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  transition: all 0.15s;
}
.client-row:hover { border-color: var(--border-2); background: var(--surface-3); }
.client-row-avatar {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.client-row-info { flex: 1; min-width: 0; }
.client-row-name { font-size: 0.9rem; font-weight: 600; color: var(--text-1); }
.client-row-meta { font-size: 0.73rem; color: var(--text-2); margin-top: 2px; }

/* ─── LIST ROWS ─── */
.list-row {
  display: flex; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 16px;
  gap: 12px; transition: all 0.15s;
}
.list-row:hover { border-color: var(--border-2); background: var(--surface-3); }

/* ═══════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 0.68rem; font-weight: 700;
}
.badge-accent  { background: var(--accent-dim);  color: var(--accent);  border: 1px solid rgba(245,158,11,0.2); }
.badge-green   { background: var(--green-dim);   color: var(--green);   border: 1px solid rgba(16,185,129,0.2); }
.badge-blue    { background: var(--blue-dim);    color: var(--blue);    border: 1px solid rgba(59,130,246,0.2); }
.badge-red     { background: var(--red-dim);     color: var(--red);     border: 1px solid rgba(244,63,94,0.2); }
.badge-purple  { background: var(--purple-dim);  color: var(--purple);  border: 1px solid rgba(139,92,246,0.2); }
.badge-teal    { background: var(--teal-dim);    color: var(--teal);    border: 1px solid rgba(6,182,212,0.2); }
.badge-mono    { background: var(--surface-3);   color: var(--text-2);  border: 1px solid var(--border); }

/* ═══════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════ */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 12px; }
.form-full   { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: 0.72rem; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.form-label-req::after { content: ' *'; color: var(--accent); }

.form-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.86rem; color: var(--text-1);
  outline: none; width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-input::placeholder { color: var(--text-4); }
.form-input:disabled { opacity: 0.5; cursor: not-allowed; }
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 72px; }

.form-hint { font-size: 0.7rem; color: var(--text-3); margin-top: 2px; }
.form-error { font-size: 0.7rem; color: var(--red); margin-top: 2px; }
.form-input.invalid { border-color: var(--red); }

/* ─── FILTER BAR ─── */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 24px 16px; flex-wrap: wrap;
}
.filter-btn {
  padding: 6px 14px; border-radius: 20px;
  font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border); cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--border-2); color: var(--text-1); }
.filter-btn.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(245,158,11,0.3); }
.filter-select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 0.78rem; color: var(--text-1); outline: none; cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.data-table th {
  background: var(--surface-2); color: var(--text-3);
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  color: var(--text-1); vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.data-table .num { font-family: var(--font-mono); text-align: right; }
.data-table .center { text-align: center; }

/* ─── INLINE INPUT TABLE ─── */
.inline-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.inline-table th {
  background: var(--surface-2); color: var(--text-3);
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.inline-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
  word-break: break-word;
  overflow-wrap: break-word;
}
.inline-table tbody tr:last-child td { border-bottom: none; }
.inline-table .num  { text-align: right; }
.inline-table input {
  background: transparent; border: none; outline: none;
  font-family: var(--font-sans); font-size: 0.84rem; color: var(--text-1);
  width: 100%; padding: 3px 0;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.inline-table input:focus { border-bottom-color: var(--accent); }
.inline-table input[type=number] { font-family: var(--font-mono); text-align: right; }

/* ─── RA BILL TABLE ─── */
.ra-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 16px; }
.ra-table { width: 100%; border-collapse: collapse; font-size: 0.81rem; table-layout: auto; min-width: 100%; }
.ra-table th {
  background: var(--surface-2); color: var(--text-3);
  font-size: 0.67rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 10px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.ra-table th.left { text-align: left; }
.ra-table th.no-wrap {
  white-space: nowrap;
}
.ra-table td {
  padding: 10px; border-bottom: 1px solid var(--border);
  color: var(--text-1); text-align: center; vertical-align: middle;
  word-break: break-word;
  overflow-wrap: break-word;
}
.ra-table td.left { text-align: left; white-space: normal; }
.ra-table td.num  { font-family: var(--font-mono); white-space: nowrap; }
.ra-table tbody tr:last-child td { border-bottom: none; }
.ra-table tfoot td { background: rgba(245,158,11,0.05); font-weight: 700; border-top: 1.5px solid rgba(245,158,11,0.25); white-space: nowrap; }

/* RA color columns */
.th-prev  { background: rgba(59,130,246,0.08)!important;  color: var(--blue)!important;   border-bottom: 2px solid rgba(59,130,246,0.2)!important; }
.th-this  { background: rgba(16,185,129,0.08)!important;  color: var(--green)!important;  border-bottom: 2px solid rgba(16,185,129,0.2)!important; }
.th-total { background: rgba(245,158,11,0.08)!important;  color: var(--accent)!important; border-bottom: 2px solid rgba(245,158,11,0.2)!important; }
.td-prev  { background: rgba(59,130,246,0.04)!important; }
.td-this  { background: rgba(16,185,129,0.04)!important; }
.td-total { background: rgba(245,158,11,0.04)!important; }

.ra-qty-input {
  background: rgba(255,255,255,0.04); border: 1px solid transparent;
  border-radius: 5px; padding: 5px 8px;
  font-family: var(--font-mono); font-size: 0.83rem; color: var(--text-1);
  outline: none; width: 90px; text-align: right;
  transition: all 0.15s;
}
.ra-qty-input:hover { border-color: var(--border-2); }
.ra-qty-input:focus { border-color: var(--green); background: rgba(16,185,129,0.07); box-shadow: 0 0 0 2px rgba(16,185,129,0.12); }
.ra-qty-input.overbill { border-color: var(--red)!important; background: var(--red-dim)!important; }

/* ─── DELETE BUTTON ─── */
.del-btn {
  background: none; border: none; cursor: pointer; color: var(--text-3);
  padding: 5px; border-radius: 5px; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.del-btn:hover { color: var(--red); background: var(--red-dim); }

/* ═══════════════════════════════════════════════════════════════
   DETAIL VIEW
   ═══════════════════════════════════════════════════════════════ */
.detail-header {
  padding: 20px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  flex-shrink: 0;
}
.detail-wo-num { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700; color: var(--accent); letter-spacing: 0.08em; margin-bottom: 4px; }
.detail-name   { font-size: 1.25rem; font-weight: 800; color: var(--text-1); margin-bottom: 3px; }
.detail-client { font-size: 0.82rem; color: var(--text-2); }
.detail-chips  { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: flex-start; }

/* ─── TAB BAR ─── */
.tab-bar {
  display: flex; gap: 0;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 24px; flex-shrink: 0;
}
.tab-btn {
  padding: 13px 16px;
  font-size: 0.82rem; font-weight: 500; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: pointer; background: none; border-top: none; border-left: none; border-right: none;
  font-family: var(--font-sans); transition: all 0.15s; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.tab-btn:hover { color: var(--text-1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count {
  font-size: 0.65rem; background: var(--surface-2); color: var(--text-3);
  padding: 1px 6px; border-radius: 10px;
}
.tab-btn.active .tab-count { background: var(--accent-dim); color: var(--accent); }

.tab-panel { display: none; padding: 24px; }
.tab-panel.active { display: block; }

/* ═══════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
  z-index: 1000; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn 0.15s ease;
}
.modal-overlay.open { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  width: 100%; max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.2s ease;
}
.modal-sm  { max-width: 460px; }
.modal-md  { max-width: 660px; }
.modal-lg  { max-width: 960px; }
.modal-xl  { max-width: 1180px; }
.modal-fullscreen {
  max-width: none;
  width: 100vw;
  height: 100vh;
  margin: 0;
  border-radius: 0;
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-shrink: 0;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--text-1); }
.modal-subtitle { font-size: 0.75rem; color: var(--text-2); margin-top: 2px; }

.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

.modal-fullscreen .modal-body {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.close-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 6px; border-radius: var(--radius-sm);
  transition: all 0.15s; display: flex; align-items: center; justify-content: center;
}
.close-btn:hover { color: var(--text-1); background: var(--surface-2); }

/* ═══════════════════════════════════════════════════════════════
   SECTION HEADERS & MISC
   ═══════════════════════════════════════════════════════════════ */
.section-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.section-title { font-size: 0.88rem; font-weight: 700; color: var(--text-1); }
.section-sub   { font-size: 0.73rem; color: var(--text-2); margin-top: 2px; }

.section-label {
  font-size: 0.62rem; font-weight: 800; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 10px;
}

.divider { height: 1px; background: var(--border); margin: 18px 0; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-3); margin-bottom: 14px; }
.breadcrumb .crumb { color: var(--text-2); cursor: pointer; }
.breadcrumb .crumb:hover { color: var(--accent); }

/* ─── EMPTY STATE ─── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}
.empty-icon  { font-size: 3.5rem; margin-bottom: 16px; opacity: 0.3; }
.empty-title { font-size: 0.95rem; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.empty-sub   { font-size: 0.8rem; color: var(--text-3); max-width: 320px; line-height: 1.6; }

/* ─── SUMMARY PANEL ─── */
.summary-panel { display: flex; flex-direction: column; gap: 0; }
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.storage-tag { display: flex; align-items: center; gap: 4px; font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; }
.storage-tag .dot { width: 6px; height: 6px; border-radius: 50%; }
.storage-tag.disc { background: var(--surface-2); color: var(--text-3); }
.storage-tag.disc .dot { background: var(--text-3); }
.storage-tag.dirty { background: rgba(245,158,11,0.1); color: var(--accent); }
.storage-tag.dirty .dot { background: var(--accent); }
.storage-tag.clean { background: rgba(16,185,129,0.1); color: var(--green); }
.storage-tag.clean .dot { background: var(--green); }

.summary-row:last-child { border-bottom: none; }
.summary-label { color: var(--text-2); }
.summary-value { font-family: var(--font-mono); font-weight: 600; color: var(--text-1); }
.summary-row.total {
  padding: 14px 0 0;
  font-size: 0.95rem;
}
.summary-row.total .summary-label { font-weight: 700; color: var(--text-1); }
.summary-row.total .summary-value { font-size: 1.2rem; font-weight: 800; }
.summary-row.deduction .summary-value { color: var(--red); }
.summary-row.highlight .summary-value { color: var(--green); }

/* ─── PRO TIP ─── */
.pro-tip {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--accent-dim); border: 1px solid rgba(245,158,11,0.15);
  display: flex; gap: 10px; align-items: flex-start;
}
.pro-tip-title { font-size: 0.72rem; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.pro-tip-text  { font-size: 0.7rem; color: var(--text-2); line-height: 1.5; }

/* ─── TOAST ─── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-2);
  color: var(--text-1); padding: 12px 18px; border-radius: 10px;
  font-size: 0.83rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%); opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex; align-items: center; gap: 10px;
  max-width: 360px; pointer-events: auto;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.toast-success { border-color: rgba(16,185,129,0.3); }
.toast.toast-error   { border-color: rgba(244,63,94,0.3); }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }

/* ─── SKELETON LOADING ─── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── MINI CHART ─── */
.mini-chart { display: flex; align-items: flex-end; gap: 3px; height: 40px; }
.mini-bar {
  flex: 1; background: var(--accent-dim); border-radius: 2px 2px 0 0;
  transition: background 0.2s;
  min-height: 4px;
}
.mini-bar:hover { background: var(--accent); }

/* ─── PAYMENT STATUS ─── */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-paid     { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.status-partial  { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.status-unpaid   { background: var(--red); }
.status-overdue  { background: var(--red); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ─── HELPER CLASSES ─── */
.mono  { font-family: var(--font-mono); }
.bold  { font-weight: 700; }
.muted { color: var(--text-2); }
.danger{ color: var(--red); }
.success { color: var(--green); }
.accent  { color: var(--accent); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-8   { margin-bottom: 8px; }
.mb-12  { margin-bottom: 12px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.fw-900 { font-weight: 900; }

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { position: fixed; left: -256px; width: 256px; height: 100%; transition: left 0.3s; z-index: 200; }
  .sidebar.open { left: 0; }
  .topbar { padding: 0 16px; }
  .view-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .content-aside { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   LETTERHEAD UPLOAD UI
   ═══════════════════════════════════════════════════════════════ */
.letterhead-dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.letterhead-dropzone:hover {
  border-color: var(--accent);
  background: rgba(245,158,11,0.04);
}
.letterhead-dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(245,158,11,0.08);
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.letterhead-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.letterhead-preview-wrap {
  width: 100%;
  position: relative;
}
.letterhead-preview-img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.letterhead-preview-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--green);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   MARGIN CALIBRATION STYLES
   ═══════════════════════════════════════════════════════════════ */
.margin-handle {
  position: absolute;
  cursor: ns-resize;
  user-select: none;
  z-index: 10;
}
.margin-handle-horizontal {
  left: 0; right: 0;
  height: 20px;
}
.margin-handle-vertical {
  top: 0; bottom: 0;
  width: 20px;
  cursor: ew-resize;
}
.margin-handle:hover .margin-line {
  background: #007bff;
}
.margin-line {
  position: absolute;
  background: rgba(59, 130, 246, 0.4);
  transition: all 0.2s;
}
.margin-handle:hover .margin-line {
  background: rgba(59, 130, 246, 0.8);
  height: 3px;
}
.margin-handle-horizontal .margin-line {
  left: 0; right: 0; top: 50%; height: 1.5px;
  transform: translateY(-50%);
}
.margin-handle-vertical .margin-line {
  top: 0; bottom: 0; left: 50%; width: 1.5px;
  transform: translateX(-50%);
}
.margin-handle-vertical:hover .margin-line {
  width: 3px;
}
.margin-label {
  position: absolute;
  background: #2563eb;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  width: max-content;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.margin-handle-horizontal .margin-label {
  top: -28px; left: 50%;
  transform: translateX(-50%);
}
.margin-handle-vertical .margin-label {
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: center;
}
#cal-handle-left .margin-label { left: -42px; }
#cal-handle-right .margin-label { right: -42px; }
#cal-handle-top .margin-label { top: -28px; }
#cal-handle-bottom .margin-label { bottom: -28px; top: auto; }

/* ═══════════════════════════════════════════════════════════════
   PRINT STYLES — HEADER & FOOTER BAND SYSTEM
   ═══════════════════════════════════════════════════════════════ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
    orphans: 5;
    widows: 5;
  }

  body, html {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .sidebar, .topbar, .detail-actions, .tab-bar, .modal-header .close-btn,
  .no-print, .btn, .filter-bar, .toast-container { display: none !important; }

  .modal-overlay {
    position: static !important;
    background: none !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
  }
  .modal {
    border: none !important;
    box-shadow: none !important;
    max-height: none !important;
    animation: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    width: auto !important;
    min-height: auto !important;
    height: auto !important;
  }
  .modal-header { display: flex !important; }
  .modal-body { overflow: visible !important; padding: 0 !important; }
  .modal-footer { display: none !important; }

  /* Force only print wrapper area, no app chrome */
  .sidebar, .topbar, .tab-bar, .detail-actions, .filter-bar, .toast-container,
  .section-label, .stat-card, .wo-card, .client-row, .btn, .no-print {
    display: none !important;
  }

  /* Keep print modal content visible in the print stream */
  .modal-overlay, .modal {
    display: block !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    width: auto !important;
    max-width: 100% !important;
    min-height: auto !important;
    position: static !important;
  }

  /* Ensure the print panel is full width and well spaced */
  #bill-print-area, #challan-print-area, .print-area {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
  }

  /* When print is triggered through printOnly, only this content should show */
  body.print-active .app-shell > :not(.modal-overlay) {
    display: none !important;
  }
  body.print-active .modal-overlay {
    display: block !important;
  }

  /* ─── BACKGROUND LAYER ───
     Full-page background that repeats on every page.
     NOTE: Removed fixed height to allow natural page flow.
     Position:fixed + width:210mm handles page width.
     Height adapts to each page automatically. */
  .print-letterhead-background {
    display: block !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 210mm;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ─── HEADER BAND ───
     position:fixed makes Chrome/Edge repeat it on EVERY printed page.
     Height and background-image are set inline by buildPrintWrapper().
     ──────────────────────────────────────── */
  .print-letterhead-header,
  .print-letterhead-footer {
    display: block !important;
    position: fixed;
    left: 0;
    width: 210mm;
    z-index: 0;
    pointer-events: none;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .print-letterhead-header {
    top: 0;
  }
  .print-letterhead-footer {
    bottom: 0;
  }

  /* ─── CONTENT FOREGROUND LAYER ───
     Padding set dynamically by buildPrintWrapper() creates safe print area.
     Padding PREVENTS content overlap with fixed header/footer.
     NO page-break-inside: avoid - allows natural multi-page flow. */
  .print-content-wrapper {
    position: relative;
    z-index: 1;
    background: transparent !important;
    margin: 0;
    /* REMOVED: page-break-inside: avoid (causes overlap on multi-page) */
    /* Padding already set inline via buildPrintWrapper() */
  }

  /* No letterhead fallback */
  .print-content-wrapper.no-letterhead {
    padding: 12mm !important;
  }

  /* ─── SAFE PRINT AREA ───
     Content inside print-content-wrapper respects padding (safe area).
     Allow natural page breaks for multi-page flow. */
  .print-area {
    /* REMOVED: page-break-inside: avoid (was causing multi-page overlap) */
    /* Content can now flow naturally across pages */
    width: 100%;
    margin: 0;
    padding: 0;
    break-inside: auto;  /* Allow breaks */
  }

  /* Section boxes should stay together if possible */
  .print-area > div[style*="border"] {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  /* ─── TABLE OPTIMIZATION FOR MULTI-PAGE ───
     Tables can flow across pages with proper header/footer repetition */
  .print-area table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1mm;
    /* Removed: page-break-inside: avoid (allows table to split across pages) */
  }

  .print-area table thead {
    display: table-header-group;  /* Repeats on every page */
    page-break-after: avoid;      /* Header stays with first rows */
  }

  .print-area table tbody tr {
    page-break-inside: avoid;     /* Rows don't split vertically */
    page-break-after: auto;       /* Natural break between rows */
  }

  .print-area table tfoot {
    display: table-footer-group;  /* Footer stays with last rows */
    page-break-before: avoid;     /* Footer stays together */
  }

  /* Allow rows to break to next page if needed */
  .print-area table tbody tr:last-child {
    page-break-after: auto;
  }

  /* ─── TEXT AND CONTENT PRESERVATION ───
     Prevent text from breaking awkwardly */
  .print-area td, .print-area th {
    page-break-inside: avoid;
    orphans: 3;
    widows: 3;
  }

  /* Numeric fields should not wrap */
  .print-area td[style*="text-align:right"],
  .print-area th[style*="text-align:right"] {
    word-break: keep-all;
    white-space: nowrap;
  }

  /* Description columns can wrap normally */
  .print-area td[style*="word-break:break-word"],
  .print-area td[style*="white-space:normal"] {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }

  /* ─── BACKGROUND GRAPHICS ───
     Ensure colors and backgrounds print properly */
  body.print-active * {
    background: transparent !important;
  }

  .print-area,
  .print-area table,
  .print-area td,
  .print-area th {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ─── FLEX AND GRID LAYOUTS ───
     Ensure grid/flex items print properly */
  .print-area > div[style*="display:grid"],
  .print-area > div[style*="display:flex"] {
    break-inside: auto;
  }

  /* ─── BORDERS AND BOXES ───
     Maintain visual structure */
  .print-area div[style*="border"] {
    break-inside: auto;
  }

  .print-content-layer:not(.no-letterhead) {
    padding-top: 20mm !important;
  }

  .print-area {
    background: #fff !important;
    color: #000 !important;
    font-family: Arial, sans-serif !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    page-break-before: auto;
    page-break-after: auto;
  }

  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }

  /* Normalize UI surfaces for print (avoid dark theme cards) */
  .card, .stat-card, .wo-card, .client-row, .modal, .modal-body, .tab-panel, .content-aside,
  .section-header, .section-label, .progress-bar, .progress-fill, .chip,
  .bill-content, .challan-content {
    background: #fff !important;
    color: #000 !important;
    border-color: #ccc !important;
    box-shadow: none !important;
  }

  .wo-card::before, .chip, .stat-card::after, .no-print, .btn {
    display: none !important;
  }

  table, th, td, .work-orders-table, .bill-table {
    background: #fff !important;
    color: #000 !important;
    border-color: #bbb !important;
  }

  th, td { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  /* Force background graphics to print (user must also enable in browser) */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* ─── FORCED PAGE BREAKS (Excel-style) ───
     Rows with .page-break-before get a forced page break */
  .page-break-before {
    page-break-before: always !important;
    break-before: page !important;
  }

  /* Hide the on-screen page break label in print */
  .page-break-before td:first-child::before,
  .page-break-before td:first-child::after {
    display: none !important;
  }

  /* Hide selection mode visual cues */
  .pb-selectable,
  .pb-select-mode .print-area table tbody tr:hover td:first-child::before {
    display: none !important;
  }

  /* Hide breaks dropdown and badge in print */
  .breaks-dropdown-wrap,
  .breaks-badge {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   PAGE BREAK CONTROLS (Excel-style Breaks Dropdown)
   ═══════════════════════════════════════════════════════════════ */

/* Breaks dropdown wrapper */
.breaks-dropdown-wrap {
  position: relative;
  display: inline-block;
}

.breaks-dropdown-wrap .btn svg {
  transition: transform 0.2s;
}
.breaks-dropdown-wrap.open .btn svg:last-child {
  transform: rotate(180deg);
}

/* Dropdown menu */
.breaks-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  overflow: hidden;
  animation: slideUp 0.15s ease;
}
.breaks-dropdown-wrap.open .breaks-menu {
  display: block;
}

.breaks-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-1);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
  transition: background 0.12s;
}
.breaks-menu-item:hover {
  background: var(--surface-2);
}
.breaks-menu-item:not(:last-child) {
  border-bottom: 1px solid var(--border);
}
.breaks-menu-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}
.breaks-menu-item .menu-item-text {
  display: flex;
  flex-direction: column;
}
.breaks-menu-item .menu-item-label {
  font-weight: 600;
  font-size: 0.82rem;
}
.breaks-menu-item .menu-item-desc {
  font-size: 0.68rem;
  color: var(--text-3);
  margin-top: 1px;
}
.breaks-menu-item.danger { color: var(--red); }
.breaks-menu-item.danger:hover { background: var(--red-dim); }

/* Page break row indicator (on-screen visual) */
.page-break-before {
  position: relative;
}
.page-break-before td:first-child::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2.5px dashed #3b82f6;
  z-index: 5;
  pointer-events: none;
}
.page-break-before td:first-child::after {
  content: '—— Page Break ——';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-1);
  color: #3b82f6;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0 8px;
  white-space: nowrap;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 6;
  pointer-events: none;
}

/* Print preview: clickable row highlight for selecting page break position */
.print-area table tbody tr.pb-selectable:hover {
  outline: 2px solid var(--blue) !important;
  outline-offset: -1px;
  cursor: pointer;
}
.print-area table tbody tr.pb-selectable:hover td {
  background: rgba(59,130,246,0.08) !important;
}

/* Page break selection mode indicator */
.pb-select-mode .print-area table tbody tr {
  cursor: pointer;
}
.pb-select-mode .print-area table tbody tr:hover td {
  background: rgba(59,130,246,0.08) !important;
}
.pb-select-mode .print-area table tbody tr:hover td:first-child::before {
  content: '⇒ Insert Break Here';
  display: inline;
  color: #3b82f6;
  font-size: 9px;
  font-weight: 700;
  margin-right: 4px;
}

/* Page break indicator in print preview */
.print-area table tbody tr.page-break-before {
  position: relative;
}
.print-area table tbody tr.page-break-before td {
  border-top: 2.5px dashed #3b82f6 !important;
}

/* Breaks count badge */
.breaks-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  margin-left: 4px;
}
.breaks-badge:empty {
  display: none;
}

/* ─── SCREEN: hide the print-only layers ─── */
.print-letterhead-header,
.print-letterhead-footer {
  display: none;
}

/* ─── STORAGE STATUS BANNER ─── */
#storage-status-banner {
  margin-left: auto;
  margin-right: 12px;
}

.storage-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: all 0.3s ease;
  white-space: nowrap;
}

.storage-tag .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
}

.storage-tag.disc { border-color: var(--text-4); color: var(--text-3); }
.storage-tag.disc .dot { background: var(--text-4); }

.storage-tag.clean { border-color: rgba(16,185,129,0.3); color: var(--green); }
.storage-tag.clean .dot { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }

.storage-tag.dirty { border-color: rgba(245,158,11,0.4); color: var(--accent); background: var(--accent-dim); }
.storage-tag.dirty .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); animation: pulse-storage 2s infinite; }

.storage-tag .file-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.storage-tag .status-lbl {
  opacity: 0.8;
  font-weight: 400;
}

.ml-8 { margin-left: 8px; }

@keyframes pulse-storage {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}



/* ─── PRINT AREA (ON-SCREEN PREVIEW) ─── */
.print-area {
  background-color: #ffffff !important;
  color: #000000 !important;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  margin: 0 auto;
}

/* ─── PRO FLOATING CALCULATOR ── */
.floating-calc {
  position: fixed; bottom: 30px; right: 30px; width: 300px;
  background: var(--surface-1); border: 1.5px solid var(--border-3);
  border-radius: 12px; box-shadow: 0 16px 64px rgba(0,0,0,0.35);
  z-index: 10000; display: flex; flex-direction: column; overflow: hidden;
  animation: slide-up-calc 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.floating-calc-header {
  padding: 12px 16px; background: linear-gradient(to right, var(--surface-2), var(--surface-1));
  border-bottom: 1px solid var(--border); display: flex;
  justify-content: space-between; align-items: center; cursor: grab; user-select: none;
}
.floating-calc-header:active { cursor: grabbing; }

.floating-calc-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; font-weight: 800; color: var(--accent); letter-spacing: 0.02em;
}

.calc-ctrl-btn {
  background: transparent; border: none; color: var(--text-3);
  font-size: 1.1rem; cursor: pointer; padding: 4px; border-radius: 6px;
  line-height: 1; transition: all 0.2s; display: flex; align-items: center;
}
.calc-ctrl-btn:hover { background: var(--surface-3); color: var(--text-1); }

.calc-ctrl-btn:active svg, .calc-ctrl-btn:active {
  transform: rotate(180deg);
  transition: transform 0.3s ease;
}

/* Tabs */
.floating-calc-nav {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  padding: 2px; gap: 2px;
}
.calc-mini-tab {
  height: 36px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px;
  font-size: 1.1rem; cursor: pointer; transition: all 0.2s;
}
.calc-mini-tab:hover { background: var(--surface-3); }
.calc-mini-tab.active {
  background: var(--surface-1); color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Body & Content */
.floating-calc-body { padding: 20px; max-height: 480px; overflow-y: auto; }
.calc-widget-title {
  font-size: 0.72rem; font-weight: 800; color: var(--text-4);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 16px;
}

.calc-row { display: flex; gap: 10px; margin-bottom: 12px; }
.flex-1 { flex: 1; }
.col-4 { width: calc(33.33% - 7px); }

/* Result Box */
.calc-widget-result {
  margin-top: 20px; padding: 18px; border-radius: 12px;
  background: var(--accent-dim); border: 1px solid rgba(245,158,11,0.3);
  text-align: center;
}
.res-label { font-size: 0.62rem; font-weight: 800; color: var(--text-3); margin-bottom: 6px; }
.res-main { font-size: 2.4rem; font-weight: 900; color: var(--accent); font-family: var(--font-mono); line-height: 1; }
.res-sub { font-size: 0.7rem; font-weight: 700; color: var(--text-2); margin-top: 6px; }

/* Result Grid (Pro Mode) */
.calc-widget-result.pro { padding: 12px; }
.res-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.res-item { 
  flex: 1; background: var(--surface-1); padding: 8px; 
  border-radius: 8px; border: 1px solid var(--border); display: flex; flex-direction: column;
}
.res-item.wide { flex-basis: 100%; border-color: rgba(245,158,11,0.2); }
.res-item .val { font-size: 1.25rem; font-weight: 800; color: var(--accent); font-family: var(--font-mono); }
.res-item .lbl { font-size: 0.6rem; color: var(--text-3); font-weight: 600; margin-top: 2px; }

/* Formula Display */
.calc-formula-display {
  margin-top: 14px; padding: 8px 12px; font-size: 0.68rem;
  color: var(--text-4); border: 1px dashed var(--border); border-radius: 6px;
  font-family: var(--font-mono); font-style: italic; opacity: 0.8;
}

/* History */
.calc-history-toggle {
  margin-top: 12px; text-align: center; font-size: 0.68rem;
  font-weight: 700; color: var(--text-3); cursor: pointer; user-select: none;
}
.calc-history-toggle:hover { color: var(--accent); }

.calc-history-list {
  display: none; height: 120px; overflow-y: auto; background: var(--surface-2);
  border-top: 1px solid var(--border); padding: 10px;
}
.history-item { 
  display: flex; justify-content: space-between; gap: 10px; padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05); font-size: 0.7rem;
}
.history-item .time { color: var(--text-4); }
.history-item .text { font-weight: 600; color: var(--text-2); }

/* Compact Inputs */
.form-label-sm { font-size: 0.65rem; font-weight: 700; color: var(--text-3); margin-bottom: 4px; display: block; }
.form-input-sm { 
  width: 100%; padding: 6px 10px; font-size: 0.85rem; font-weight: 600;
  background: var(--surface-1); border: 1px solid var(--border); 
  border-radius: 8px; color: var(--text-1); transition: border-color 0.2s;
}
.form-input-sm:focus { border-color: var(--accent); outline: none; }
.mt-8 { margin-top: 8px; }

/* Highlighting for Excess Billed Quantity */
.ra-qty-input.overbill {
  background: rgba(239, 68, 68, 0.15) !important;
  border: 1px solid #ef4444 !important;
  color: #ef4444 !important;
  border-radius: 4px;
}

/* ─── USER PROFILE & DROPDOWN ─── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: 12px;
}

.user-profile {
  position: relative;
  cursor: pointer;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  border: 2px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s;
  user-select: none;
}

.user-profile:hover .user-avatar {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(245,158,11,0.3);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 220px;
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  padding: 8px;
  display: none;
  flex-direction: column;
  z-index: 1000;
  transform-origin: top right;
  animation: dropdownFade 0.2s ease-out;
}

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

.user-dropdown.active {
  display: flex;
}

.dropdown-header {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  margin-bottom: 6px;
}

.dropdown-user-email {
  font-size: 0.75rem;
  color: var(--text-3);
  word-break: break-all;
  font-weight: 600;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.dropdown-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-1);
}

.dropdown-item.danger {
  color: #ef4444;
}

.dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.dropdown-divider {
  height: 1px;
  background: rgba(255,255,255,0.05);
  margin: 6px 0;
}

/* ═══════════════════════════════════════════════════════════════
   WHATSAPP SUPPORT BUTTON
   ═══════════════════════════════════════════════════════════════ */
#whatsappSupportBtn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  background-color: #25D366;
  color: #fff;
  border-radius: 50%;
  display: none; /* Flex applied via JS after delay */
  justify-content: center;
  align-items: center;
  box-shadow: 0 6px 16px rgba(37, 211, 102, 0.4);
  z-index: 10000;
  cursor: pointer;
  text-decoration: none;
  opacity: 0;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease, background-color 0.2s;
}

#whatsappSupportBtn.visible {
  opacity: 1;
  transform: translateY(0);
}

#whatsappSupportBtn:hover {
  transform: scale(1.1) translateY(0);
  background-color: #1ebe57;
}

/* Tooltip implementation */
#whatsappSupportBtn::before {
  content: "Need Help? Chat with us";
  position: absolute;
  right: 70px;
  background-color: var(--surface-3);
  color: var(--text-1);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  border: 1px solid var(--border);
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
  transform: translateX(10px);
  pointer-events: none;
}

#whatsappSupportBtn:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* Notification Badge */
.whatsapp-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background-color: #ef4444;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 10px;
  border: 2px solid var(--bg);
}

@media (max-width: 600px) {
  #whatsappSupportBtn {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  #whatsappSupportBtn svg {
    width: 24px;
    height: 24px;
  }
  #whatsappSupportBtn::before {
    display: none; /* Hide tooltip on mobile to avoid screen overflow */
  }
}

/* ═══════════════════════════════════════════════════════════════
   PREMIUM SUBSCRIPTION CARD
   ═══════════════════════════════════════════════════════════════ */
.sub-status-card {
  margin: 12px 10px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.sub-status-card:hover {
  border-color: var(--border-3);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.sub-status-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 100%;
  background: radial-gradient(circle at top right, var(--sub-glow, transparent) 0%, transparent 70%);
  opacity: 0.15;
  pointer-events: none;
}

.sub-status-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sub-status-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sub-bg, var(--surface-3));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.sub-status-info {
  flex: 1;
}

.sub-status-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin-bottom: 2px;
}

.sub-status-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-1);
}

.sub-status-detail {
  font-size: 0.75rem;
  color: var(--text-2);
  line-height: 1.4;
}

.sub-status-action {
  width: 100%;
  margin-top: 4px;
}

/* Plan Variants */
.sub-card-trial {
  --sub-glow: var(--blue);
  --sub-bg: var(--blue-dim);
}

.sub-card-pro {
  --sub-glow: var(--accent);
  --sub-bg: var(--accent-dim);
}

.sub-card-premium {
  --sub-glow: var(--green);
  --sub-bg: var(--green-dim);
  border: 1px solid rgba(16,185,129,0.2);
}

.sub-card-expired {
  --sub-glow: var(--red);
  --sub-bg: var(--red-dim);
  border: 1.5px solid rgba(244,63,94,0.3);
}

/* Animation for pulse effect on trial/expired */
.sub-pulse {
  animation: sub-pulse-anim 2s infinite;
}

@keyframes sub-pulse-anim {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* ─── Brand Status Tag ─── */
#brand-status-tag {
  display: inline-flex;
  align-items: center;
}
.brand-tag {
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.brand-tag-free    { background: var(--blue-dim);   color: var(--blue);   border: 1px solid rgba(59,130,246,0.3); }
.brand-tag-pro     { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(245,158,11,0.3); }
.brand-tag-premium { background: var(--green-dim);  color: var(--green);  border: 1px solid rgba(16,185,129,0.3); }
.brand-tag-expired { background: var(--red-dim);    color: var(--red);    border: 1px solid rgba(244,63,94,0.3); }
