/* ============================================================================
   SRK Honda — Receipt & GST Invoice System
   Theme: ElevenLabs-inspired light theme.
   ----------------------------------------------------------------------------
   Sections:
     1. Design tokens (CSS variables)
     2. Reset + base
     3. Auth-only layout (login / change-password)
     4. App layout (sidebar + topbar + main)
     5. Sidebar
     6. Topbar
     7. User menu dropdown
     8. Cards
     9. Buttons
    10. Inputs / forms
    11. Tables
    12. Badges + pills
    13. Alerts (inline)
    14. Toasts (overlay)
    15. Modal dialogs
    16. Utility classes
    17. Mobile responsiveness (<768px)
    18. Print stylesheet
   ========================================================================= */

/* 1. Design tokens ---------------------------------------------------------- */
:root {
  --c-bg:        #f8f9fb;
  --c-card:      #ffffff;
  --c-border:    #e5e7eb;
  --c-border-2:  #d1d5db;
  --c-text:      #0f172a;
  --c-muted:     #6b7280;
  --c-subtle:    #9ca3af;
  --c-link:      #2563eb;
  --c-primary:   #0f172a;
  --c-primary-h: #1e293b;
  --c-success:   #047857;
  --c-success-bg:#ecfdf5;
  --c-danger:    #b91c1c;
  --c-danger-bg: #fef2f2;
  --c-warn:      #b45309;
  --c-warn-bg:   #fffbeb;
  --c-zebra:     #fafbfc;
  --c-hover:     #f3f4f6;

  --r-card:   10px;
  --r-input:  8px;
  --r-pill:   999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 1px 3px rgba(0,0,0,.06);          /* matches BUILD_PROMPT spec */
  --shadow-lg: 0 8px 24px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.04);

  --sidebar-w: 240px;
  --topbar-h:  60px;
  --content-pad: 24px;

  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.30);
}

/* 2. Reset + base ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { max-width: 100%; }
svg { display: inline-block; vertical-align: middle; width: 18px; height: 18px; flex-shrink: 0; }

a { color: var(--c-link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 600; line-height: 1.25; color: var(--c-text); }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p  { margin: 0 0 12px; }
small, .muted { color: var(--c-muted); }
hr { border: 0; border-top: 1px solid var(--c-border); margin: 20px 0; }

::selection { background: rgba(37,99,235,.18); }

/* Skip-link — first body child in header.php. Visible on focus only. */
.skip-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--c-primary); color: #fff;
  padding: 8px 14px; border-radius: 8px;
  font-weight: 500; z-index: 200;
  text-decoration: none;
}
.skip-link:focus { top: 8px; outline: none; box-shadow: var(--focus-ring); }

/* 3. Auth-only layout (login, change-password before app shell) ------------- */
.auth-layout {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-card .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.auth-card .brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--c-primary); color: #fff;
  border-radius: 8px; font-weight: 700; font-size: 13px;
  letter-spacing: .04em;
}

/* 4. App layout ------------------------------------------------------------- */
body.app-layout { min-height: 100vh; }

.main-col {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.content {
  flex: 1;
  padding: var(--content-pad);
  max-width: 1280px;
  width: 100%;
}

/* 5. Sidebar --------------------------------------------------------------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--c-card);
  border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  z-index: 60;
  overflow-y: auto;
}
.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--c-text);
  font-weight: 600;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--c-primary); color: #fff;
  border-radius: 8px; font-weight: 700; font-size: 11px;
  letter-spacing: .04em;
}
.brand-text { font-size: 15px; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 1px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  color: var(--c-text);
  border-radius: 8px;
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-link:hover { background: var(--c-hover); text-decoration: none; }
.nav-link.active { background: var(--c-primary); color: #fff; }
.nav-link.active:hover { background: var(--c-primary-h); }

.nav-section-label {
  margin: 14px 12px 6px;
  font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  /* Bumped from --c-subtle (#9ca3af, ~2.85:1) to --c-muted for AA contrast. */
  color: var(--c-muted);
  display: flex; align-items: center; gap: 6px;
}
.admin-pill {
  background: #fef3c7; color: #92400e;
  font-size: 9px; font-weight: 600;
  padding: 1px 6px; border-radius: var(--r-pill);
  letter-spacing: .04em; text-transform: uppercase;
}

/* Mobile drawer overlay */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 55;
}

