/* ======================================================
   CSS DESIGN SYSTEM — Sky Dent Invoicing
   Professional medical/dental vendor palette.
   ====================================================== */

:root {
  /* --- Palette --- */
  --color-primary:       #0f766e;   /* deep teal 700 — professional, medical */
  --color-primary-hover: #115e59;   /* deep teal 800 */
  --color-primary-medium:#0d9488;   /* teal 600 */
  --color-primary-light: #f0fdfa;   /* teal 50 — soft background tint */
  --color-primary-glow:  rgba(13, 148, 136, 0.12); /* focus shadow */
  --color-surface:       #ffffff;
  --color-bg:            #f8fafc;   /* Slate 50 background */
  --color-border:        #e2e8f0;   /* Slate 200 border */
  --color-border-light:  #f1f5f9;   /* Slate 100 border */
  --color-text:          #334155;   /* Slate 700 text */
  --color-text-dark:     #0f172a;   /* Slate 900 text */
  --color-muted:         #64748b;   /* Slate 500 muted */
  --color-danger:        #ef4444;   /* Red 500 */
  --color-danger-light:  #fef2f2;
  --color-danger-border: #fecaca;
  --color-success:       #10b981;   /* Emerald 500 */
  --color-success-light: #ecfdf5;
  --color-success-border:#a7f3d0;
  --color-row-alt:       #f8fafc;   /* Slate 50 alt row */
  /* Slightly stronger divider used inside the invoice form sections */
  --color-border-strong: #dde3ec;
  /* Draft / amber notice palette (was hardcoded inline in invoice routes) */
  --color-draft-bg:      #fefce8;
  --color-draft-border:  #fef08a;
  --color-draft-title:   #854d0e;
  --color-draft-text:    #a16207;
  /* Post action (distinct green, differentiated from primary teal) */
  --color-post:          #16a34a;   /* Green 600 */
  --color-post-hover:    #15803d;   /* Green 700 */

  /* --- Typography --- */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* --- Spacing & shape --- */
  --space:   1rem;       /* base spacing unit */
  --radius:  12px;       /* modern border radius */
  --radius-sm: 8px;      /* smaller border radius for inputs/buttons */

  /* --- Depth & Elevation --- */
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -1px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.08), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* === LAYOUT CONTAINER === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--space) * 1.5) var(--space);
}

/* === HEADER === */
header {
  background: transparent;
  color: var(--color-text-dark);
  padding: 0;
  margin-bottom: calc(var(--space) * 1.5);
  border: none;
}

header .container {
  padding-top: 0;
  padding-bottom: 0;
  max-width: 100%;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

header h1 {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--color-text-dark);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

header p {
  font-size: 0.95rem;
  color: var(--color-muted);
  margin-top: 4px;
}

/* === SECTIONS === */
section {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: calc(var(--space) * 1.5);
  margin-bottom: calc(var(--space) * 1.5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

section:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(13, 148, 136, 0.1);
}

section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: var(--space);
  padding-bottom: calc(var(--space) * 0.5);
  border-bottom: 1px solid var(--color-border-light);
  letter-spacing: -0.01em;
  text-transform: none;
}

/* === FORM GRID === */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: calc(var(--space) * 1);
}

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

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
}

/* === UNIFIED FIELD STYLING ===
   One modern look for every input / select / textarea / search field,
   across the products forms, the invoice form and the search dropdowns. */
