/* ============================================================
   UPVC Billing App - Mobile-first design system
   ============================================================ */
:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --primary-grad: linear-gradient(135deg, #0f766e 0%, #10b981 100%);
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #16a34a;
  --info: #2563eb;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .16);
  --topbar-h: 56px;
  --bottomnav-h: 62px;
  --sidebar-w: 250px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--text); }

::placeholder { color: var(--text-3); }
a { color: var(--primary); text-decoration: none; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; background: var(--primary-grad);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  z-index: 999;
}
.splash-logo {
  width: 76px; height: 76px; border-radius: 20px; background: #fff; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; letter-spacing: -1px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.splash-title { color: #fff; font-size: 18px; font-weight: 700; letter-spacing: .3px; }
.spinner {
  width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 40;
  background: var(--primary-grad); color: #fff;
  display: flex; align-items: center; gap: 4px;
  padding: 0 10px;
  box-shadow: 0 2px 10px rgba(15,23,42,.18);
  padding-top: env(safe-area-inset-top);
}
.topbar-btn {
  background: transparent; border: 0; color: #fff; width: 40px; height: 40px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
}
.topbar-btn:active { background: rgba(255,255,255,.18); }
.topbar-title { flex: 1; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; }
.topbar-actions { display: flex; gap: 2px; }

.mainarea { padding: calc(var(--topbar-h) + 12px) 14px calc(var(--bottomnav-h) + 16px); transition: padding .2s; }

/* ---------- Sidebar (desktop/tablet) ---------- */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 50;
  background: #ffffff; border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .25s ease;
  display: flex; flex-direction: column; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }
.sidebar-brand {
  display: flex; align-items: center; gap: 12px; padding: 18px 20px;
  background: var(--primary-grad); color: #fff;
}
.sidebar-brand .brand-box {
  width: 40px; height: 40px; border-radius: 11px; background: #fff; color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px;
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 16px; }
.sidebar-brand .brand-sub { font-size: 11px; opacity: .85; }
.sidebar-nav { display: flex; flex-direction: column; padding: 10px 10px 20px; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  color: var(--text-2); font-weight: 600; font-size: 14px; border: 0; background: transparent;
  width: 100%; text-align: left;
}
svg { width: 24px; height: 24px; flex-shrink: 0; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); }
.nav-item:active { background: var(--bg); }
.nav-sep { margin: 8px 14px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 700; }
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 45; opacity: 0; visibility: hidden;
  transition: opacity .2s;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  z-index: 40; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 11px; font-weight: 600; border: 0; background: transparent;
  padding-top: 8px;
}
.bottomnav-item svg { width: 23px; height: 23px; }
.bottomnav-item.active { color: var(--primary); }
.bottomnav-item:active { background: var(--bg); }

