:root {
  --ink: #1a1a2e; --ink-light: #4a4a6a; --ink-muted: #5a5a7a;
  --accent: #2563eb; --accent-light: #dbeafe;
  --accent-inv-title: #0A3A84;
  --accent-total: #E39A0A;
  --po-accent: #2563eb; --po-accent-light: #ede9fe;
  --surface: #ffffff; --surface-2: #f8f9fc; --surface-3: #f0f2f8;
  --border: #e2e5f0; --border-strong: #c8cce0;
  --success: #059669; --danger: #dc2626; --warning: #d97706;
  --radius: 10px; --radius-sm: 6px;
  --shadow: 0 1px 4px rgba(26,26,46,0.08), 0 4px 16px rgba(26,26,46,0.06);
  --shadow-lg: 0 8px 32px rgba(26,26,46,0.12);
  --font: 'Inter', -apple-system, sans-serif;
  --mobile-breakpoint: 768px;
  --tablet-breakpoint: 1024px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--surface-2); color: var(--ink); min-height: 100vh; font-size: 14px; line-height: 1.5; }
/* Do not reveal any app data until the current session has been authenticated. */
body.auth-locked > :not(#auth-overlay) { display: none !important; }
body.auth-locked #auth-overlay { display: flex; }

/* TOPBAR - Mobile Responsive */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 12px; display: flex; align-items: center; position: sticky; top: 0; z-index: 100; flex-wrap: wrap; gap: 4px; }
.topbar-brand { font-weight: 700; font-size: 16px; color: var(--accent); letter-spacing: -0.3px; padding-right: 16px; border-right: 1px solid var(--border); margin-right: 4px; height: 56px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-brand svg { width: 20px; height: 20px; }

/* Mobile Navigation Dropdown */
.nav-dropdown { position: relative; flex: 1; min-width: 120px; }
.nav-dropdown-btn { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; color: var(--ink); cursor: pointer; font-family: var(--font); width: 100%; justify-content: space-between; }
.nav-dropdown-btn:hover { background: var(--surface-3); }
.nav-dropdown-menu { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); z-index: 200; margin-top: 4px; overflow: hidden; }
.nav-dropdown-menu.open { display: block; }
.nav-dropdown-menu .tab { padding: 10px 14px; display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--ink-muted); cursor: pointer; border-bottom: 1px solid var(--border); transition: background .15s; }
.nav-dropdown-menu .tab:last-child { border-bottom: none; }
.nav-dropdown-menu .tab:hover { background: var(--surface-2); color: var(--ink); }
.nav-dropdown-menu .tab.active-inv { color: var(--accent); background: var(--accent-light); }
.nav-dropdown-menu .tab.active-po { color: var(--po-accent); background: var(--po-accent-light); }
.nav-dropdown-menu .tab.active-saved { color: var(--success); background: #ecfdf5; }
.nav-dropdown-menu .tab.active-settings { color: var(--ink); background: var(--surface-3); }

/* Desktop Tabs */
.tabs-desktop { display: none; height: 56px; flex: 1; }
@media (min-width: 768px) {
  .tabs-desktop { display: flex; }
  .nav-dropdown { display: none; }
  .topbar { padding: 0 24px; flex-wrap: nowrap; }
}
.tab { padding: 0 16px; display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.active-inv { color: var(--accent); border-color: var(--accent); }
.tab.active-po { color: var(--po-accent); border-color: var(--po-accent); }
.tab.active-saved { color: var(--success); border-color: var(--success); }
.tab.active-settings { color: var(--ink); border-color: var(--ink); }

.topbar-actions { display: flex; gap: 6px; margin-left: auto; padding-left: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: all .15s; font-family: var(--font); white-space: nowrap; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink-light); }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #1d4ed8; }
.btn-po { background: var(--po-accent); color: #fff; border-color: var(--po-accent); }
.btn-po:hover { background: #6d28d9; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; }
.btn-danger { background: transparent; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-warning { background: transparent; border-color: #fde68a; color: var(--warning); }
.btn-warning:hover { background: #fffbeb; }
.btn-sm { font-size: 11px; padding: 4px 10px; }

@media (max-width: 480px) {
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 6px 10px; }
  .topbar-brand { font-size: 14px; padding-right: 10px; }
}

/* PAGES */
.page { display: none; }
.page.active { display: block; }
/* Used only while a saved document is exported. It gives html2canvas the same
   fully rendered document it gets from the editor, without changing the page
   the user is looking at. */
.page.pdf-export-stage { display: block; position: fixed; left: -10000px; top: 0; width: 1200px; background: #fff; }

/* DOC LAYOUT */
.doc-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; max-width: 1200px; margin: 0 auto; padding: 16px; align-items: start; }
@media (max-width: 1024px) {
  .doc-layout { grid-template-columns: 1fr; }
  .controls { order: -1; }
}
@media (max-width: 768px) {
  .doc-layout { padding: 10px; gap: 12px; }
}

/* PREVIEW WRAP */
.preview-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.preview-header { background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 600; color: var(--ink-muted); letter-spacing: 0.05em; text-transform: uppercase; flex-wrap: wrap; gap: 6px; }
.preview-status { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--success); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

/* ================================================================
   DOCUMENT BODY - FIXED LAYOUT, RESPONSIVE SCALING
   ================================================================ */
.doc-body { 
  padding: 24px 20px; 
  min-height: 700px; 
  background: #fff;
  overflow-x: auto; /* allows horizontal scroll if needed, but preserves layout */
}

/* On larger screens, increase padding */
@media (min-width: 768px) {
  .doc-body { padding: 40px 44px; min-height: 900px; }
}

/* On small screens, shrink font sizes & padding, keep SAME LAYOUT */
@media (max-width: 640px) {
  .doc-body { padding: 14px 12px; font-size: 12px; }
  .doc-title { font-size: 18px !important; }
  .doc-meta-label { font-size: 8px !important; }
  .doc-meta-value { font-size: 12px !important; }
  .doc-table { font-size: 11px !important; }
  .doc-table thead th { font-size: 8px !important; padding: 6px 6px !important; }
  .doc-table tbody td { font-size: 11px !important; padding: 6px 6px !important; }
  .totals-row { font-size: 11px !important; }
  .totals-row.grand { font-size: 13px !important; }
  .doc-company-name { font-size: 14px !important; }
  .doc-number { font-size: 11px !important; }
  .doc-footer-note { font-size: 10px !important; }
  .doc-sig-name { font-size: 11px !important; }
  .doc-company-meta { font-size: 10px !important; }
  .doc-meta-sub { font-size: 10px !important; }
  .doc-notes-text { font-size: 11px !important; }
}

@media (max-width: 480px) {
  .doc-body { padding: 14px; font-size: 11px; }
  .doc-title { font-size: 16px !important; }
  .doc-table thead th { padding: 4px 4px !important; font-size: 7px !important; }
  .doc-table tbody td { padding: 4px 4px !important; font-size: 10px !important; }
  .totals-row { font-size: 10px !important; }
  .totals-row.grand { font-size: 12px !important; }
}

/* ================================================================
   DOCUMENT HEADER - ALWAYS ROW LAYOUT
   ================================================================ */
.doc-header { 
  display: flex; 
  flex-direction: row; 
  justify-content: space-between; 
  align-items: flex-start; 
  gap: 12px; 
  margin-bottom: 24px;
  flex-wrap: wrap; /* wraps only if absolutely necessary */
}
.doc-logo-area { 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  flex: 1 1 50%;
  min-width: 150px;
}
.doc-logo-img { 
  max-height: 50px; 
  max-width: 140px; 
  object-fit: contain; 
  display: none; 
}
@media (min-width: 768px) {
  .doc-logo-img { max-height: 60px; max-width: 160px; }
}
.doc-company-name { 
  font-size: 16px; 
  font-weight: 700; 
  color: var(--ink); 
  letter-spacing: -0.3px; 
}
@media (min-width: 768px) {
  .doc-company-name { font-size: 18px; }
}
.doc-company-meta { 
  font-size: 11px; 
  color: var(--ink-muted); 
  line-height: 1.6; 
}
@media (min-width: 768px) {
  .doc-company-meta { font-size: 12px; }
}
.doc-title-area { 
  text-align: right; 
  flex: 0 1 auto;
  min-width: 120px;
}
.doc-title { 
  font-size: 18px; 
  font-weight: 800; 
  letter-spacing: -1px; 
  line-height: 1; 
  margin-bottom: 4px; 
}
@media (min-width: 768px) {
  .doc-title { font-size: 22px; }
}
.doc-title.inv-color { color: var(--accent-inv-title); }
.doc-title.po-color { color: var(--accent-inv-title); }
.doc-number { 
  font-size: 12px; 
  font-weight: 600; 
  color: var(--ink-muted); 
  margin-bottom: 2px; 
}
.doc-date { 
  font-size: 11px; 
  color: var(--ink-muted); 
}

.doc-divider { 
  border: none; 
  border-top: 1px solid var(--border); 
  margin: 20px 0; 
}
@media (min-width: 768px) {
  .doc-divider { margin: 28px 0; }
}

/* ================================================================
   META ROW - STAYS AS 2 COLUMNS UNLESS VERY SMALL
   ================================================================ */
.doc-meta-row { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 16px; 
  margin-bottom: 24px; 
}
@media (max-width: 400px) { 
  .doc-meta-row { 
    grid-template-columns: 1fr 1fr; 
    gap: 8px; 
  } 
}
@media (min-width: 600px) {
  .doc-meta-row { gap: 24px; }
}
@media (min-width: 768px) {
  .doc-meta-row { gap: 32px; margin-bottom: 36px; }
}
.doc-meta-label { 
  font-size: 9px; 
  font-weight: 700; 
  letter-spacing: 0.1em; 
  text-transform: uppercase; 
  color: var(--ink-muted); 
  margin-bottom: 6px; 
}
@media (min-width: 768px) {
  .doc-meta-label { font-size: 10px; margin-bottom: 8px; }
}
.doc-meta-value { 
  font-size: 13px; 
  font-weight: 600; 
  color: var(--ink); 
  margin-bottom: 2px; 
}
@media (min-width: 768px) {
  .doc-meta-value { font-size: 14px; }
}
.doc-meta-sub { 
  font-size: 11px; 
  color: var(--ink-muted); 
  line-height: 1.6; 
}
@media (min-width: 768px) {
  .doc-meta-sub { font-size: 12px; }
}
.doc-meta-right { 
  text-align: right; 
}
@media (max-width: 400px) { 
  .doc-meta-right { 
    text-align: right; 
  } 
}

/* ================================================================
   TABLE - ALWAYS TABULAR, NEVER STACKS
   ================================================================ */
.doc-table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 12px; 
}
@media (min-width: 768px) {
  .doc-table { font-size: 13px; }
}
.doc-table thead tr { background: var(--ink); color: #fff; }
.doc-table thead th { 
  padding: 8px 10px; 
  font-size: 9px; 
  font-weight: 700; 
  letter-spacing: 0.1em; 
  text-transform: uppercase; 
  text-align: left; 
}
@media (min-width: 768px) {
  .doc-table thead th { padding: 10px 14px; font-size: 10px; }
}
.doc-table thead th.r { text-align: right; }
.doc-table tbody tr { border-bottom: 1px solid var(--border); }
.doc-table tbody tr:last-child { border-bottom: 2px solid var(--border-strong); }
.doc-table tbody td { 
  padding: 8px 10px; 
  font-size: 12px; 
  color: var(--ink); 
  vertical-align: top; 
  word-break: break-word; 
}
@media (min-width: 768px) {
  .doc-table tbody td { padding: 12px 14px; font-size: 13px; }
}
.doc-table tbody td.r { text-align: right; }
.item-desc { 
  color: var(--ink-muted); 
  font-size: 10px; 
  margin-top: 2px; 
}
@media (min-width: 768px) {
  .item-desc { font-size: 12px; }
}

/* ================================================================
   TOTALS - KEEPS NOTES LEFT, TOTALS RIGHT
   ================================================================ */
.doc-summary-row { 
  display: flex; 
  flex-wrap: wrap; 
  gap: 24px; 
  align-items: flex-start; 
  justify-content: flex-end; 
  margin-top: 12px; 
  padding: 14px; 
}
.doc-summary-left { 
  flex: 1 1 280px; 
  min-width: 220px; 
  max-width: 420px; 
  align-self: flex-start; 
}
.doc-summary-left .doc-notes { margin-top: 0; }
.doc-totals { 
  display: flex; 
  justify-content: flex-end; 
  flex: 0 0 auto; 
  margin-left: auto; 
  margin-top: 0; 
  align-self: flex-start; 
}
.doc-totals-inner { 
  min-width: 180px; 
  width: auto; 
  max-width: 260px; 
}
@media (max-width: 768px) {
  .doc-summary-row { flex-direction: row; gap: 16px; padding: 0; }
  /**.doc-totals { width: 100%; } ***/
  .doc-totals-inner { max-width: 100%; }
}  
@media (max-width: 480px) {
  .doc-totals-inner { max-width: 100%; }
}
.totals-row { 
  display: flex; 
  justify-content: space-between; 
  padding: 4px 0; 
  font-size: 12px; 
  color: var(--ink-light); 
}
@media (min-width: 768px) {
  .totals-row { font-size: 13px; padding: 5px 0; }
}
.totals-row.grand { 
  border-top: 2px solid var(--ink); 
  margin-top: 6px; 
  padding-top: 8px; 
  font-size: 14px; 
  font-weight: 700; 
  color: var(--ink); 
}
@media (min-width: 768px) {
  .totals-row.grand { margin-top: 8px; padding-top: 10px; font-size: 15px; }
}
.totals-row .val { font-weight: 600; }
.totals-row.grand .val { color: var(--accent-total); }
.totals-row.grand.po-grand .val { color: var(--accent-total); }

/* NOTES */
.doc-notes { margin-top: 24px; }
.doc-notes-label { 
  font-size: 9px; 
  font-weight: 700; 
  letter-spacing: 0.1em; 
  text-transform: uppercase; 
  color: var(--ink-muted); 
  margin-bottom: 6px; 
}
@media (min-width: 768px) {
  .doc-notes-label { font-size: 10px; margin-bottom: 8px; }
}
.doc-notes-text { 
  font-size: 12px; 
  color: var(--ink-muted); 
  line-height: 1.7; 
  white-space: pre-wrap; 
  word-break: break-word; 
  word-spacing: normal; 
  letter-spacing: normal; 
}
.doc-warranty-text { margin-bottom: 16px; }

/* FOOTER */
.doc-footer { 
  margin-top: 32px; 
  display: flex; 
  flex-direction: row; 
  justify-content: space-between; 
  align-items: flex-end; 
  gap: 12px; 
  border-top: 1px solid var(--border); 
  padding-top: 16px; 
  flex-wrap: wrap; 
}
@media (min-width: 600px) {
  .doc-footer { flex-direction: row; justify-content: space-between; align-items: flex-end; }
}
@media (min-width: 768px) {
  .doc-footer { margin-top: 48px; padding-top: 24px; }
}
.doc-footer-note { 
  font-size: 11px; 
  color: var(--ink-muted); 
  font-style: italic; 
}
@media (min-width: 768px) {
  .doc-footer-note { font-size: 12px; }
}
.doc-sig { 
  display: inline-flex; 
  flex-direction: column; 
  align-items: flex-start; 
  text-align: left; 
}
@media (min-width: 600px) {
  .doc-sig { align-items: flex-end; text-align: right; }
}
.doc-sig-img { 
  max-height: 40px; 
  max-width: 120px; 
  object-fit: contain; 
  display: block; 
  margin-bottom: 4px; 
}
@media (min-width: 768px) {
  .doc-sig-img { max-height: 52px; max-width: 160px; }
}
.doc-sig-line { 
  width: 120px; 
  border-bottom: 1px solid var(--border-strong); 
  margin-bottom: 6px; 
  height: 28px; 
}
@media (min-width: 600px) {
  .doc-sig-line { margin-left: auto; }
}
@media (min-width: 768px) {
  .doc-sig-line { width: 180px; height: 36px; }
}
.doc-sig-label { 
  font-size: 8px; 
  letter-spacing: 0.1em; 
  text-transform: uppercase; 
  color: var(--ink-muted); 
}
.doc-sig-name { 
  font-size: 12px; 
  font-weight: 600; 
  color: var(--ink); 
  margin-top: 2px; 
}
@media (min-width: 768px) {
  .doc-sig-name { font-size: 13px; }
}

/* SIDEBAR CONTROLS - Responsive */
.controls { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) {
  .controls { gap: 16px; }
}
.ctrl-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.ctrl-header { padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); display: flex; align-items: center; gap: 7px; }
@media (min-width: 768px) {
  .ctrl-header { padding: 13px 18px; font-size: 12px; }
}
.ctrl-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 768px) {
  .ctrl-body { padding: 16px 18px; gap: 12px; }
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 10px; font-weight: 600; color: var(--ink-muted); }
@media (min-width: 768px) {
  .field label { font-size: 11px; }
}
.field input, .field textarea, .field select { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 12px; color: var(--ink); background: var(--surface); transition: border-color .15s, box-shadow .15s; width: 100%; }
@media (min-width: 768px) {
  .field input, .field textarea, .field select { padding: 8px 10px; font-size: 13px; }
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.field textarea { resize: vertical; min-height: 60px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 400px) {
  .field-row { grid-template-columns: 1fr; }
}

/* ITEMS EDITOR */
.item-cols-header { display: grid; grid-template-columns: 1fr 50px 70px 28px; gap: 4px; padding: 4px 10px; background: var(--surface-3); border-bottom: 1px solid var(--border); }
@media (min-width: 768px) {
  .item-cols-header { grid-template-columns: 1fr 64px 80px 28px; gap: 6px; padding: 6px 14px; }
}
.item-cols-header span { font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
@media (min-width: 768px) {
  .item-cols-header span { font-size: 10px; }
}
.item-row { display: grid; grid-template-columns: 1fr 50px 70px 28px; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); align-items: start; }
@media (min-width: 768px) {
  .item-row { grid-template-columns: 1fr 64px 80px 28px; gap: 6px; padding: 10px 14px; }
}
.item-row:last-child { border-bottom: none; }
.item-row input { padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; font-family: var(--font); color: var(--ink); width: 100%; }
@media (min-width: 768px) {
  .item-row input { padding: 6px 8px; font-size: 12px; }
}
.item-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.del-btn { background: transparent; border: none; cursor: pointer; color: var(--ink-muted); padding: 4px; border-radius: 4px; display: flex; align-items: center; justify-content: center; margin-top: 4px; transition: color .15s, background .15s; }
.del-btn:hover { color: var(--danger); background: #fef2f2; }
.add-item-row { padding: 6px 10px; background: var(--surface-2); }
.delivery-totals { margin-top: 14px; padding-right: 14px; }
.received-section { margin-top: 34px; }
.received-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.received-card { border: 1px solid var(--border); padding: 16px; min-height: 144px; display: flex; flex-direction: column; gap: 13px; color: var(--ink-muted); font-size: 12px; }
.received-heading { display: flex; gap: 12px; align-items: center; color: var(--ink-muted); }
.received-heading strong { color: var(--ink); }
.received-line, .received-field div { border-bottom: 1px solid var(--border-strong); min-height: 16px; }
.received-field { display: grid; grid-template-columns: auto 1fr; align-items: end; gap: 10px; }
@media (max-width: 640px) { .received-grid { gap: 6px; } .received-card { padding: 8px; min-height: 118px; font-size: 9px; gap: 9px; } .received-heading { gap: 6px; } .received-field { gap: 5px; } }
@media (min-width: 768px) {
  .add-item-row { padding: 10px 14px; }
}

/* SAVED DOCUMENTS PAGE */
.saved-layout { max-width: 1200px; margin: 0 auto; padding: 16px; }
@media (min-width: 768px) {
  .saved-layout { padding: 24px; }
}
.saved-header { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
@media (min-width: 768px) {
  .saved-header { flex-direction: row; justify-content: space-between; align-items: center; }
}
.saved-title { font-size: 20px; font-weight: 700; color: var(--ink); letter-spacing: -0.4px; }
@media (min-width: 768px) {
  .saved-title { font-size: 24px; }
}
.saved-search { display: flex; gap: 8px; flex-wrap: wrap; }
.saved-search input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 13px; color: var(--ink); background: var(--surface); flex: 1; min-width: 150px; }
.saved-search select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 13px; color: var(--ink); background: var(--surface); }
.saved-search input:focus, .saved-search select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.status-select { border: 0; border-radius: 999px; padding: 5px 8px; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; color: var(--ink); background: var(--surface-3); }
.status-select.status-draft { background: #e5e7eb; color: #374151; }
.status-select.status-pending { background: #fef3c7; color: #92400e; }
.status-select.status-paid, .status-select.status-accepted, .status-select.status-received { background: #d1fae5; color: #065f46; }
.status-select.status-ordered { background: #dbeafe; color: #1d4ed8; }
.status-select.status-declined, .status-select.status-cancelled { background: #fee2e2; color: #991b1b; }

.saved-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.saved-tab { padding: 8px 16px; font-size: 13px; font-weight: 600; color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color .15s, border-color .15s; }
.saved-tab:hover { color: var(--ink); }
.saved-tab.active { color: var(--accent); border-color: var(--accent); }
.saved-tab.active-po { color: var(--po-accent); border-color: var(--po-accent); }

.saved-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.saved-actions .action-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.saved-actions .action-label { color: var(--ink-muted); font-size: 13px; }
.saved-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 12px 16px; background: var(--surface-2); border-top: 1px solid var(--border); }
.saved-pagination button { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); padding: 6px 10px; cursor: pointer; transition: background .15s, border-color .15s; }
.saved-pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.saved-pagination .page-info { font-size: 12px; color: var(--ink-muted); }
.saved-table th.checkbox-col, .saved-table td.checkbox-col { width: 44px; text-align: center; }
.saved-table th.checkbox-col input, .saved-table td.checkbox-col input { width: 16px; height: 16px; }
.saved-table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; overflow-x: auto; }
.saved-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 700px; }
@media (min-width: 768px) {
  .saved-table { font-size: 13px; min-width: unset; }
}
.saved-table thead { background: var(--surface-3); }
.saved-table thead th { padding: 10px 12px; text-align: left; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); cursor: pointer; white-space: nowrap; user-select: none; }
@media (min-width: 768px) {
  .saved-table thead th { padding: 12px 16px; font-size: 11px; }
}
.saved-table thead th:hover { color: var(--ink); }
.saved-table thead th .sort-icon { margin-left: 4px; opacity: 0.5; }
.saved-table tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
.saved-table tbody tr:hover { background: var(--surface-2); }
.saved-table tbody td { padding: 10px 12px; vertical-align: middle; }
@media (min-width: 768px) {
  .saved-table tbody td { padding: 12px 16px; }
}
.saved-table tbody td .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.saved-empty { padding: 40px 20px; text-align: center; color: var(--ink-muted); font-size: 14px; }
.saved-empty svg { margin-bottom: 8px; opacity: 0.3; }

/* SETTINGS - Responsive */
.settings-layout { max-width: 720px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
@media (min-width: 768px) {
  .settings-layout { padding: 32px 24px; gap: 20px; }
}
.settings-title { font-size: 20px; font-weight: 700; color: var(--ink); letter-spacing: -0.4px; margin-bottom: 2px; }
@media (min-width: 768px) {
  .settings-title { font-size: 22px; }
}
.settings-sub { color: var(--ink-muted); font-size: 13px; }
@media (min-width: 768px) {
  .settings-sub { font-size: 14px; }
}
.s-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.s-card-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
@media (min-width: 768px) {
  .s-card-header { padding: 16px 24px; }
}
.s-card-title { font-size: 13px; font-weight: 600; color: var(--ink); }
@media (min-width: 768px) {
  .s-card-title { font-size: 14px; }
}
.s-card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) {
  .s-card-body { padding: 20px 24px; gap: 14px; }
}
.s-field-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 600px) {
  .s-field-row { grid-template-columns: 1fr 1fr; gap: 14px; }
}
.s-field { display: flex; flex-direction: column; gap: 4px; }
.s-field label { font-size: 11px; font-weight: 600; color: var(--ink-light); }
@media (min-width: 768px) {
  .s-field label { font-size: 12px; }
}
.s-field input, .s-field textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 12.5px; color: var(--ink); background: var(--surface); transition: border-color .15s, box-shadow .15s; width: 100%; }
@media (min-width: 768px) {
  .s-field input, .s-field textarea { padding: 9px 12px; font-size: 13.5px; }
}
.s-field input:focus, .s-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.s-field textarea { resize: vertical; min-height: 70px; }

.upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 16px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; position: relative; }
@media (min-width: 768px) {
  .upload-area { padding: 20px; }
}
.upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.upload-area input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-preview { max-height: 60px; max-width: 160px; object-fit: contain; margin: 0 auto 6px; display: none; border-radius: 4px; }
@media (min-width: 768px) {
  .upload-preview { max-height: 72px; max-width: 200px; margin-bottom: 8px; }
}
.upload-text { font-size: 11px; color: var(--ink-muted); }
@media (min-width: 768px) {
  .upload-text { font-size: 12px; }
}
.upload-text strong { color: var(--accent); }
.s-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px; flex-wrap: wrap; }
@media (min-width: 768px) {
  .s-actions { padding-top: 8px; }
}