.form-group input,
.form-group select,
.form-group textarea,
.search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--color-text-dark);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.form-group textarea,
textarea {
  height: auto;
  min-height: 80px;
  padding: 10px 12px;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-group input[readonly],
.form-group input[disabled],
input[readonly],
input[disabled] {
  background: var(--color-bg);
  color: var(--color-muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* === CARD — primary content container (used on every page) === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: calc(var(--space) * 1.5);
  margin-bottom: calc(var(--space) * 1.5);
  box-shadow: var(--shadow-sm);
}

.card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: 8px;
}

/* Small helper / caption text under fields */
.hint { font-size: 12px; color: var(--color-muted); margin-top: 4px; }

/* Opening-stock callout (product add form + add-product modal) */
.opening-stock-section { margin-top: 16px; padding: 16px; background: var(--color-bg); border: 1px dashed var(--color-border); border-radius: var(--radius-sm); }
.opening-stock-section h3 { margin: 0 0 4px; font-size: 13px; color: var(--color-text-dark); text-transform: none; letter-spacing: 0; }
.opening-stock-section .hint { font-size: 12px; color: var(--color-muted); margin: 0 0 12px; }

/* Form layout grid (auto-fit responsive columns) */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

/* Sub-heading with divider (invoice form section titles) */
.form-section-head { margin-top: 16px; border-bottom: 1px solid var(--color-border-strong); padding-bottom: 8px; }

/* Definition-list grid (detail views) */
.dl-grid { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; align-items: center; }
.dl-label { font-weight: 600; color: var(--color-muted); font-size: 13px; }
.dl-value { color: var(--color-text-dark); font-size: 14px; font-weight: 500; }
.qty-highlight { font-size: 20px; font-weight: 700; color: var(--color-primary); }

/* Section header (title + actions row) */
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--color-border); padding-bottom: 12px; gap: 8px; }
.section-head h2 { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

/* Inline text link */
a.link { color: var(--color-primary); text-decoration: none; font-weight: 500; }
a.link:hover { text-decoration: underline; color: var(--color-primary-hover); }

/* Empty-state cell / message */
.empty { text-align: center; color: var(--color-muted); padding: 48px 0; font-size: 14px; background: var(--color-bg); border-radius: var(--radius-sm); border: 1px dashed var(--color-border); margin: 16px 0; }

/* Totals box (invoice & product views) — scoped so it never collides with
   the dashboard .totals-grid .totals-row variant defined below. */
.totals-box { width: 320px; margin-left: auto; background: var(--color-bg); padding: 20px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); margin-top: 16px; }
.totals-box .totals-row { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 14px; color: var(--color-muted); }
.totals-box .totals-row span:last-child { color: var(--color-text-dark); font-weight: 600; }
.totals-box .totals-row.grand { font-weight: 800; font-size: 18px; margin-top: 16px; padding-top: 16px; border-top: 2px solid var(--color-border); color: var(--color-primary); }
.totals-box .totals-row.grand span:last-child { color: var(--color-primary); }

/* Sortable table headers (invoice list) */
th.sortable { cursor: pointer; user-select: none; }
th.sortable a { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; }
th.sortable:hover { color: var(--color-primary); }
th.sortable.sorted, th.sortable.sorted a { color: var(--color-primary); }
.sort-ind { font-size: 10px; line-height: 1; }

/* Product search cell keeps a usable width inside the line table */
.lines-table .product-wrapper { min-width: 200px; }

/* Invoice-list filter bar — bare fields share the unified field look */
.invoice-filter { display: flex; gap: 16px; margin-bottom: 20px; align-items: center; flex-wrap: wrap; }
.invoice-filter input[type="text"],
.invoice-filter select {
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--color-text-dark);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.invoice-filter input[type="text"]:focus,
.invoice-filter select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* In-page validation (client-side UX layer; the server stays authoritative) */
.field-error input,
input.field-error,
.field-error .search-input {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}
.field-error-msg { color: var(--color-danger); font-size: 12px; font-weight: 600; margin-top: 4px; }

/* Draft notice block (invoice detail) */
.notice-draft { background: var(--color-draft-bg); border: 1px solid var(--color-draft-border); }
.notice-draft-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.notice-draft h3 { color: var(--color-draft-title); margin: 0; }
.notice-draft p { color: var(--color-draft-text); font-size: 13px; margin-top: 4px; }

/* Small uppercase caption (detail field labels) */
.caption { font-size: 12px; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* Inline-SVG alignment helper */
.icon { display: inline-block; vertical-align: middle; }

/* Right-aligned numeric cells/fields */
.text-right { text-align: left; }

/* Horizontal button / control group */
.actions { display: flex; gap: 8px; align-items: center; }
.actions-end { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }

/* Clickable table row */
.row-link { cursor: pointer; }

/* Visually-hidden label (screen-reader only) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === TABLE === */
.lines-table, .products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.lines-table thead th, .products-table thead th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  padding: 10px 8px;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.lines-table thead th.col-item-no {
  width: 110px;
}

.lines-table thead th:last-child {
  width: 44px;  /* narrow delete column */
}

.lines-table tbody tr, .products-table tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: background-color 0.15s ease;
}