/* 6. Topbar ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--content-pad);
  background: rgba(248, 249, 251, 0.85);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--c-border);
  z-index: 40;
}
.topbar-menu { display: none; }      /* hidden on desktop */
.topbar-spacer { flex: 1; }
.page-title {
  font-size: 16px; margin: 0; font-weight: 600;
  /* Stop long titles from wrapping the topbar on narrow screens. */
  min-width: 0; flex-shrink: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--c-text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--c-hover); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* 7. User menu dropdown ---------------------------------------------------- */
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 6px;
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  cursor: pointer;
  color: var(--c-text);
  font: inherit;
}
.user-btn:hover { background: var(--c-hover); }
.user-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.1; text-align: left; min-width: 0; }
.user-name {
  font-size: 13px; font-weight: 600;
  max-width: 140px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: var(--c-muted); text-transform: capitalize; }
.user-btn .chev svg { width: 14px; height: 14px; }

.user-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 200px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 70;
}
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--c-text);
  font-size: 13px; font-weight: 500;
}
.dropdown-item:hover { background: var(--c-hover); text-decoration: none; }
.dropdown-item.danger { color: var(--c-danger); }
.dropdown-item.danger:hover { background: var(--c-danger-bg); }

/* 8. Cards ----------------------------------------------------------------- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-md);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-header {
  display: flex; align-items: center; gap: 12px;
  margin: -4px 0 16px;
}
.card-header h2 { margin: 0; }
.card-header .actions { margin-left: auto; display: flex; gap: 8px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.kpi-card { padding: 18px; }
.kpi-label { font-size: 12px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--c-muted); margin-top: 2px; }

/* 9. Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: var(--r-input);
  font: inherit; font-weight: 500; font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-text);
  transition: background-color .12s, border-color .12s, color .12s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[disabled], .btn.is-loading { opacity: .6; cursor: not-allowed; }

.btn-primary {
  background: var(--c-primary); color: #fff;
  border-color: var(--c-primary);
}
.btn-primary:hover { background: var(--c-primary-h); border-color: var(--c-primary-h); }

.btn-secondary {
  background: var(--c-card); color: var(--c-text);
  border-color: var(--c-border-2);
}
.btn-secondary:hover { background: var(--c-hover); }

.btn-danger {
  background: var(--c-card); color: var(--c-danger);
  border-color: #fca5a5;
}
.btn-danger:hover { background: var(--c-danger-bg); }

.btn-ghost { color: var(--c-muted); }
.btn-ghost:hover { color: var(--c-text); background: var(--c-hover); }

/* WhatsApp-flavoured button used by /vouchers/_share_button.php. The brand
   green is WhatsApp's #25d366 — kept here so the partial doesn't have to
   carry inline styles. The text colour stays white in both states. */