/* ---------- Responsive ---------- */
@media (min-width: 900px) {
  .topbar { display: none; }
  .bottomnav { display: none; }
  .sidebar { transform: translateX(0); box-shadow: none; border-right: 1px solid var(--line); }
  .mainarea { padding: 24px 28px; margin-left: var(--sidebar-w); }
}

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.page-title { font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden;
}
.card-pad { padding: 16px; }
.card-title { font-size: 15px; font-weight: 700; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title small { font-weight: 500; color: var(--text-3); font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.stat-card .stat-value { font-size: 24px; font-weight: 800; margin-top: 4px; letter-spacing: -.5px; }
.stat-card .stat-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--primary-grad); }
.stat-card.green { color: var(--primary-dark); }
.stat-card.green .stat-bar { background: linear-gradient(90deg, #10b981, #0f766e); }
.stat-card.amber .stat-bar { background: linear-gradient(90deg, #f59e0b, #f97316); }
.stat-card.blue .stat-bar { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.stat-card.red .stat-bar { background: linear-gradient(90deg, #ef4444, #dc2626); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px;
  font-size: 15px; font-weight: 700; color: #fff; background: var(--primary);
  min-height: 46px; transition: transform .06s, box-shadow .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary-grad); box-shadow: 0 6px 14px rgba(15,118,110,.3); }
.btn-ghost { background: #fff; color: var(--primary); border: 1.5px solid var(--line-2); }
.btn-soft { background: var(--primary-light); color: var(--primary-dark); }
.btn-danger { background: var(--danger); }
.btn-amber { background: var(--accent); }
.btn-sm { padding: 7px 12px; min-height: 40px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 38px; height: 38px; padding: 0; border-radius: 11px; min-height: 0;
}
.btn-fab.tl { position: fixed; right: 16px; bottom: calc(var(--bottomnav-h) + 16px); height: 56px; width: 56px; border-radius: 18px; box-shadow: var(--shadow-lg); z-index: 30; }
@media (min-width: 900px) { .btn-fab.tl { bottom: 30px; right: 30px; } }
.btn-fab svg { width: 24px; height: 24px; }

.segmented { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 10px;
  font-weight: 700; font-size: 13px; color: var(--text-2);
}
.segmented button.on { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.field-label .req { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; border: 1.5px solid var(--line-2); border-radius: 12px;
  padding: 12px 14px; background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s; appearance: none; -webkit-appearance: none;
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.14);
}
.select {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.input-num { text-align: left; }
.field-hint { font-size: 12px; color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.error-text { color: var(--danger); font-size: 12.5px; font-weight: 600; margin-top: 4px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.switch-row .lbl b { display: block; font-size: 14px; }
.switch-row .lbl span { font-size: 12px; color: var(--text-3); }
.switch { position: relative; width: 50px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--line-2); border-radius: 30px; transition: background .2s; }
.switch .track::before {
  content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(22px); }

/* ---------- Search ---------- */
.searchbar { position: relative; }
.searchbar svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); }
.searchbar .input { padding-left: 40px; }

/* ---------- List items ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--line); background: #fff;
}
.list-item:last-child { border-bottom: 0; }
.list-item.ripple:active { background: var(--bg); }
.list-avatar {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { font-size: 12.5px; color: var(--text-2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-right { text-align: right; flex-shrink: 0; }
.list-value { font-weight: 800; }
.list-chip { font-size: 11.5px; padding: 3px 9px; border-radius: 30px; font-weight: 700; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 30px; font-size: 12.5px; font-weight: 700; }
.chip-green { background: #ecfdf5; color: #047857; }
.chip-red { background: #fef2f2; color: #b91c1c; }
.chip-amber { background: #fffbeb; color: #b45309; }
.chip-blue { background: #eff6ff; color: #1d4ed8; }
.chip-gray { background: #f1f5f9; color: #475569; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty .empty-ic { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 20px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.empty .empty-ic svg { width: 32px; height: 32px; }
.empty b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }
.empty p { font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 11px 14px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-3); background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .tbody-row:active { background: #f8fafc; cursor: pointer; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0; border: 0; background: #fff; padding: 10px 16px; border-radius: 30px;
  font-weight: 700; font-size: 13.5px; color: var(--text-2); box-shadow: var(--shadow);
}
.tab.on { background: var(--primary-grad); color: #fff; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .2s;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }
.modal {
  background: #fff; width: 100%; max-width: 520px; max-height: 90vh;
  border-radius: 20px 20px 0 0; overflow: hidden; display: flex; flex-direction: column;
  transform: translateY(40px); transition: transform .22s ease;
}
.modal-backdrop.show .modal { transform: translateY(0); }
.modal-head {
  padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-weight: 800; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 20px; max-height: 88vh; }
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: calc(var(--topbar-h) + 10px); left: 0; right: 0; z-index: 120; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px; max-width: 100%;
  animation: toastIn .25s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toastIn { from { transform: translateY(-14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--primary-grad); padding: 24px 18px; padding-top: calc(24px + env(safe-area-inset-top));
}
.login-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 22px; padding: 26px 22px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 58px; height: 58px; border-radius: 16px; background: var(--primary-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px;
  margin: 0 auto 12px;
}
.login-title { text-align: center; font-size: 19px; font-weight: 800; }
.login-sub { text-align: center; font-size: 13px; color: var(--text-2); margin-top: 4px; margin-bottom: 20px; }
.login-server {
  margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line-2);
}
.login-server summary { cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 700; text-align: center; list-style: none; }
.login-server summary::after { content: " ▾"; }
.login-server[open] summary::after { content: " ▴"; }
.demo-note { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 14px; }

/* ---------- Invoice / document ---------- */
.doc { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.doc-head { background: var(--primary-grad); color: #fff; padding: 18px 18px 14px; }
.doc-head .doc-type { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; opacity: .85; font-weight: 700; }
.doc-head .doc-company { font-size: 20px; font-weight: 800; margin-top: 2px; }
.doc-head .doc-meta { font-size: 12px; opacity: .95; margin-top: 6px; line-height: 1.6; }
.doc-body { padding: 18px; }
.doc-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; }
.doc-row b { font-weight: 700; }
.doc-section-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 16px 0 8px; }
.doc-total { background: var(--primary-light); border-radius: 12px; padding: 12px 16px; margin-top: 12px; }
.doc-line { display: flex; justify-content: space-between; align-items: center; font-size: 14px; padding: 3px 0; }
.doc-line.grand { font-size: 17px; font-weight: 800; color: var(--primary-dark); border-top: 1.5px solid var(--primary); margin-top: 6px; padding-top: 8px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.doc-table th { background: #f8fafc; text-align: left; padding: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); border-bottom: 1px solid var(--line); }
.doc-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.doc-actions { display: flex; gap: 10px; margin-top: 14px; }
.note-box { font-size: 12px; color: var(--text-3); background: #f8fafc; border-radius: 10px; padding: 12px; margin-top: 12px; white-space: pre-wrap; word-break: break-word; }

/* ---------- Product line editor ---------- */
.line-card { border: 1.5px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; background: #fff; overflow: hidden; }
.line-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.line-num { font-weight: 800; font-size: 13px; color: var(--text-2); }
.line-del { border: 0; background: #fee2e2; color: var(--danger); width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.line-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.line-calc { background: var(--primary-light); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; color: var(--primary-dark); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.line-calc b { float: right; font-variant-numeric: tabular-nums; }

/* ---------- Skeleton ---------- */
.skel { border-radius: 10px; background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 50%, #eef2f7 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Misc ---------- */
.section-gap { height: 14px; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12.5px; }
.text-bold { font-weight: 700; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; }

/* ---------- Quotation (C-2 format) ---------- */
.quote-doc { background: #fff; }
.q-page { padding: 18px 22px; page-break-after: always; break-after: page; display: flex; flex-direction: column; }
.q-page:last-child { page-break-after: auto; break-after: auto; }
.q-page-last { page-break-after: auto !important; break-after: auto !important; page-break-before: auto !important; break-before: auto !important; }
.q-head { border-bottom: 2px solid #0f766e; padding-bottom: 10px; margin-bottom: 10px; }
.q-head-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.q-logo img { max-height: 90px; max-width: 240px; object-fit: contain; }
.q-logo-ph { width: 72px; height: 72px; border-radius: 14px; background: #0f766e; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 800; }
.q-brand { text-align: right; }
.q-brand-name { font-size: 22px; font-weight: 800; color: #0f766e; text-align: right; }
.q-brand-meta { font-size: 12.5px; color: var(--text-2); line-height: 1.7; text-align: right; }
.q-head-identity { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.q-client { font-size: 13px; color: var(--text-2); font-weight: 700; }
.q-client b { color: #0f766e; }
.q-projline { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.q-projline b { color: #0f766e; }
.q-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 11px; color: var(--text-3); border-top: 1px solid var(--line); margin-top: 14px; padding-top: 6px; }
.q-foot-brands { display: flex; align-items: center; gap: 8px; }
.q-foot-brands img { max-height: 30px; max-width: 72px; object-fit: contain; display: block; }
.q-foot-pg { flex: 1; text-align: center; }
.q-fw { color: #94a3b8; font-style: italic; }
.q-body { flex: 1; }
.q-letter p { font-size: 13.5px; line-height: 1.75; margin: 0 0 10px; }
.q-to, .q-dear { font-weight: 700; }
.q-ul { margin-left: 16px; }
.q-sign-wrap { margin-top: 18px; text-align: right; }
.q-sign { font-size: 13.5px; line-height: 1.6; }
.win-block { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; break-inside: avoid; }
.win-brand { margin-bottom: 8px; }
.win-brand img { max-height: 44px; max-width: 130px; object-fit: contain; display: block; }
.win-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.win-title { display: flex; align-items: center; gap: 10px; }
.win-code { background: #0f766e; color: #fff; font-weight: 800; font-size: 12px; padding: 6px 10px; border-radius: 8px; }
.win-name { font-size: 15px; font-weight: 800; }
.ws-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.ws-table td { border: 1px solid var(--line); padding: 4px 7px; font-size: 11.5px; }
.ws-table td.k { background: #f8fafc; font-weight: 700; color: var(--text-2); width: 70px; white-space: nowrap; }
.win-draw { text-align: center; margin-bottom: 6px; }
.win-svg { width: 160px; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.win-view { font-size: 11px; color: var(--text-3); font-style: italic; margin-top: 2px; }
.win-draw-img .win-img-big { position: relative; width: 100%; max-width: 260px; margin: 0 auto; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.win-draw-img .win-img-big img { position: absolute; left: 13.9%; top: 18.5%; width: 72.2%; height: 63%; object-fit: contain; }
.win-draw-img .win-dim { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-img { text-align: center; margin-top: 6px; }
.win-img img { max-width: 160px; max-height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.win-mid { display: flex; align-items: flex-start; gap: 20px; }
.win-left { flex: 0 0 auto; width: 280px; max-width: 100%; min-width: 0; }
.win-right { flex: 1; min-width: 0; }
@media (max-width: 700px) {
  .win-mid { flex-direction: column; align-items: center; gap: 14px; }
  .win-left { width: 100%; max-width: 420px; }
  .win-right { width: 100%; }
}
.cv-title { font-weight: 800; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: #0f766e; margin: 6px 0 3px; }
.cv-table { width: 100%; border-collapse: collapse; margin: 0; }
.cv-table th { background: #f8fafc; text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); padding: 5px 7px; border: 1px solid var(--line); }
.cv-table td { padding: 4px 7px; border: 1px solid var(--line); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cv-table td:first-child { color: var(--text-2); font-weight: 600; width: 60%; }
.cv-table tr.total td { background: #e9f7f2; font-weight: 800; color: #0f766e; }
.win-acc { margin-top: 6px; display: flex; gap: 16px; align-items: flex-start; }
.win-acc > div { flex: 1; min-width: 0; }
.win-acc ul { margin: 0; padding-left: 16px; font-size: 11.5px; line-height: 1.7; }
.q-note { font-size: 11.5px; font-style: italic; color: var(--text-3); margin: 8px 0 0; }
.totals { margin: 10px 0 0; border: 1.5px solid #0f766e; border-radius: 10px; overflow: hidden; background: #eef6ff; }
.tot-head { background: #e7ebf1; color: #000000; font-weight: 800; font-size: 13px; text-align: center; padding: 6px 12px; letter-spacing: .5px; border: 1.5px solid #d0d7e0; border-bottom: 1.5px solid #0f766e; }
.tot-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; font-size: 12.5px; border-top: 1px solid rgba(15, 118, 110, .18); background: #eef6ff; }
.tot-row span { color: var(--text-2); }
.tot-row b { font-variant-numeric: tabular-nums; }
.tot-row.total { background: #d9ecff; color: #0b4d8f; font-weight: 800; font-size: 13.5px; border-top: 1.5px solid #0f766e; }
.tot-row.total b { color: #0b4d8f; }
.q-accept { font-size: 13px; line-height: 1.6; margin-bottom: 6px; }
.q-sig-grid { display: flex; gap: 30px; margin: 30px 0 18px; }
.q-sig { flex: 1; text-align: center; border-top: 1px dotted #999; padding-top: 6px; font-size: 12px; color: var(--text-2); }
.q-terms { font-size: 12.5px; line-height: 1.7; margin-top: 16px; }
.q-terms-title { font-weight: 800; margin-bottom: 6px; }
.q-ol { padding-left: 20px; margin: 0; }
.q-ol li { margin-bottom: 6px; }

/* ---------- Invoice (J7 Fabrication format) ---------- */
.invoice-doc { background: #fff; padding: 14px 18px; font-size: 12px; }
.inv-title { text-align: center; font-size: 20px; font-weight: 800; color: #0f766e; margin-bottom: 12px; letter-spacing: .5px; }
.inv-top2 { display: flex; align-items: stretch; gap: 14px; margin-bottom: 8px; }
.inv-left { flex: 0 0 38%; display: flex; flex-direction: column; gap: 10px; }
.inv-left > .inv-party:last-child { flex: 1; }
.inv-right { flex: 1 1 62%; min-width: 0; }
.inv-irn { line-height: 1.7; font-size: 11.5px; margin-bottom: 6px; }
.inv-party { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; line-height: 1.6; font-size: 12px; }
.inv-party .inv-block-title { margin-bottom: 3px; }
.inv-supplier-box { display: flex; align-items: flex-start; gap: 10px; }
.inv-name { font-weight: 800; font-size: 15px; color: #0f766e; }
.inv-logo { margin-bottom: 6px; }
.inv-logo img { max-height: 56px; max-width: 180px; object-fit: contain; }
.inv-table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.inv-meta { width: 100%; border-collapse: collapse; border: 1px solid var(--line); }
.inv-meta td { padding: 4px 6px; border: 1px solid var(--line); font-size: 10.5px; }
.inv-meta td.k { font-weight: 700; background: #f8fafc; white-space: normal; overflow-wrap: anywhere; }
.inv-terms { margin-top: 8px; margin-bottom: 0; }
.inv-details-title { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-bottom: 0; }
.inv-details-title .inv-block-title { margin-bottom: 0; }
.inv-totfoot { background: #f8fafc; }
.inv-tot-grid { display: flex; }
.inv-tot-grid .it { flex: 1 1 0; border-left: 1px solid var(--line); padding: 5px 4px; text-align: center; line-height: 1.3; }
.inv-tot-grid .it:first-child { border-left: none; }
.inv-tot-grid .it span { display: block; font-size: 10.5px; font-weight: 700; }
.inv-tot-grid .it b { display: block; font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .2px; }
.inv-tot-grid .it.total { background: #d9ecff; color: #0b4d8f; }
.inv-block { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 12px; line-height: 1.6; }
.inv-block-title { font-weight: 800; text-transform: uppercase; letter-spacing: .5px; font-size: 10.5px; color: var(--text-2); margin-bottom: 4px; }
.inv-table-wrap { margin: 10px 0; overflow-x: auto; }
.inv-table th { background: #0f766e; color: #fff; padding: 5px 6px; text-align: center; font-size: 9px; border: 1px solid #0f766e; text-transform: uppercase; letter-spacing: .3px; }
.inv-table td { padding: 5px 6px; border: 1px solid var(--line); vertical-align: top; font-size: 10.5px; }
.inv-table .l { text-align: left; }
.inv-table .r { text-align: right; }
.inv-table .c { text-align: center; }
.inv-table .b { font-weight: 700; background: #f8fafc; }
.inv-words { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 12px; }
.inv-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.inv-row > .inv-box { margin-bottom: 0; flex: 1 1 auto; }
.inv-row > .inv-sign-box { flex: 0 0 40%; }
.inv-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 12px; line-height: 1.6; }
.inv-box pre { margin: 0; white-space: pre-wrap; font-family: inherit; font-size: 12px; line-height: 1.6; }
.inv-decl { font-size: 12px; line-height: 1.6; }
.inv-sign-box { text-align: right; font-size: 13px; line-height: 1.8; }

/* ---------- Invoice responsive ---------- */
@media (max-width: 700px) {
  .invoice-doc { padding: 10px 8px; }
  .inv-title { font-size: 16px; margin-bottom: 10px; }
  .inv-top2 { flex-direction: column; gap: 8px; }
  .inv-left, .inv-right { flex: 1 1 100%; width: 100%; }
  .inv-row { flex-direction: column; }
  .inv-row > .inv-sign-box { flex: 1 1 auto; }
  .inv-tot-grid { flex-wrap: wrap; }
  .inv-tot-grid .it { flex: 1 1 45%; border-left: none; border-top: 1px solid var(--line); padding: 4px 3px; }
  .inv-tot-grid .it:first-child { border-left: none; }
  .inv-tot-grid .it.total { flex: 1 1 100%; }
  .inv-table th { font-size: 8px; padding: 4px 3px; }
  .inv-table td { font-size: 9px; padding: 4px 3px; }
}

/* ---------- Settings logo picker ---------- */
.logo-pick { border: 1.5px dashed var(--primary); border-radius: 10px; padding: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; text-align: center; min-height: 80px; color: var(--text-2); background: #f8fafc; }
.logo-pick img { max-height: 64px; max-width: 220px; object-fit: contain; }
.logo-pick:hover { border-color: var(--primary); background: #f0fdfa; }

.q-logo { margin-bottom: 0; }

/* ---------- Print ---------- */
@media print {
  .topbar, .bottomnav, .sidebar, .sidebar-overlay, .page-header, .page-actions,
  .btn, .doc-actions, .tabs, .searchbar, .fab, .btn-fab, .modal-backdrop { display: none !important; }
  body { background: #fff; }
  .mainarea { padding: 0; margin: 0; }
  .doc { box-shadow: none; border-radius: 0; }
  .doc-head { background: #0f766e !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-total { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .totals, .tot-head, .tot-row, .tot-row.total { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table tr, .doc-table tr { break-inside: avoid; }
  .no-print { display: none !important; }
  .card, .quote-doc { box-shadow: none; border-radius: 0; }
  .quote-doc, .q-page { overflow: visible; }
  html, body { height: auto; overflow: visible; }
  .q-page { page-break-after: always; break-after: page; }
  .q-page:last-child { page-break-after: auto; break-after: auto; }
  .q-page-last { page-break-after: auto !important; break-after: auto !important; page-break-before: auto !important; break-before: auto !important; }
  .win-block { break-inside: avoid; }
  .totals { break-inside: avoid; }
  .win-svg { border: none; }
  .win-draw-img .win-img-big { border: 1px solid #ddd; box-shadow: none; }
.invoice-doc { padding: 10px 12px; }
  .inv-table th, .inv-table td { font-size: 9px; padding: 4px 4px; }
  .inv-table-wrap { overflow: visible; }
}

/* ---------- Standalone print slips (advance slip etc.) ---------- */
#print-slip { display: none; }
@media print {
  body.eb-print-slip .topbar, body.eb-print-slip .bottomnav, body.eb-print-slip .sidebar,
  body.eb-print-slip .sidebar-overlay, body.eb-print-slip .mainarea,
  body.eb-print-slip .modal-backdrop, body.eb-print-slip .toast-root { display: none !important; }
  body.eb-print-slip #print-slip { display: block !important; }
  #print-slip .adv-slip-doc { max-width: 100%; margin: 0 auto; padding: 12px 20px; color: #1e293b; font-size: 12px; line-height: 1.35; font-family: 'DejaVu Sans', Arial, sans-serif; }
  #print-slip .as-title { text-align: center; font-size: 19px; font-weight: 800; letter-spacing: 3px; padding: 8px 0 6px; border-bottom: 2px solid #0f766e; }
  #print-slip .as-co { text-align: center; margin-top: 10px; font-size: 13px; font-weight: 700; }
  #print-slip .as-sub { text-align: center; font-size: 10px; color: #475569; }
  #print-slip .as-emp { margin-top: 16px; width: 100%; border-collapse: collapse; }
  #print-slip .as-emp td { padding: 5px 8px; border: 1px solid #cbd5e1; font-size: 11.5px; }
  #print-slip .as-emp td.k { background: #f1f5f9; font-weight: 700; width: 42%; }
  #print-slip .as-amount { margin-top: 18px; text-align: center; }
  #print-slip .as-lbl { font-size: 11px; color: #475569; }
  #print-slip .as-big { font-size: 26px; font-weight: 800; color: #0f766e; }
  #print-slip .as-words { margin-top: 14px; font-size: 11.5px; }
  #print-slip .as-cmt { margin-top: 14px; font-size: 11.5px; border-top: 1px solid #e2e8f0; padding-top: 10px; }
  #print-slip .as-sign { margin-top: 42px; text-align: right; }
  #print-slip .as-sigline { border-top: 1px solid #cbd5e1; padding-top: 4px; width: 46%; margin-left: auto; text-align: center; font-size: 11px; }
  #print-slip .as-fnote { margin-top: 16px; text-align: center; font-size: 9.5px; color: #64748b; }
}

/* ---------- Animations ---------- */
.fade-in { animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Feature additions
   ============================================================ */
.btn-warn { background: var(--accent); color: #fff; }
.btn-warn:hover { filter: brightness(1.05); }

/* pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager-info { font-size: 12.5px; color: var(--text-3); }
.pager-btns { display: flex; gap: 6px; }

/* bar chart (dashboard) */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 0 16px 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-track { width: 100%; max-width: 34px; height: 100%; display: flex; align-items: flex-end; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar-fill { width: 100%; background: var(--primary-grad); border-radius: 6px; min-height: 3px; transition: height .4s ease; }
.bar-label { font-size: 10px; color: var(--text-3); white-space: nowrap; }

/* product grid */
.prod-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 12px 16px; }
.prod-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; text-align: center; background: var(--card); }
.prod-card:hover { box-shadow: var(--shadow); }
.prod-img { width: 100%; height: 96px; border-radius: 8px; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; position: relative; }
.prod-brand { position: absolute; top: 6px; left: 6px; background: rgba(255,255,255,.92); border-radius: 6px; padding: 2px 5px; max-width: 70%; }
.prod-brand img { max-height: 22px; max-width: 60px; display: block; object-fit: contain; }
.prod-img img { width: 100%; height: 100%; object-fit: cover; }
.prod-img-ph { color: var(--text-3); }
.prod-img-ph svg { width: 34px; height: 34px; }
.prod-name { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.25; }
.prod-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; word-break: break-all; }
.prod-meta { display: flex; justify-content: center; gap: 4px; margin-top: 6px; flex-wrap: wrap; }

/* barcode (Code39) */
.bc-wrap { display: flex; flex-direction: column; align-items: center; padding: 10px 0 4px; }
.bc-bars { display: flex; height: 42px; overflow: hidden; }
.bc-bar { width: 1px; background: #000; }
.bc-w { width: 3px; }
.bc-gap { width: 1px; background: transparent; }
.bc-gw { width: 3px; background: transparent; }
.bc-text { font-family: "Courier New", monospace; font-size: 11px; letter-spacing: 3px; color: #000; margin-top: 3px; }

/* salary slips */
.slip-list { display: flex; flex-direction: column; gap: 8px; }
.slip-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; align-items: center; }
.slip-name { font-size: 14px; font-weight: 700; }
.slip-sub { font-size: 12px; color: var(--text-2); grid-column: 1 / 2; }
.slip-actions { grid-column: 2 / 3; grid-row: 1 / 3; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.slip-net { font-weight: 800; font-size: 14px; color: var(--primary-dark); }

/* checkbox (bulk) */
.check { display: inline-flex; align-items: center; margin-right: 10px; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check span { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line-2); background: var(--card); display: inline-flex; align-items: center; justify-content: center; transition: all .15s; }
.check input:checked + span { background: var(--primary); border-color: var(--primary); }
.check input:checked + span::after { content: ""; width: 10px; height: 6px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg) translateY(-1px); }

/* list avatar image thumbnails */
.list-avatar img { display: block; }

/* ============================================================
   Dark mode
   ============================================================ */
[data-theme="dark"] {
  --primary: #2dd4bf;
  --primary-dark: #5eead4;
  --primary-light: #134e4a;
  --accent: #f59e0b;
  --danger: #f87171;
  --success: #4ade80;
  --info: #60a5fa;
  --bg: #0b1120;
  --card: #111a2e;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --line: #1e293b;
  --line-2: #334155;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .6);
}
[data-theme="dark"] body { color: var(--text); }
[data-theme="dark"] .segmented button.on { background: var(--card); color: var(--primary-dark); }
[data-theme="dark"] .chip-blue { background: #172554; color: #93c5fd; }
[data-theme="dark"] .chip-green { background: #052e1b; color: #86efac; }
[data-theme="dark"] .chip-red { background: #3f0d12; color: #fca5a5; }
[data-theme="dark"] .topbar, [data-theme="dark"] .bottomnav, [data-theme="dark"] .sidebar { background: var(--card); }
[data-theme="dark"] .doc, [data-theme="dark"] .doc-head, [data-theme="dark"] .doc-total, [data-theme="dark"] .inv-box, [data-theme="dark"] .inv-title, [data-theme="dark"] .inv-table th {
  background: var(--card); color: var(--text);
}
[data-theme="dark"] .bc-bar { background: #e2e8f0; }
[data-theme="dark"] .bc-text { color: #e2e8f0; }
[data-theme="dark"] .prod-card, [data-theme="dark"] .slip-item { background: var(--card); }
[data-theme="dark"] .logo-pick:hover { background: #134e4a; }
[data-theme="dark"] .input, [data-theme="dark"] .select, [data-theme="dark"] .textarea { color: var(--text); }
[data-theme="dark"] .modal { background: var(--card); color: var(--text); }
[data-theme="dark"] .toast { background: var(--text); color: var(--bg); }
[data-theme="dark"] .stat-card.green { color: var(--primary-dark); }
[data-theme="dark"] .slip-net { color: var(--primary-dark); }

/* ============================================================
   QR + Purchase + expanded dark coverage
   ============================================================ */
.qr-wrap { display: flex; justify-content: center; padding: 8px 0 2px; }
.qr-img { width: 96px; height: 96px; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 4px; }
[data-theme="dark"] .qr-img { border-color: var(--line-2); }
.img-ph-text { font-size: 11px; color: var(--text-3); }

.pur-head { display: grid; grid-template-columns: 1fr 72px 92px 90px 32px; gap: 6px; font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; margin-bottom: 6px; }
.pur-item { display: grid; grid-template-columns: 1fr 72px 92px 90px 32px; gap: 6px; margin-bottom: 8px; align-items: center; }
.pur-amt { font-weight: 700; font-size: 13px; text-align: right; }
.pur-total { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-2); font-size: 15px; }
.pur-total b { color: var(--primary-dark); }
.cat-pager { border-top: 1px solid var(--line); }

[data-theme="dark"] .card,
[data-theme="dark"] .searchbar .input,
[data-theme="dark"] .modal { background: var(--card); }
[data-theme="dark"] .list-item { border-bottom-color: var(--line); }
[data-theme="dark"] .list-avatar { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .list-item.ripple:active { background: var(--line); }
[data-theme="dark"] .table th { background: var(--line); color: var(--text-2); }
[data-theme="dark"] .table tbody tr:active { background: var(--line); }
[data-theme="dark"] .table td { border-bottom-color: var(--line); }
[data-theme="dark"] .card-title { border-bottom-color: var(--line); }
[data-theme="dark"] .segmented { background: var(--line); }
[data-theme="dark"] .empty .empty-ic { background: var(--line); }
[data-theme="dark"] .prod-img { background: var(--line); }
[data-theme="dark"] .doc-line, [data-theme="dark"] .line-calc { color: var(--text-2); }
[data-theme="dark"] .line-calc { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .inv-box { background: var(--line); border-color: var(--line-2); }
[data-theme="dark"] .doc { box-shadow: none; }
[data-theme="dark"] .bar-fill { background: var(--primary-grad); }
[data-theme="dark"] .pager { border-top-color: var(--line); }
[data-theme="dark"] .chip-gray { background: var(--line); color: var(--text-2); }
[data-theme="dark"] .chip-amber { background: #422006; color: #fcd34d; }
[data-theme="dark"] .btn-soft { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .btn-ghost { color: var(--text-2); }
[data-theme="dark"] .nav-item.active { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .nav-item:active { background: var(--line); }
[data-theme="dark"] .field-label { color: var(--text-2); }
[data-theme="dark"] .tab { background: var(--line); color: var(--text-2); }
[data-theme="dark"] .tab.on { background: var(--primary-grad); color: #fff; }
[data-theme="dark"] .slip-list { border-color: var(--line); }
[data-theme="dark"] .sidebar { background: var(--card); border-right-color: var(--line); }
[data-theme="dark"] .qr-img { background: #fff; }
[data-theme="dark"] .pur-total b { color: var(--primary-dark); }

.adv-box { background: var(--bg); border: 1px dashed var(--line-2); border-radius: 12px; padding: 12px; }
.adv-basic { font-size: 13px; }
.adv-basic b { color: var(--primary-dark); }
.adv-rows { display: flex; flex-direction: column; gap: 6px; }
.adv-row { display: grid; grid-template-columns: 24px 90px 92px 1fr auto; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; }
.adv-slip { font-weight: 700; }
.adv-dt { color: var(--text-3); }
.adv-cmt { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adv-amt { font-weight: 700; }
.adv-net { font-size: 13.5px; }
.adv-net b { color: var(--primary-dark); }
[data-theme="dark"] .adv-box { background: var(--line); }
[data-theme="dark"] .adv-row { background: var(--bg); border-color: var(--line-2); }

.wa-rows { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow: auto; padding-right: 2px; }
.wa-row { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.wa-info { flex: 1; min-width: 0; }
.wa-name { font-weight: 700; font-size: 14px; }
.wa-sub { font-size: 12px; color: var(--text-3); margin-bottom: 6px; }
.wa-msg { width: 100%; min-height: 72px; font-size: 12.5px; }
.wa-actions { display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 520px) {
  .wa-row { flex-direction: column; }
  .wa-actions { flex-direction: row; width: 100%; }
  .wa-actions .btn { flex: 1; }
}
[data-theme="dark"] .wa-row { background: var(--line); border-color: var(--line-2); }

.pay-slip { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.pay-org { background: var(--primary-grad); color: #fff; font-weight: 800; font-size: 15px; padding: 14px 16px; }
.pay-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); padding: 10px 16px 4px; }
.pay-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; font-size: 13.5px; border-top: 1px solid var(--line); }
.pay-row span { color: var(--text-2); }
.pay-row b { font-weight: 700; text-align: right; }
.pay-total { background: var(--primary-light); font-size: 15px; }
.pay-total b { color: var(--primary-dark); }
[data-theme="dark"] .pay-total { background: var(--line); }

/* ============================================================
   Mobile UX polish (touch targets, responsive forms, safe areas)
   ============================================================ */
button, a { -webkit-tap-highlight-color: transparent; }
.list-item, .nav-item, .bottomnav-item, .tab { -webkit-tap-highlight-color: transparent; }

.btn:focus-visible, .tab:focus-visible, .nav-item:focus-visible,
.bottomnav-item:focus-visible, .segmented button:focus-visible,
.line-del:focus-visible, .topbar-btn:focus-visible, .switch-row:focus-within {
  outline: 3px solid rgba(15,118,110,.35); outline-offset: 1px;
}

.mainarea {
  padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px) 14px calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 16px);
}
.btn-fab.tl { bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 16px); }
.card-title { flex-wrap: wrap; }
.pur-qty, .pur-rate { width: 100%; }

/* Add to Home Screen helper */
.inst-hero {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 18px;
  background: var(--primary-grad); color: #fff; display: flex; align-items: center; justify-content: center;
}
.inst-hero svg { width: 30px; height: 30px; }
.inst-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.inst-step { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 1.5; }
.inst-n {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-dark); font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}

/* enlarge tap areas on touch devices */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; }
  .btn-icon { width: 44px; height: 44px; }
  .line-del { width: 40px; height: 40px; }
  .segmented button { padding: 11px 8px; }
  .topbar-btn { width: 44px; height: 44px; }
}

/* purchase items: stack name / qty-rate-amount on small screens */
@media (max-width: 560px) {
  .pur-head { display: none; }
  .pur-item {
    grid-template-columns: 1fr 1fr 1fr 40px;
    grid-template-areas:
      "nm nm nm rm"
      "q r amt amt";
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
  }
  .pur-name { grid-area: nm; }
  .pur-qty { grid-area: q; }
  .pur-rate { grid-area: r; }
  .pur-amt { grid-area: amt; }
  .pur-rm { grid-area: rm; }
  .q-sig-grid { flex-direction: column; gap: 16px; margin: 20px 0 12px; }
}

/* ============================================================
   Dark mode polish (documents + purchase rows)
   ============================================================ */
[data-theme="dark"] .login-card,
[data-theme="dark"] .invoice-doc,
[data-theme="dark"] .quote-doc,
[data-theme="dark"] .q-page,
[data-theme="dark"] .win-block,
[data-theme="dark"] .line-card { background: var(--card); color: var(--text); }
[data-theme="dark"] .line-head,
[data-theme="dark"] .win-code { background: var(--line); color: var(--text-2); }
[data-theme="dark"] .doc-head { background: var(--primary-grad); color: #fff; }
[data-theme="dark"] .doc-head .doc-type,
[data-theme="dark"] .doc-head .doc-meta,
[data-theme="dark"] .doc-company { color: #fff; }
[data-theme="dark"] .totals { background: #0b2447; }
[data-theme="dark"] .tot-head { background: #12294a; border-color: #1e3a5f; color: #cbd5e1; }
[data-theme="dark"] .tot-row { background: #0b2447; border-top-color: rgba(45,212,191,.18); }
[data-theme="dark"] .tot-row.total { background: #123456; color: #7dd3fc; }
[data-theme="dark"] .tot-row.total b { color: #7dd3fc; }
[data-theme="dark"] .cv-table th,
[data-theme="dark"] .inv-meta td.k,
[data-theme="dark"] .inv-totfoot { background: var(--line); color: var(--text-2); }
[data-theme="dark"] .cv-table tr.total td { background: #134e4a; color: #5eead4; }
[data-theme="dark"] .inv-table td,
[data-theme="dark"] .inv-meta td,
[data-theme="dark"] .cv-table td,
[data-theme="dark"] .ws-table td { border-color: var(--line-2); }
[data-theme="dark"] .q-head { border-bottom-color: var(--primary); }
[data-theme="dark"] .q-sign { color: var(--text); }
[data-theme="dark"] .pur-item { background: var(--bg); border-color: var(--line-2); }