.lines-table tbody tr:hover, .products-table tbody tr:hover {
  background-color: var(--color-primary-light);
}

.lines-table tbody td, .products-table tbody td {
  padding: 10px 8px;
  vertical-align: middle;
}

/* Empty state message (shown when no rows) */
.lines-empty {
  text-align: center;
  padding: calc(var(--space) * 2) var(--space);
  color: var(--color-muted);
  font-size: 0.88rem;
}

/* Add-line button */
#add-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: calc(var(--space) * 1);
  padding: 8px 18px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  background: transparent;
  border: 1px dashed var(--color-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

#add-line:hover {
  background: var(--color-primary-light);
  border-style: solid;
}

#add-line:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* === TOTALS === */
.totals-grid {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  width: 280px;
  padding: 6px 0;
  font-size: 0.9rem;
}

.totals-row span:first-child {
  color: var(--color-muted);
}

.totals-row span:last-child {
  font-weight: 600;
  text-align: left;
  min-width: 120px;
  color: var(--color-text-dark);
}

.totals-row.grand-total {
  border-top: 2px solid var(--color-primary);
  padding-top: 12px;
  margin-top: 4px;
}

.totals-row.grand-total span:last-child {
  font-size: 1.25rem;
  color: var(--color-primary);
  font-weight: 800;
}

/* === FOOTER === */
footer {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: calc(var(--space) * 1.25);
  display: flex;
  justify-content: flex-end;
  gap: calc(var(--space) * 0.75);
}

footer button {
  height: 42px;
  padding: 0 24px;
  font-family: var(--font-family);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

footer button:active:not(:disabled) {
  transform: scale(0.98);
}

footer button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#btn-save {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 2px 0 rgba(15, 118, 110, 0.2);
}

#btn-save:not(:disabled):hover {
  background: var(--color-primary-hover);
}

#btn-new {
  background: #fff;
  color: var(--color-text-dark);
  border: 1px solid var(--color-border);
}

#btn-new:not(:disabled):hover {
  background: var(--color-bg);
  border-color: var(--color-muted);
}

/* === RESPONSIVE (usable down to ~768px) === */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .totals-row {
    width: 100%;
  }

  .totals-grid {
    align-items: stretch;
  }

  footer {
    flex-direction: column;
  }

  footer button {
    width: 100%;
  }
}

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

  .lines-table, .products-table {
    font-size: 0.8rem;
  }

  .lines-table thead th,
  .lines-table tbody td,
  .products-table thead th,
  .products-table tbody td {
    padding: 10px 8px;
  }
}

/* === LINE-ITEM INPUTS (inside table cells) === */
.line-item-no {
  width: 80px;
  height: 34px;
  padding: 0 6px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  cursor: default;
  box-shadow: none;
}

.line-product-cell {
  position: relative;
  min-width: 220px;
}

.line-product-cell input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  color: var(--color-text-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  text-align: left;
  direction: ltr;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.line-product-cell input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.line-product-cell input.has-product {
  background: #f0fdfa; /* soft primary light */
  border-color: var(--color-primary-medium);
  color: var(--color-primary-hover);
  font-weight: 500;
}

/* --- Search dropdown (product/customer autocomplete) ---
   The list is positioned dynamically by search-dropdown.js (it sets
   top/left/width + display inline); all static appearance lives here so the
   component no longer injects its own <style> or hardcoded hex. */
.search-dropdown-wrapper { position: relative; }

.search-dropdown-list {
  position: fixed;
  z-index: 2000;
  max-height: 250px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  list-style: none;
  margin: 4px 0 0 0;
  padding: 6px 0;
  width: 100%;
}

.search-dropdown-list li {
  padding: 8px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light);
  transition: background 0.1s ease, color 0.1s ease;
  color: var(--color-text);
}

.search-dropdown-list li:hover,
.search-dropdown-list li.active {
  background: var(--color-primary-light);
  color: var(--color-primary-hover);
}

.search-dropdown-list li.dd-empty,
.search-dropdown-list li.dd-empty:hover {
  color: var(--color-muted);
  font-style: italic;
  cursor: default;
  background: transparent;
}

.search-dropdown-list .dd-artno {
  font-weight: 600;
  color: var(--color-primary);
}