.btn-success {
  background: #25d366; color: #fff;
  border-color: #1ebe5d;
}
.btn-success:hover { background: #1ebe5d; border-color: #16a34a; }

.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn-lg { min-height: 44px; padding: 10px 18px; font-size: 15px; }
.btn-block { display: flex; width: 100%; }

/* 10. Inputs / forms ------------------------------------------------------- */
/* Spec: 16px gap between form fields. */
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 180px; }
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--c-muted); margin-bottom: 4px; }
.required-mark { color: var(--c-danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  font: inherit; font-size: 14px;
  color: var(--c-text);
  background: var(--c-card);
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-input);
  transition: border-color .12s, box-shadow .12s;
}
.textarea { min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-link);
  box-shadow: var(--focus-ring);
}
.input[disabled], .select[disabled], .textarea[disabled],
.input[readonly] { background: var(--c-bg); color: var(--c-muted); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid {
  border-color: #fca5a5;
}
.field-error { color: var(--c-danger); font-size: 12px; margin-top: 4px; }
.field-help  { color: var(--c-muted);  font-size: 12px; margin-top: 4px; }

/* Checkbox / radio rows */
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check-row input[type=checkbox], .check-row input[type=radio] { accent-color: var(--c-link); }

/* 11. Tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--r-card); background: var(--c-card); }
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13.5px;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--c-border);
}
.table thead th {
  /* `top: 0` not var(--topbar-h): the .table-wrap has overflow-x:auto, so
     sticky positions against the wrap's own scroll context (not the viewport).
     A non-zero top would push the header row down by that amount inside the
     wrap, leaving an empty band above it on initial render. */
  position: sticky; top: 0;
  background: var(--c-card);
  font-weight: 600;
  color: var(--c-muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  z-index: 1;
}
.table tbody tr:nth-child(even) td { background: var(--c-zebra); }
.table tbody tr:hover td { background: #eef2ff; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; }
/* Long names (customer / party / branch) — truncate with full name on hover. */
.table .name-cell {
  max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Empty state */
.empty {
  padding: 36px 20px;
  text-align: center; color: var(--c-muted);
}

/* 12. Badges + pills ------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: 11.5px; font-weight: 600;
  border-radius: var(--r-pill);
  background: var(--c-bg);
  color: var(--c-muted);
  border: 1px solid var(--c-border);
}
.badge-success { background: var(--c-success-bg); color: var(--c-success); border-color: #a7f3d0; }
.badge-danger  { background: var(--c-danger-bg);  color: var(--c-danger);  border-color: #fca5a5; }
.badge-warn    { background: var(--c-warn-bg);    color: var(--c-warn);    border-color: #fcd34d; }
.badge-info    { background: #eff6ff; color: var(--c-link); border-color: #bfdbfe; }

/* 13. Alerts (inline) ------------------------------------------------------ */
.alert {
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
}
.alert-success { background: var(--c-success-bg); border-color: #a7f3d0; color: var(--c-success); }
.alert-danger  { background: var(--c-danger-bg);  border-color: #fca5a5; color: var(--c-danger); }
.alert-warn    { background: var(--c-warn-bg);    border-color: #fcd34d; color: var(--c-warn); }

/* 14. Toasts (overlay, top-right) ----------------------------------------- */
.toast-stack {
  position: fixed; top: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
  max-width: 360px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-link);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: toast-in .2s ease-out;
}
.toast-msg { flex: 1; }
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--c-muted); padding: 0; width: 18px; height: 18px;
  font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.toast-close:hover { color: var(--c-text); }
.toast.toast-success { border-left-color: var(--c-success); }
.toast.toast-error   { border-left-color: var(--c-danger); }
.toast.toast-warn    { border-left-color: var(--c-warn); }
@keyframes toast-in {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Inline flash banners (server-rendered) reuse alert visuals */
.flash {
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
}
.flash-success { background: var(--c-success-bg); color: var(--c-success); border-color: #a7f3d0; }
.flash-error   { background: var(--c-danger-bg);  color: var(--c-danger);  border-color: #fca5a5; }
.flash-warn    { background: var(--c-warn-bg);    color: var(--c-warn);    border-color: #fcd34d; }

/* 15. Modal dialogs -------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 90; padding: 20px;
}
.modal {
  background: var(--c-card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px;
  padding: 22px;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* 16. Utility classes ------------------------------------------------------ */
.row-flex { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-flex .spacer { flex: 1; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--c-muted); }
.mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* 17. Mobile responsiveness (<768px) -------------------------------------- */
@media (max-width: 767.98px) {
  :root { --content-pad: 16px; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }

  .main-col { margin-left: 0; }
  .topbar-menu { display: inline-flex; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; }

  /* ---------------------------------------------------------------
     Mobile fix: defeat inline `style="max-width:NNNpx"` on .field
     ---------------------------------------------------------------
     Many PHP pages (voucher list filters, voucher create/edit forms,
     report filters) write inline styles like:
         <div class="field" style="max-width:240px"> ... </div>
     Inline styles beat normal CSS rules, so on phones those fields
     stay narrow (170/200/240px) instead of stretching to full width.
     We can't easily refactor dozens of PHP files, so we override the
     inline value here. `!important` is REQUIRED specifically because
     of those inline `style=""` attributes — there is no other way to
     beat an inline style from a stylesheet. This rule is scoped
     inside the mobile media query, so it cannot affect desktop
     (>=768px) layout at all. */
  .field-row > .field,
  form[data-filter-form] .field,
  form[data-filter-form].field-row > .field {
    max-width: none !important;
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }
  /* Inline checkbox rows (e.g. "Show deleted", "Include deleted") use
     <label class="check-row"> in the markup. When they sit directly
     inside .field-row they should stay auto-width so the checkbox +
     label don't stretch awkwardly across the row. (When they're wrapped
     in <div class="field"> the .field stretches full-width — which is
     fine; the check-row inside still flows compactly.) */
  .field-row > label.check-row,
  .field-row > .check-row {
    width: auto !important;
    flex: 0 0 auto !important;
  }

  .btn { min-height: 44px; }   /* touch target */
  /* Bump primary mobile entry-point button to AAA touch target. */
  .icon-btn { width: 44px; height: 44px; }
  .nav-link { padding: 12px 12px; }

  .user-meta { display: none; } /* keep avatar only on small screens */

  /* Topbar global search is hidden on phones — there's not enough horizontal
     room for it next to the hamburger, page title, and user menu. Sidebar
     navigation already covers wayfinding on small screens. */
  .topbar-search { display: none; }
}

/* prefers-reduced-motion — kill non-essential animation/transition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 18. Print stylesheet ---------------------------------------------------- */
/* Pages render two layouts: the rich on-screen UI, and a hidden
   `.print-only` block carrying the bordered-grid voucher layout. On print
   we hide the screen UI and reveal `.print-only`. The print-only markup
   lives inside each view page so it can read the same PHP variables. */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .sidebar, .sidebar-overlay,
  .topbar, .toast-stack,
  .btn, .actions, .icon-btn,
  .user-menu, .nav,
  .skip-link,
  .no-print { display: none !important; }

  .main-col { margin-left: 0 !important; }
  .content  { padding: 0 !important; max-width: none !important; }

  /* Hide the rich on-screen voucher layout when a `.print-only` block is
     present (i.e. the new layout has been wired). The screen-side view
     content is wrapped in `.print-screen-only` for this purpose. */
  .print-screen-only { display: none !important; }

  /* Show the print-only block. */
  .print-only { display: block !important; color: #000 !important; }

  /* Card/table fallbacks for legacy view pages without `.print-only`. */
  .card { border: none !important; box-shadow: none !important; padding: 0 !important; background: #fff !important; }
  .table-wrap { border: none !important; overflow: visible !important; }
  .table thead th { background: #fff !important; color: #000 !important; }
  a { color: #000 !important; text-decoration: none !important; }

  /* ---- Bordered-grid voucher layout (used by .print-only block) ----
     Serif font + tight padding to match the Royal Wings reference receipt. */
  .print-only { font-family: 'DejaVu Serif', 'Times New Roman', 'Times', serif;
                font-size: 10pt; line-height: 1.25; }
  .print-only .lh-band { text-align: center; padding: 1mm 0; margin-bottom: 1mm; }
  .print-only .lh-name { font-size: 18pt; font-weight: 700; letter-spacing: 0.02em;
                          text-transform: uppercase; line-height: 1.05; }
  .print-only .lh-addr { font-size: 9.5pt; margin-top: 0.5mm; line-height: 1.2; }
  .print-only .lh-meta { font-size: 9pt;   margin-top: 0.5mm; letter-spacing: 0.01em; }
  .print-only .lh-meta .sep { display: inline-block; width: 5mm; }

  .print-only table.vtable {
    width: 100%; border-collapse: collapse; border: 1px solid #000;
    table-layout: fixed;
  }
  .print-only table.vtable td {
    border: 1px solid #000; padding: 5px 7px; vertical-align: top;
    word-wrap: break-word; font-size: 9.5pt;
  }
  .print-only table.vtable td.lbl {
    font-weight: normal; color: #000; font-size: 9.5pt;
    letter-spacing: 0; width: 18%; text-transform: uppercase;
  }
  .print-only table.vtable td.val { font-weight: 700; width: 32%; }
  .print-only table.vtable td.val .name-line { font-weight: 700; font-size: 10.5pt; }
  .print-only table.vtable td.val .sub { font-weight: normal; font-size: 8.5pt;
                                          margin-top: 0.5mm; color: #000; }

  .print-only .modes-row { width: 100%; border-collapse: collapse; }
  .print-only .modes-row td { border: none !important; padding: 0 6px 0 0;
                              font-size: 9.5pt; font-weight: normal;
                              white-space: nowrap; }

  .print-only .for-cell { height: 16mm; text-align: right; vertical-align: top;
                          font-size: 9.5pt; }
  .print-only .for-cell .for-line { font-weight: normal; text-transform: none;
                                    margin-bottom: 10mm; }
  .print-only .for-cell .sig { font-style: italic; font-size: 8.5pt; color: #000; }

  .print-only .amount-big   { font-size: 12pt; font-weight: 700; }
  .print-only .amount-words { font-style: italic; font-weight: normal; font-size: 9pt; }

  .print-only .notes-block { margin-top: 2mm; font-size: 8.5pt; line-height: 1.3;
                              page-break-inside: avoid; }
  .print-only .notes-block .note-head { font-weight: 700; margin-bottom: 0.5mm;
                                         font-size: 9pt; }
  .print-only .notes-block .note-line { font-style: italic; margin-bottom: 0.3mm; }
  .print-only .notes-block .note-line .glyph { display: inline-block; width: 5mm;
                                                 font-style: normal; }

  .print-only .print-stamp { margin-top: 1.5mm; font-size: 8pt; font-style: italic;
                              color: #000; }

  /* Items table for invoice print. */
  .print-only table.itable {
    width: 100%; border-collapse: collapse; border: 1px solid #000;
    margin-top: 2mm;
  }
  .print-only table.itable th, .print-only table.itable td {
    border: 1px solid #000; padding: 4px 6px; font-size: 9pt;
    vertical-align: top; word-wrap: break-word;
  }
  .print-only table.itable th { background: #f3f4f6 !important; text-align: left;
                                 font-weight: 700; text-transform: uppercase;
                                 font-size: 8.5pt; letter-spacing: 0.03em; }
  .print-only table.itable td.num,
  .print-only table.itable th.num { text-align: right; }

  .print-only table.totals-table { width: 100%; border-collapse: collapse;
                                    border: 1px solid #000; }
  .print-only table.totals-table td { border: 1px solid #000; padding: 4px 6px;
                                       font-size: 9.5pt; }
  .print-only table.totals-table tr.grand td { font-size: 11pt; font-weight: 700;
                                                 background: #f3f4f6 !important; }

  .print-only .muted { color: #4b5563 !important; }
  .print-only .mono  { font-family: 'DejaVu Sans Mono', Menlo, Consolas, monospace; }

  .print-only .inv-title-band {
    border-top: 1px solid #000; border-bottom: 1px solid #000;
    padding: 2mm 0; text-align: center; font-weight: 700; font-size: 13pt;
    letter-spacing: 0.08em; margin: 1mm 0 2mm 0;
  }

  /* Default page size = half-A4 landscape (210mm x 148mm) — receipts fit
     compactly. Invoice view injects an inline <style> override that
     restores A4 portrait, so this default doesn't break invoice prints. */
  @page { size: 210mm 148mm; margin: 6mm 8mm; }
}

/* On screen: hide the print-only block. */
@media screen {
  .print-only { display: none !important; }
}

/* =============================================================================
   19. Mobile + PWA polish (added — do not remove or refactor earlier rules)
   -----------------------------------------------------------------------------
   This section was appended after the original theme to:
     - Respect iPhone notches and the iOS home-indicator (safe-area insets).
     - Tweak layout when launched as an installed PWA (display-mode: standalone).
     - Fix the voucher-list filter forms on medium-width viewports.
       The filter forms use inline `max-width:170px` on each .field — those
       inline styles win over normal CSS, so we use !important + a scoping
       attribute (data-filter-form) so we don't accidentally restyle other
       field-rows on the page.
     - Make tap-targets >= 44px on phones.
     - Stop iOS auto-zoom on focused inputs (font-size < 16px triggers it).
   ========================================================================= */

/* PWA / safe-area: respect notches + iOS home indicator */
:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
}
body { padding-bottom: var(--safe-bottom); }
.topbar { padding-top: var(--safe-top); padding-left: max(16px, var(--safe-left)); padding-right: max(16px, var(--safe-right)); }
.sidebar { padding-bottom: var(--safe-bottom); }

/* Standalone-mode tweaks (when launched as installed PWA) */
@media all and (display-mode: standalone) {
  /* slightly more padding so the topbar doesn't feel jammed against the
     status bar on devices without a notch */
  .topbar { min-height: calc(var(--topbar-h) + var(--safe-top)); }
}

/* Filter-card layout fix:
   The voucher-list filter forms use inline `max-width:170px` on each field.
   On medium-width viewports those max-widths cause weird wrapping (the user
   reported a screenshot showing inputs stacking right-side only). Override
   the inline max-widths on smaller screens so fields flow into 2 columns,
   then 1 column on phones.

   Scope the override to forms that opt-in via `data-filter-form` so we
   don't accidentally over-style other field-rows. Two shapes are supported:
     1. <form data-filter-form class="card"> ... <div class="field-row"> ... </div> </form>
        (voucher list pages)
     2. <form data-filter-form class="field-row"> ... </form>
        (report pages — the form itself IS the row)
*/
@media (max-width: 1024px) {
  form[data-filter-form] .field-row > .field,
  form[data-filter-form].field-row > .field { min-width: 220px; }
}
@media (max-width: 640px) {
  form[data-filter-form] .field-row,
  form[data-filter-form].field-row { flex-direction: column; gap: 10px; }
  form[data-filter-form] .field-row > .field,
  form[data-filter-form].field-row > .field {
    max-width: none !important;
    width: 100%;
  }
  form[data-filter-form] .field-row > .field button[type="submit"],
  form[data-filter-form].field-row > .field button[type="submit"],
  form[data-filter-form] .field-row > button[type="submit"],
  form[data-filter-form].field-row > button[type="submit"] {
    width: 100%;
  }
}

/* Mobile touch targets — make sure tap-able controls are >= 44px on phones */
@media (max-width: 640px) {
  .btn, .btn-sm, .icon-btn, a.btn { min-height: 44px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* Tap highlight is jarring on dark btn-primary */
.btn { -webkit-tap-highlight-color: transparent; }

/* Avoid iOS auto-zoom on focused inputs (font-size < 16px causes zoom) */
.input, .select, .textarea { font-size: 16px; }
@media (min-width: 768px) {
  .input, .select, .textarea { font-size: 14px; }
}

/* ---------------------------------------------------------------------------
 * "Send via WhatsApp" share dialog (rendered by /vouchers/_share_button.php)
 * ---------------------------------------------------------------------------
 * Native <dialog> styling. We only override the backdrop look + the open-state
 * positioning so the modal sits centered with a soft dim behind it. The
 * inner form is laid out with inline styles in the partial so it works even
 * when this CSS rule has not yet shipped.
 */
.share-dialog {
  background: var(--c-card, #fff);
  color: var(--c-text, #0f172a);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .25), 0 4px 12px rgba(15, 23, 42, .08);
}
.share-dialog::backdrop {
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(2px);
}
/* Old browsers without ::backdrop fall back to the open-state itself. */
.share-dialog[open] {
  position: fixed;
  inset: 0;
  margin: auto;
}

/* === Topbar search modernization ===========================================
 * The topbar search input previously inherited the global .input style
 * (flat white box, grey border) which felt out of place in the translucent
 * topbar. This block gives it a modern, "soft inset" pill look:
 *   - Light-grey resting background, no visible border (transparent border
 *     keeps the box-model identical so the focus state doesn't jump).
 *   - Inline magnifying-glass SVG as a background-image (no extra DOM, no
 *     icon font dependency, monochrome muted-grey).
 *   - On focus the input becomes white, picks up the brand link-blue border
 *     and the standard --focus-ring so accessibility is preserved.
 * Pill radius (999px) was chosen over 12px because the topbar is a thin
 * horizontal strip — pill shape reads as a "search field" at a glance and
 * matches the .user-btn pill on the same row, giving the topbar a unified
 * silhouette.
 * On phones (<768px) the search is hidden — see the rule appended inside
 * the existing mobile @media block (search for ".topbar-search { display:
 * none; }"). The topbar has no room for it next to the hamburger + title.
 * ========================================================================= */
.topbar-search {
  position: relative;
  min-width: 200px;
  max-width: 360px;
  flex: 1;
}
.topbar-search input[type="search"] {
  width: 100%;
  /* 38px left-padding leaves room for the magnifying-glass icon below. */
  padding: 8px 14px 8px 38px;
  font: inherit;
  font-size: 14px;
  color: var(--c-text);
  background-color: #f3f4f6;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 16px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.topbar-search input[type="search"]:hover {
  background-color: #e5e7eb;
}
.topbar-search input[type="search"]:focus {
  background-color: #ffffff;
  border-color: var(--c-link);
  box-shadow: var(--focus-ring);
  outline: none;
}
/* Strip the WebKit/Chromium native "x" cancel button — looks janky next to
 * the rounded pill shape and the user can simply select-all + delete. */
.topbar-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}
/* Results dropdown — already has its own positioning in header.php's inline
 * styles; we only ensure it sits cleanly under the new pill input. */
.topbar-search-results {
  top: calc(100% + 4px);
  left: 0;
  right: 0;
}

/* === Invoice items table compact inputs ====================================
 * The invoice items table (#invoice-items-table) has narrow columns
 * (Disc 90px, GST% 80px, Qty 70px) but the inputs inherit the global
 * .input rule (min-height 38px, padding 8px 12px, font-size 16px on mobile)
 * which made small numeric values look oversized and clipped in the user's
 * screenshot. This block scopes a tighter sizing strictly to that table —
 * the global .input rule is untouched so every other form keeps its
 * comfortable default sizing.
 *
 * Note on font-size 13px on mobile: dropping below 16px usually triggers
 * iOS focus-zoom. Acceptable here because the table forces horizontal
 * scroll at min-width:1300px on phones — the user is already in zoomed/
 * panning mode for this table, and legibility of the typed value beats
 * preventing one extra tap-zoom event.
 * ========================================================================= */
#invoice-items-table tbody td .input,
#invoice-items-table tbody td .select {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.3;
  border-radius: 6px;
}
#invoice-items-table tbody td {
  padding: 6px 6px;
  vertical-align: top;
}
#invoice-items-table thead th {
  padding: 6px 6px;
  font-size: 12px;
}
/* Numeric cells (Qty, Rate, Disc, GST%, Amount) carry class="input num" —
 * keep them right-aligned so digits column-stack neatly inside narrow cells. */
#invoice-items-table tbody td .input.num {
  text-align: right;
}

/* === Customer Search Autocomplete ===
 * Styles for the searchable customer picker that replaces the plain <select
 * id="customer_id"> dropdown across vouchers and reports. The widget renders
 * a text input with an absolutely-positioned dropdown panel beneath. Tokens
 * (var(--c-...)) reuse the design system declared at the top of this file
 * so light/dark / future theme tweaks propagate without edits here.
 *
 * Layout note: the wrap is position:relative so the panel can absolutely
 * position against it. The panel sits ABOVE following form rows (z-index)
 * but does NOT trap pointer events outside its bounds.
 * --------------------------------------------------------------------- */
.cs-wrap {
  position: relative;
  width: 100%;
}

/* The text input piggybacks on the existing .input rule for sizing/colours.
 * We just leave room on the right for the (✕) clear button so its X never
 * sits over typed text. */
.cs-wrap .cs-input {
  width: 100%;
  padding-right: 36px;
}

/* (✕) clear button — only shown after a customer is picked. Floats inside
 * the input's right edge using absolute positioning. tabIndex = -1 in JS
 * keeps it out of the keyboard flow; the input itself is the focus target. */
.cs-wrap .cs-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: 0;
  background: transparent;
  color: var(--c-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
}
.cs-wrap .cs-clear:hover {
  background: var(--c-hover);
  color: var(--c-text);
}
.cs-wrap .cs-clear:focus {
  outline: 2px solid var(--c-link);
  outline-offset: 1px;
}

/* The dropdown panel. z-index is high enough to clear cards / sticky bars
 * but low enough to stay below modals (which use z-index: 9999). */
.cs-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1500;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--c-card);
  border: 1px solid var(--c-border-2);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
  max-height: 280px;
  overflow-y: auto;
}
.cs-panel[hidden] {
  display: none;
}

/* Each row. Two-line layout: bold name on top, muted phone+GSTIN below. */
.cs-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--c-border);
  line-height: 1.35;
}
.cs-item:last-child {
  border-bottom: 0;
}
.cs-item:hover,
.cs-item.is-active {
  background: var(--c-hover);
}

.cs-item-name {
  font-weight: 600;
  color: var(--c-text);
  font-size: 14px;
}
.cs-item-meta {
  color: var(--c-muted);
  font-size: 12px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* Empty / loading / error states share .cs-empty for the muted look. */
.cs-empty {
  padding: 10px 12px;
  color: var(--c-muted);
  font-size: 13px;
  text-align: center;
  font-style: italic;
}
.cs-empty.cs-error {
  color: var(--c-danger);
  font-style: normal;
}
.cs-empty.cs-loading {
  font-style: normal;
}

/* Mobile tweak: bump tap target heights inside the panel so each row is
 * easy to hit without precision. The input itself already inherits the
 * mobile-friendly .input sizing higher up in this stylesheet. */
@media (max-width: 640px) {
  .cs-panel { max-height: 60vh; }
  .cs-item  { padding: 10px 12px; }
}