@media (max-width: 768px) {
  .doc-layout { padding: 10px; gap: 12px; }
}

/* TOAST */
.saved-toast { position: fixed; bottom: 16px; right: 16px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 12px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px; transform: translateY(80px); opacity: 0; transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s; z-index: 999; max-width: 90%; }
@media (min-width: 768px) {
  .saved-toast { bottom: 24px; right: 24px; padding: 12px 20px; font-size: 13px; }
}
.saved-toast.show { transform: translateY(0); opacity: 1; }
.auth-error { display: none; margin-top: 12px; color: var(--danger); font-size: 12px; font-weight: 500; }
.auth-error.show { display: block; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; z-index: 300; padding: 16px; }
.modal-overlay.show { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: 420px; width: 100%; padding: 24px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal-desc { font-size: 13px; color: var(--ink-muted); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn { padding: 8px 20px; }

/* PRINT */
@media print {
  @page { margin: 12mm; }
  html, body { background: #fff !important; color: #000 !important; }
  .topbar, .controls, .preview-header, .tab, .btn, .btn-primary, .btn-ghost, .toast, .modal-overlay, .nav-dropdown { display: none !important; }
  .doc-layout { display: block !important; padding: 0 !important; width: 100% !important; }
  .preview-wrap { box-shadow: none !important; border-radius: 0 !important; background: #fff !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .doc-body { padding: 24px 32px !important; background: #fff !important; width: 100% !important; }
  .doc-table thead { background: #111 !important; color: #fff !important; }
  .doc-table tbody td, .doc-meta-label, .doc-notes-label, .doc-notes-text, .totals-row, .doc-footer-note, .doc-meta-sub, .doc-meta-value { color: #000 !important; }
  .doc-notes-text { white-space: pre-wrap !important; }
  .doc-summary-row { display: flex !important; flex-wrap: wrap !important; flex-direction: row !important; align-items: flex-start !important; justify-content: flex-end !important; }
  .doc-summary-left { flex: 1 1 320px !important; max-width: 60% !important; }
  .doc-totals { flex: 0 0 220px !important; width: auto !important; min-width: 0 !important; }
  .doc-summary-left, .doc-totals { width: auto !important; min-width: 0 !important; align-self: flex-start !important; }
  .page { display: block !important; }
  .page:not(.print-target) { display: none !important; }
}