.search-dropdown-list .dd-cat {
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

/* --- Qty / Discount / Price inputs inside table --- */
.lines-table input[type="number"],
.lines-table input[type="text"] {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  color: var(--color-text-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.lines-table input[type="number"]:focus,
.lines-table input[type="text"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* --- Price select --- */
.lines-table select {
  width: 110px;
  height: 34px;
  padding: 0 6px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  color: var(--color-text-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.lines-table select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* --- Line total (read-only) --- */
.line-total-value {
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  min-width: 90px;
  color: var(--color-text-dark);
}

/* --- Remove (×) button --- */
.btn-remove-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn-remove-line:hover {
  color: var(--color-danger);
  background: var(--color-danger-light);
  border-color: var(--color-danger-border);
}

/* --- Draft restoration banner --- */
.draft-banner {
  display: none;
  background: var(--color-success);
  color: #fff;
  padding: 12px 24px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  animation: slideDownFade 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDownFade {
  from { transform: translate(-50%, -20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* --- Validation Errors --- */
.validation-errors {
  display: none;
  background: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: var(--space);
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.validation-errors ul {
  margin-left: 20px;
  margin-top: 6px;
}

.validation-errors li {
  margin-bottom: 4px;
}

/* --- Global Initialization Error Banner --- */
.init-error-banner {
  background: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: var(--space);
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

/* === APP LAYOUT & SIDEBAR === */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #0f172a; /* Slate 900 — professional solid dark */
  color: #fff;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-brand {
  margin-bottom: 40px;
  padding: 0 12px;
}

.sidebar-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--color-primary-medium);
  font-weight: 600;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  color: #94a3b8; /* Slate 400 */
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background-color: rgba(255, 255, 255, 0.03);
  color: #f8fafc;
}

.sidebar-link.active {
  background-color: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-weight: 600;
  border-left-color: var(--color-primary-medium);
}

.sidebar-icon {
  display: inline-flex;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
}

.sidebar-link:hover .sidebar-icon,
.sidebar-link.active .sidebar-icon {
  opacity: 1;
  color: var(--color-primary-medium);
}

.app-main {
  flex: 1;
  padding: 24px 24px;
  overflow-x: auto;
}

/* === DASHBOARD COMPONENTS === */
.db-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: calc(var(--space) * 1.25);
  margin-bottom: calc(var(--space) * 1.5);
}

.db-metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, border-color 0.2s ease;
}

.db-metric-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: rgba(13, 148, 136, 0.15);
}

.db-metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-muted);
  letter-spacing: 0.05em;
}

.db-metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-text-dark);
  line-height: 1.2;
}

.db-metric-subtext {
  font-size: 12px;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.db-metric-trend-up {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid var(--color-success-border);
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
}

.db-metric-trend-down {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
}

/* Monthly Chart */
.db-chart-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: calc(var(--space) * 1.5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.db-chart-container:hover {
  box-shadow: var(--shadow-md);
}

.db-chart-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 28px;
}

.db-chart-canvas {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 220px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border-light);
  gap: 16px;
}

.db-chart-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
  position: relative;
  cursor: pointer;
}

.db-chart-bar {
  width: 32px;
  background: linear-gradient(180deg, rgba(13, 148, 136, 0.15) 0%, rgba(13, 148, 136, 0.02) 100%);
  border: 1px solid rgba(13, 148, 136, 0.25);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  position: relative;
  min-height: 4px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.db-chart-bar.current {
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.15);
}

.db-chart-bar-wrapper:hover .db-chart-bar {
  transform: translateY(-2px);
  background: linear-gradient(180deg, rgba(13, 148, 136, 0.3) 0%, rgba(13, 148, 136, 0.1) 100%);
  border-color: rgba(13, 148, 136, 0.5);
}

.db-chart-bar-wrapper:hover .db-chart-bar.current {
  background: linear-gradient(180deg, var(--color-primary-hover) 0%, #115e59 100%);
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.3);
}

.db-chart-bar-value {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: 6px;
  white-space: nowrap;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 2px 6px;
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s ease;
}

.db-chart-bar-wrapper:hover .db-chart-bar-value {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.db-chart-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  gap: 16px;
}

.db-chart-label {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--color-muted);
  font-weight: 600;
}

/* Side-by-Side Panels */
.db-panels-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--space) * 1.5);
  margin-bottom: calc(var(--space) * 1.5);
}

.db-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.db-panel:hover {
  box-shadow: var(--shadow-md);
}

.db-panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 20px;
  border-bottom: 1px solid var(--color-border-light);
  padding-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.db-view-all-link {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primary-medium);
  text-decoration: none;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  transition: color 0.15s ease;
}

.db-view-all-link:hover {
  color: var(--color-primary);
}

/* Product list with elegant soft rows */
.db-product-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.db-product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--color-text);
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.db-product-row:hover {
  background: #ffffff;
  border-color: var(--color-border-light);
  box-shadow: var(--shadow-sm);
  transform: translateX(3px);
  color: var(--color-text-dark);
}

.db-product-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.db-product-leader {
  display: none; /* remove old leaders */
}

.db-product-val {
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  color: var(--color-primary-medium);
}

/* Payment Method list */
.db-paymethod-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.db-paymethod-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.db-paymethod-info {
  display: flex;
  justify-content: space-between;
}

.db-paymethod-name {
  font-weight: 600;
  color: var(--color-text-dark);
}

.db-paymethod-pct {
  font-weight: 700;
  color: var(--color-primary-medium);
}

.db-paymethod-bar-bg {
  height: 8px;
  background: var(--color-bg);
  border-radius: 9999px;
  overflow: hidden;
}

.db-paymethod-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-medium) 100%);
  border-radius: 9999px;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Empty state and Loading */
.db-empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  font-size: 14px;
  font-style: italic;
  grid-column: 1 / -1;
  box-shadow: var(--shadow-sm);
}

.db-loading-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--color-muted);
  font-size: 15px;
  font-weight: 500;
}

/* Responsive Dashboard */
/* --- Desktop Default styling for mobile components --- */
.mobile-top-bar {
  display: none;
}
.sidebar-backdrop {
  display: none;
}
.table-responsive {
  width: 100%;
}

/* --- Table Responsive Wrapper --- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: calc(var(--space) * 1);
}

/* --- Mobile / Tablet Styles (<= 768px) --- */
@media (max-width: 768px) {
  /* Layout shifts */
  .app-layout {
    flex-direction: column;
    padding-top: 56px; /* offset for fixed top bar */
  }

  .app-main {
    padding: 16px !important;
    overflow-x: hidden;
  }

  .container {
    padding: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Mobile Top Bar */
  .mobile-top-bar {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #0f172a; /* Solid Slate 900 */
    color: #fff;
    padding: 0 16px;
    z-index: 1000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: var(--shadow-sm);
  }

  .hamburger-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: -8px;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s ease;
  }

  .hamburger-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
  }

  .mobile-bar-brand {
    margin-left: 12px;
    display: flex;
    flex-direction: column;
  }

  .mobile-bar-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.01em;
  }

  .mobile-bar-subtitle {
    font-size: 0.65rem;
    color: var(--color-primary-medium);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: -2px;
  }

  /* Off-canvas Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1010;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: none;
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: 10px 0 30px rgba(15, 23, 42, 0.25);
  }

  /* Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1005;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }

  body.drawer-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.drawer-open {
    overflow: hidden;
  }

  /* Form stack & text size prevention on focus */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: calc(var(--space) * 0.75) !important;
  }

  .form-group input,
  .form-group select,
  .form-group textarea,
  .search-input {
    font-size: 16px !important; /* iOS Zoom Prevention */
  }

  .form-group input,
  .form-group select,
  .search-input {
    height: 44px !important;    /* Touch Target Size */
  }

  /* Button touch target improvements */
  .action-btn {
    width: 44px !important;
    height: 44px !important;
  }

  .btn-remove-line {
    width: 44px !important;
    height: 44px !important;
  }

  #add-line {
    height: 44px !important;
    font-size: 0.95rem !important;
    padding: 10px 20px !important;
    width: 100% !important;
    justify-content: center;
  }

  /* Totals full-width stacking */
  .totals-grid {
    align-items: stretch !important;
  }

  .totals-row {
    width: 100% !important;
  }

  /* Footer stack */
  footer {
    flex-direction: column !important;
    gap: 10px !important;
    padding: 16px !important;
  }

  footer button {
    width: 100% !important;
    height: 48px !important;
    font-size: 0.95rem !important;
  }

  /* Dashboard Metrics 2x2 wrapping */
  .db-metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  /* Dashboard side-by-side panels stack */
  .db-panels-row {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Dashboard chart bar sizing on mobile */
  .db-chart-canvas {
    gap: 6px !important;
  }
  .db-chart-labels {
    gap: 6px !important;
  }
  .db-chart-bar {
    width: 24px !important;
  }
  .db-chart-label {
    font-size: 10px !important;
  }
}

/* Very Small Phones (<= 480px) */
@media (max-width: 480px) {
  .db-metrics-grid {
    grid-template-columns: 1fr !important;
  }
  .db-chart-canvas {
    gap: 4px !important;
  }
  .db-chart-labels {
    gap: 4px !important;
  }
  .db-chart-bar {
    width: 20px !important;
  }
  .db-chart-label {
    font-size: 9px !important;
  }
}

/* --- Global Elements: Buttons, Badges, Alerts, Action Icons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 20px;
  font-family: var(--font-family);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease, transform 0.1s ease;
  text-decoration: none;
  gap: 6px;
  box-sizing: border-box;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff !important;
  box-shadow: 0 1px 2px 0 rgba(15, 118, 110, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: #ffffff;
  color: var(--color-text-dark) !important;
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: var(--color-muted);
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff !important;
  box-shadow: 0 1px 2px 0 rgba(239, 68, 68, 0.2);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-dashed {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px dashed var(--color-primary);
}

.btn-dashed:hover:not(:disabled) {
  background: var(--color-primary-light);
  border-style: solid;
}

.btn-success {
  background: var(--color-post);
  color: #ffffff !important;
  box-shadow: 0 1px 2px 0 rgba(22, 163, 74, 0.2);
}

.btn-success:hover:not(:disabled) {
  background: var(--color-post-hover);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 0.8rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-active {
  background: var(--color-success-light);
  color: var(--color-success);
  border-color: var(--color-success-border);
}

.badge-inactive {
  background: var(--color-danger-light);
  color: var(--color-danger);
  border-color: var(--color-danger-border);
}

.badge-draft {
  background: #fef3c7; /* Amber 100 */
  color: #d97706;      /* Amber 600 */
  border-color: #fde68a;
}

.badge-posted {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: #99f6e4;
}

/* Muted VOID badge — a voided invoice reads as neutralised, not alarming. */
.badge-void {
  background: #f1f5f9; /* Slate 100 */
  color: #64748b;      /* Slate 500 */
  border-color: #e2e8f0;
}

.badge-lowstock {
  background: #fffbeb; /* Yellow 50 */
  color: #d97706;      /* Yellow 600 */
  border-color: #fde68a;
}

.badge-costmissing {
  background: #fffbeb;
  color: #ea580c;
  border-color: #fed7aa;
}

.read-only-display-price {
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--color-muted);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  box-shadow: none;
}

.alert {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success {
  background: var(--color-success-light);
  color: #065f46; /* Emerald 800 */
  border-color: var(--color-success-border);
}

.alert-error {
  background: var(--color-danger-light);
  color: #991b1b; /* Red 800 */
  border-color: var(--color-danger-border);
}

.alert-warning {
  background: #fffbeb; /* Amber 50 */
  color: #92400e;      /* Amber 800 */
  border-color: #fde68a;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--color-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  box-sizing: border-box;
}

.action-btn:hover {
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-color: var(--color-primary-medium);
}

/* Responsive tables and column wrapping rules */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space);
}

.products-table th, 
.products-table td,
.lines-table th,
.lines-table td {
  white-space: nowrap;
}

/* Allow description to wrap and maintain min-width on products page */
#products-table th:nth-child(2),
#products-table td:nth-child(2) {
  white-space: normal;
  min-width: 250px;
  width: auto;
}

/* Allow product description/autocomplete column in line-item table to wrap */
.lines-table th:first-child,
.lines-table td:first-child {
  white-space: normal;
}

/* Printing styles */
@media print {
  .sidebar {
    display: none !important;
  }
  .app-main {
    padding: 0 !important;
  }
  .mobile-top-bar,
  .sidebar-backdrop {
    display: none !important;
  }
  .app-layout {
    padding-top: 0 !important;
  }
}
