/* =============================================================
   ERP Cloud 365 — Professional Polish (loaded after style.css)
   ============================================================= */

/* -------- Status badges -------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge i { font-size: 0.7rem; }

.badge-success { background: var(--success-soft); color: var(--success); border-color: rgba(16, 185, 129, 0.25); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, 0.25); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(245, 158, 11, 0.25); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: rgba(14, 165, 233, 0.25); }
.badge-neutral { background: var(--surface-2);    color: var(--fg-muted); border-color: var(--hairline); }

/* Voided rows: faded + strikethrough on the invoice number to make scan-skipping fast */
.row-voided td { opacity: 0.62; }
.row-voided td:nth-child(3) strong,
.row-voided td:nth-child(4) strong { text-decoration: line-through; text-decoration-color: var(--danger); }

/* -------- Sticky table headers (opt-in via .sticky-thead) -------- */
table.sticky-thead thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-elevated);
    box-shadow: 0 1px 0 var(--hairline);
}

/* Sortable column headers */
table.sortable thead th[data-sort] {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
}
table.sortable thead th[data-sort]:hover-disabled { background: var(--surface-2); }
table.sortable thead th[data-sort]::after {
    content: '↕';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.35;
    font-size: 0.85em;
}
table.sortable thead th[data-sort].sort-asc::after  { content: '↑'; opacity: 1; color: var(--accent); }
table.sortable thead th[data-sort].sort-desc::after { content: '↓'; opacity: 1; color: var(--accent); }

/* Density toggle */
table.compact thead th, table.compact tbody td { padding-top: 0.35rem; padding-bottom: 0.35rem; font-size: 0.86rem; }

/* Pager (used by sales/purchase) */
.pager { border-top: 1px solid var(--hairline); }
.pager .btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* -------- Empty states with CTA -------- */
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--fg-muted); }
.empty-state i { font-size: 2.2rem; opacity: 0.35; display: block; margin-bottom: 0.6rem; color: var(--fg-faint); }
.empty-state p { margin: 0 0 1rem 0; font-size: 0.95rem; }
.empty-state .btn { margin: 0 auto; }

/* -------- Sub-tabs (used inside a page to switch between sections) -------- */
.subtabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--hairline);
    overflow-x: auto;
    scrollbar-width: thin;
}
.subtab {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    color: var(--fg-muted);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
    font-family: inherit;
    white-space: nowrap;
    margin-bottom: -1px;
}
.subtab:hover-disabled { color: var(--fg); background: var(--accent-soft); }
.subtab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.subtab i { font-size: 0.85rem; }

/* -------- Combobox keyboard-active highlight --------
   Up/Down arrows mark the focused option with .combobox-active. Make it
   visually distinct from plain :hover-disabled so keyboard users always see where
   their cursor is. */
.combobox-option.combobox-active,
.combobox-create.combobox-active {
    background: var(--accent) !important;
    color: white !important;
    outline: none;
}
.combobox-option.combobox-active strong,
.combobox-create.combobox-active strong { color: white !important; }

/* The combobox host needs to be a positioning context so the floating
   dropdown lands relative to its input, not the page root. */
.voucher-combobox {
    position: relative;
}

.combobox-dropdown {
    /* Float over the next voucher-card instead of being clipped under it.
       The old rule only set max-height; with .voucher-card carrying a
       backdrop-filter (which creates a new stacking context), a non-positioned
       dropdown could not paint above the subsequent card. */
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--surface-1, var(--bg-elevated, #ffffff));
    border: 1px solid var(--surface-3, var(--hairline, rgba(15, 23, 42, 0.08)));
    border-radius: var(--radius-sm, 8px);
    box-shadow: 0 12px 28px -6px rgba(15, 23, 42, 0.18), 0 4px 8px -4px rgba(15, 23, 42, 0.10);
    /* Allow scroll when there are many options so keyboard nav can reach them. */
    max-height: 280px;
    overflow-y: auto;
}
.combobox-dropdown[hidden] { display: none; }

/* When any combobox inside a card is focused / open, escape that card's
   stacking context above the following ones so the dropdown wins z-order
   even when sibling cards have their own (backdrop-filter / transform). */
.voucher-card:focus-within {
    position: relative;
    z-index: 10;
}

/* Individual option rows inside the dropdown — keep the look consistent with
   the rest of the form. The .combobox-active state is already styled in this
   file (purple highlight); these rules just provide the default padding/hover
   so options no longer render as raw unstyled text when the dropdown floats. */
.combobox-option,
.combobox-create,
.combobox-empty {
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
    color: var(--text-main, var(--fg, #0f172a));
    cursor: pointer;
    line-height: 1.3;
    border-bottom: 1px solid var(--surface-2, var(--bg-soft, #f1f5f9));
}
.combobox-option:last-child,
.combobox-create:last-child { border-bottom: none; }
.combobox-option:hover,
.combobox-create:hover {
    background: var(--surface-2, var(--bg-soft, #f1f5f9));
}
.combobox-empty {
    color: var(--text-muted, var(--fg-muted, #475569));
    cursor: default;
    font-style: italic;
}

/* -------- Skip-to-content link (visible on keyboard focus) -------- */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: white;
    padding: 0.75rem 1.25rem;
    z-index: 10000;
    font-weight: 600;
    border-radius: 0 0 var(--radius-sm) 0;
    text-decoration: none;
}
.skip-link:focus {
    left: 0;
    outline: 3px solid var(--warning);
    outline-offset: 2px;
}

/* -------- Filter chips (used in reports toolbar) -------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.32rem 0.7rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    color: var(--fg-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    font-family: inherit;
    line-height: 1;
}
.chip:hover-disabled { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.chip i { font-size: 0.78rem; }
.chip-load {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 1.5rem;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 0.85rem) 50%, calc(100% - 0.55rem) 50%;
    background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
    background-repeat: no-repeat;
}

/* -------- Sidebar Quick-search button (Cmd+K trigger) -------- */
.cmdk-trigger {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 1rem;
    color: var(--sidebar-muted);
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    margin: 0.15rem 0.5rem;
    transition: background var(--transition), color var(--transition);
    font-family: inherit;
    cursor: pointer;
    list-style: none;
    /* Prevent overflow into the main content when the sidebar collapses
       — the icon stays visible, the rest is hidden via :is() rule below. */
    overflow: hidden;
    white-space: nowrap;
}
.cmdk-trigger:hover-disabled { background: var(--sidebar-active); color: var(--sidebar-fg); }
.cmdk-trigger .kbd {
    font-size: 0.68rem;
    padding: 0.12rem 0.4rem;
    border: 1px solid var(--hairline-strong);
    border-radius: 4px;
    color: var(--sidebar-muted);
    background: var(--surface-2);
    font-family: ui-monospace, monospace;
}

/* When the sidebar collapses, hide the label and the keyboard-hint chip and
   center the icon — same behaviour the original .nav-item rules apply. */
body.sidebar-collapsed .cmdk-trigger {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0.25rem;
    margin-right: 0.25rem;
}
body.sidebar-collapsed .cmdk-trigger > span,
body.sidebar-collapsed .cmdk-trigger .kbd {
    display: none;
}

/* -------- Toast container — accessibility -------- */
#toast-container { pointer-events: none; }
#toast-container .toast { pointer-events: auto; }

/* Live region for screen readers — visible for sighted users via toast container */
.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;
}

/* -------- Command Palette (Cmd+K / Ctrl+K) -------- */
.cmdk-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 12vh;
    animation: cmdk-fade-in 120ms ease;
}
@keyframes cmdk-fade-in { from { opacity: 0; } to { opacity: 1; } }

.cmdk-panel {
    width: min(640px, 92vw);
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    border: 1px solid var(--hairline);
    animation: cmdk-slide-in 180ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes cmdk-slide-in {
    from { transform: translateY(-12px) scale(0.98); opacity: 0; }
    to   { transform: translateY(0)     scale(1);    opacity: 1; }
}

.cmdk-input-row {
    display: flex;
    align-items: center;
    padding: 0.85rem 1rem;
    gap: 0.65rem;
    border-bottom: 1px solid var(--hairline);
}
.cmdk-input-row i { color: var(--fg-faint); }
.cmdk-input-row input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    color: var(--fg);
    font-family: inherit;
}
.cmdk-input-row .kbd {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--hairline-strong);
    border-radius: 4px;
    color: var(--fg-muted);
    background: var(--surface-2);
    font-family: ui-monospace, monospace;
}

.cmdk-results { max-height: 50vh; overflow-y: auto; padding: 0.4rem; }
.cmdk-group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
    padding: 0.6rem 0.75rem 0.3rem;
    font-weight: 600;
}
.cmdk-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--fg);
    font-size: 0.92rem;
}
.cmdk-item:hover-disabled, .cmdk-item.cmdk-active {
    background: var(--accent-soft);
    color: var(--accent);
}
.cmdk-item i { width: 1.1rem; opacity: 0.7; }
.cmdk-empty { padding: 1.5rem; text-align: center; color: var(--fg-faint); }

/* -------- Modal focus visible -------- */
.modal :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* -------- Voucher form: highlighted active row + dirty indicator -------- */
.voucher-line:focus-within { background: var(--accent-soft); }

.dirty-indicator {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--warning);
    margin-left: 0.5rem;
    box-shadow: 0 0 0 3px var(--warning-soft);
    vertical-align: middle;
}

/* -------- Dashboard widgets -------- */
.kpi-card {
    position: relative;
    padding: 1.1rem 1.2rem;
    background: var(--bg-elevated);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover-disabled { box-shadow: var(--shadow); }
.kpi-card .kpi-label {
    font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--fg-muted); font-weight: 600;
}
.kpi-card .kpi-value {
    display: block; font-size: 1.55rem; font-weight: 700;
    color: var(--fg); margin-top: 0.4rem; line-height: 1.15;
}
.kpi-card .kpi-trend {
    display: inline-flex; align-items: center; gap: 0.25rem;
    font-size: 0.78rem; font-weight: 600; margin-top: 0.45rem;
    padding: 0.18rem 0.5rem; border-radius: 999px;
}
.kpi-card .kpi-trend.up   { color: var(--success); background: var(--success-soft); }
.kpi-card .kpi-trend.down { color: var(--danger);  background: var(--danger-soft); }
.kpi-card .kpi-trend.flat { color: var(--fg-muted); background: var(--surface-2); }

.aging-bar {
    display: flex;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-2);
    margin-top: 0.5rem;
}
.aging-bar > span {
    display: block; height: 100%;
    transition: width 400ms ease;
}
.aging-bar > .aging-current { background: var(--success); }
.aging-bar > .aging-30      { background: var(--info); }
.aging-bar > .aging-60      { background: var(--warning); }
.aging-bar > .aging-90      { background: var(--danger); }

.aging-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.5rem;
    font-size: 0.78rem;
    margin-top: 0.65rem;
    color: var(--fg-muted);
}
.aging-legend > div { display: flex; align-items: center; gap: 0.35rem; }
.aging-legend .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }

/* -------- DARK THEME — proper token overrides -------- */
[data-theme="dark"] {
    --bg:           #0b1020;
    --bg-elevated:  #11172b;
    --bg-soft:      #0f1426;
    --surface:      rgba(17, 23, 43, 0.95);
    --surface-2:    #1a2238;
    --hairline:     rgba(255, 255, 255, 0.08);
    --hairline-strong: rgba(255, 255, 255, 0.16);

    --fg:        #e2e8f0;
    --fg-muted:  #94a3b8;
    --fg-faint:  #64748b;

    --sidebar-bg:     #0d1326;
    --sidebar-fg:     #e2e8f0;
    --sidebar-muted:  #94a3b8;
    --sidebar-faint:  #64748b;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-active: #1a2238;
    --logo-gradient:  linear-gradient(90deg, #e2e8f0 30%, var(--brand-2));

    --header-bg:     #0d1326;
    --header-fg:     #e2e8f0;
    --header-muted:  #94a3b8;
    --header-border: rgba(255, 255, 255, 0.08);

    --accent-soft:   rgba(99, 102, 241, 0.18);
    --success-soft:  rgba(16, 185, 129, 0.18);
    --danger-soft:   rgba(239, 68, 68, 0.18);
    --warning-soft:  rgba(245, 158, 11, 0.18);
    --info-soft:     rgba(14, 165, 233, 0.18);

    --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
    --shadow:     0 8px 24px rgba(0, 0, 0, 0.32);
    --shadow-lg:  0 24px 48px -12px rgba(0, 0, 0, 0.55);

    --glass-bg:     rgba(17, 23, 43, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
}

/* Tweaks needed because some component CSS still uses literal colors instead of tokens */
[data-theme="dark"] body                    { background: var(--bg); color: var(--fg); }
[data-theme="dark"] .card,
[data-theme="dark"] .modal,
[data-theme="dark"] .stat-card              { background: var(--bg-elevated); color: var(--fg); border-color: var(--hairline); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea                { background: var(--bg-soft); color: var(--fg); border-color: var(--hairline-strong); }
[data-theme="dark"] table                   { color: var(--fg); }
[data-theme="dark"] table thead th          { background: var(--surface-2); color: var(--fg-muted); border-color: var(--hairline); }
[data-theme="dark"] table tbody tr          { border-color: var(--hairline); }
[data-theme="dark"] table tbody tr:hover-disabled    { background: var(--surface-2); }
[data-theme="dark"] .btn-ghost              { color: var(--fg); }
[data-theme="dark"] .muted                  { color: var(--fg-muted); }
[data-theme="dark"] .login-shell            { background: var(--bg); }
[data-theme="dark"] .modal-backdrop         { background: rgba(0, 0, 0, 0.55); }

/* Sticky thead in dark mode needs the elevated background to actually hide rows behind */
[data-theme="dark"] table.sticky-thead thead th { background: var(--bg-elevated); }

/* -------- Premium UI Enhancements -------- */
:root {
    --brand-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --surface-glass: rgba(255, 255, 255, 0.7);
    --blur-val: 10px;
}
[data-theme="dark"] {
    --surface-glass: rgba(17, 23, 43, 0.7);
}

/* Glassmorphism & Micro-animations for Voucher Cards */
.voucher-card {
    background: var(--surface-glass) !important;
    backdrop-filter: blur(var(--blur-val));
    -webkit-backdrop-filter: blur(var(--blur-val));
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.voucher-card:hover-disabled {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

/* Modern Inputs with Glow */
.voucher-input, .voucher-select, .voucher-textarea {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.voucher-input:focus, .voucher-select:focus, .voucher-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
    outline: none;
}

/* Inline form validation marker — added by JS via setFieldError() when a
   required field is empty or malformed. Pairs with a .field-err message
   element appended below the input. */
.input-error,
input.input-error,
select.input-error,
textarea.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18) !important;
}

/* Brand wordmark — never translated, never RTL-flipped. The font-feature-
   settings disable the OpenType `nalt` (national alternates) feature so the
   "365" digits don't get substituted with Arabic-Indic numerals (٣٦٥) when
   the document is in RTL/Arabic locale. */
.brand-wordmark {
    unicode-bidi: isolate;
    direction: ltr;
    font-feature-settings: "nalt" 0, "locl" 0;
    font-variant-numeric: lining-nums;
}

/* Western Arabic digits in user-data fields and table cells must not be
   substituted with Eastern Arabic digits in Arabic locale. A branch named
   "ERP Cloud 365" or a TRN like "100123456700003" should render exactly as
   the user typed it. Pre-localized values from toLocaleString already use
   the correct Unicode codepoints, so this rule doesn't affect them. */
html[lang="ar"] body {
    font-feature-settings: "nalt" 0;
}
.preserve-digits,
.simple-table td .preserve-digits {
    font-feature-settings: "nalt" 0, "locl" 0;
    font-variant-numeric: lining-nums;
}

/* --------------------------------------------------------------
   Company Setup — top-tab wizard layout
   -------------------------------------------------------------- */
.setup-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.5rem 0 2rem;
}
.setup-progress {
    background: var(--surface-1, #fff);
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 12px;
    padding: 0.85rem 1.1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.setup-progress-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 0.6rem;
}
.setup-step-label strong { color: var(--text-main, #0f172a); }
.setup-progress-count {
    margin-left: auto;
    font-weight: 600;
    color: var(--success, #10b981);
}
.setup-progress-bar {
    height: 6px;
    background: var(--surface-2, #f1f5f9);
    border-radius: 999px;
    overflow: hidden;
}
.setup-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand-1, #6366f1), var(--success, #10b981));
    border-radius: 999px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.setup-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--surface-1, #fff);
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 12px;
    padding: 0.35rem;
    margin-bottom: 1.25rem;
    overflow-x: auto;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    position: sticky;
    top: 0;
    z-index: 5;
}
.setup-tab {
    flex: 1 1 auto;
    min-width: 130px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 0.9rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted, #64748b);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}
.setup-tab:hover-disabled {
    background: var(--surface-2, #f1f5f9);
    color: var(--text-main, #0f172a);
}
.setup-tab.active {
    background: var(--brand-soft, rgba(99, 102, 241, 0.1));
    color: var(--brand-1, #6366f1);
    border-color: var(--brand-1, #6366f1);
}
.setup-tab-icon { font-size: 0.95rem; }
.setup-tab-check {
    color: var(--success, #10b981);
    font-size: 0.85rem;
    margin-left: 0.15rem;
}
.setup-tab.active .setup-tab-check { color: var(--success, #10b981); }

.setup-pane { min-height: 240px; }

.setup-card {
    background: var(--surface-1, #fff);
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 14px;
    padding: 1.5rem 1.75rem;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
    margin-bottom: 1rem;
}
.setup-card-header {
    margin: -0.25rem 0 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--hairline, rgba(15, 23, 42, 0.06));
}
.setup-card-header h3 {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main, #0f172a);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.setup-card-header h3 i { color: var(--brand-1, #6366f1); }
.setup-card-header .muted { margin: 0; }

.setup-section-h {
    margin: 1.75rem 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--text-main, #0f172a);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.setup-section-h:first-of-type { margin-top: 0; }
.setup-section-h i { color: var(--brand-1, #6366f1); }
.setup-section-meta {
    margin: 0 0 1rem;
    font-size: 0.8rem;
    color: var(--text-muted, #64748b);
}

/* Form layout used inside setup-card: 2-column auto-fit grid with .full
   spanning the entire row. Previously these classes were undeclared and
   forms rendered with browser-default sizing — adding them here gives the
   setup forms the "professional" look the requirements call for. */
.setup-card .form-grid,
.designer-form-inner .form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.25rem;
    align-items: start;
}
.setup-card .form-grid > .voucher-field.full,
.designer-form-inner .form-grid > .voucher-field.full { grid-column: 1 / -1; }
@media (max-width: 640px) {
    .setup-card .form-grid,
    .designer-form-inner .form-grid { grid-template-columns: 1fr; }
}

/* Default styling for `.input` (text inputs, selects, textareas marked with
   class="input"). Previously this class was used in markup but never defined
   in CSS, so inputs fell back to browser defaults. */
.setup-card .input,
.setup-card input.input,
.setup-card select.input,
.setup-card textarea.input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.12));
    border-radius: 8px;
    background: var(--surface-1, #fff);
    color: var(--text-main, #0f172a);
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.setup-card .input:focus,
.setup-card input.input:focus,
.setup-card select.input:focus,
.setup-card textarea.input:focus {
    outline: none;
    border-color: var(--brand-1, #6366f1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.setup-card textarea.input { min-height: 80px; resize: vertical; }
.setup-card .voucher-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main, #0f172a);
    margin-bottom: 0.35rem;
    display: block;
}

.setup-subsection {
    margin-top: 1.75rem;
}
.setup-subsection-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.setup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--hairline, rgba(15, 23, 42, 0.06));
}

.setup-card--prompt {
    text-align: center;
    padding: 2.75rem 1.5rem;
}
.setup-prompt-icon {
    font-size: 2.75rem;
    color: var(--brand-1, #6366f1);
    margin-bottom: 1rem;
    display: block;
}
.setup-card--prompt h3 {
    font-size: 1.35rem;
    margin: 0 0 0.5rem;
    color: var(--text-main, #0f172a);
}
.setup-prompt-actions {
    display: inline-flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.req { color: var(--danger, #ef4444); }

.branding-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}
.brand-item { text-align: center; }
.brand-item > label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-main, #0f172a);
}
.brand-preview-box {
    height: 140px;
    border: 2px dashed var(--hairline, rgba(15, 23, 42, 0.12));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2, #f8fafc);
    overflow: hidden;
}
.brand-preview-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.brand-preview-box i {
    font-size: 2rem;
    color: var(--text-faint, #94a3b8);
}
/* Empty-state preview: nothing uploaded yet. Render a clean blank box so the
   user can see immediately that no logo is set — never substitute the
   bundled ERP Cloud 365 site logo. */
.brand-preview-box.is-empty {
    background: repeating-linear-gradient(
        45deg,
        var(--surface-2, #f8fafc),
        var(--surface-2, #f8fafc) 8px,
        rgba(15, 23, 42, 0.03) 8px,
        rgba(15, 23, 42, 0.03) 16px
    );
}
.brand-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    justify-content: center;
}
/* Help text under each brand preview — clarifies whether the company has
   uploaded a custom asset or whether we're showing the site default. */
.brand-hint {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}
.brand-hint i { color: var(--brand-1, #6366f1); }
/* Sidebar logo — defensive size lock in case the bundled site logo is ever
   swapped for an unusually-shaped image. */
.sidebar .logo img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex-shrink: 0;
}

@media (max-width: 720px) {
    .setup-shell { padding: 0.25rem 0 1.5rem; }
    .setup-card { padding: 1.1rem 1rem; }
    .setup-tab-label { display: none; }
    .setup-tab { min-width: auto; }
    .setup-tab.active .setup-tab-label { display: inline; }
}

/* --------------------------------------------------------------
   Document Template Designer
   -------------------------------------------------------------- */
.designer-shell {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0.5rem 0 2rem;
}
.designer-tabs {
    display: flex;
    gap: 0.35rem;
    background: var(--surface-1, #fff);
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 12px;
    padding: 0.35rem;
    margin-bottom: 1.25rem;
    overflow-x: auto;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    position: sticky;
    top: 0;
    z-index: 5;
}
.designer-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted, #64748b);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}
.designer-tab:hover-disabled {
    background: var(--surface-2, #f1f5f9);
    color: var(--text-main, #0f172a);
}
.designer-tab.active {
    background: var(--brand-soft, rgba(99, 102, 241, 0.1));
    color: var(--brand-1, #6366f1);
    border-color: var(--brand-1, #6366f1);
}
/* Tiny color chip on each tab — previews the document's primary_color so
   admins can spot at-a-glance which doc type they're editing. */
.designer-tab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08) inset;
}

.designer-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 1100px) {
    .designer-grid { grid-template-columns: 1fr; }
}

.designer-form { min-width: 0; }

/* Purpose-built form header (replaces the shared setup-card-header, whose flex
   title + inline icon overlapped the subtitle here). Icon chip + title/subtitle
   stack, cleanly aligned. */
.designer-form-head {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    margin-bottom: 1.1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--hairline, rgba(15, 23, 42, 0.07));
}
.designer-form-head .dfh-icon {
    width: 2.4rem; height: 2.4rem;
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px;
    background: var(--brand-soft, rgba(99, 102, 241, 0.1));
    color: var(--brand-1, #6366f1);
    font-size: 1rem;
}
.designer-form-head .dfh-text { min-width: 0; }
.designer-form-head h3 {
    margin: 0 0 0.15rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main, #0f172a);
    line-height: 1.25;
}
.designer-form-head p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
    line-height: 1.4;
}

.designer-check {
    display: inline-flex !important;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    font-weight: 500 !important;
    color: var(--text-main, #0f172a) !important;
}
.designer-check input { width: 1rem; height: 1rem; cursor: pointer; }

/* "No print yet" badge on tabs whose print isn't implemented. */
.designer-tab-badge {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--warning, #b45309);
    background: rgba(180, 83, 9, 0.12);
    border-radius: 999px;
    padding: 0.1rem 0.4rem;
    line-height: 1;
}

/* Banner shown above the form when the active doc type has no print yet. */
.designer-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    background: rgba(180, 83, 9, 0.08);
    border: 1px solid rgba(180, 83, 9, 0.25);
    color: var(--text-main, #0f172a);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    line-height: 1.45;
}
.designer-notice i { color: var(--warning, #b45309); margin-top: 0.15rem; }

/* Accordion sections inside the designer form. Native <details> for built-in
   accessibility + keyboard support; styled to match the app's card system. */
.designer-acc {
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 12px;
    background: var(--surface-1, #fff);
    margin-bottom: 0.85rem;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}
.designer-acc > summary {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.9rem 1.1rem;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main, #0f172a);
    list-style: none;
    user-select: none;
}
.designer-acc > summary::-webkit-details-marker { display: none; }
.designer-acc > summary .acc-icon {
    width: 1.6rem; height: 1.6rem;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px;
    background: var(--brand-soft, rgba(99, 102, 241, 0.1));
    color: var(--brand-1, #6366f1);
    font-size: 0.8rem;
    flex-shrink: 0;
}
.designer-acc > summary .acc-meta {
    margin-left: auto;
    font-weight: 500;
    font-size: 0.76rem;
    color: var(--text-muted, #94a3b8);
}
.designer-acc > summary .acc-chevron {
    color: var(--text-muted, #94a3b8);
    transition: transform 0.2s ease;
    font-size: 0.85rem;
}
.designer-acc[open] > summary .acc-chevron { transform: rotate(180deg); }
.designer-acc[open] > summary { border-bottom: 1px solid var(--hairline, rgba(15, 23, 42, 0.06)); }
.designer-acc .acc-body { padding: 1rem 1.1rem 1.15rem; }

/* Live preview pane: a tall card containing the iframe of the actual print
   output. Sticky on wide screens so the preview travels with the form while
   scrolling. */
.designer-preview {
    background: var(--surface-1, #fff);
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.08));
    border-radius: 14px;
    padding: 0.75rem;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
    position: sticky;
    top: 5.5rem;
    align-self: start;
    max-height: calc(100vh - 7.5rem);
    display: flex;
    flex-direction: column;
}
.designer-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.5rem 0.75rem;
    border-bottom: 1px solid var(--hairline, rgba(15, 23, 42, 0.06));
    margin-bottom: 0.5rem;
}
.designer-preview-head i { color: var(--brand-1, #6366f1); margin-right: 0.3rem; }
.designer-preview iframe {
    width: 100%;
    flex: 1;
    min-height: 0;
    aspect-ratio: 210 / 297;
    border: 1px solid var(--hairline, rgba(15, 23, 42, 0.1));
    border-radius: 8px;
    background: #fff;
    display: block;
}

/* Premium Gradient Buttons */
.btn-save-pill {
    background: var(--brand-gradient) !important;
    color: white !important;
    border: none !important;
    padding: 0.6rem 1.5rem;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-save-pill:hover-disabled {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}
.btn-save-pill:active {
    transform: translateY(0);
}

/* Table Enhancements (Viewing Transactions) */
table tbody tr {
    transition: background-color 0.2s ease;
}
table tbody tr:hover-disabled {
    background-color: var(--accent-soft) !important;
}

/* Micro-animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.voucher-page {
    animation: fadeIn 0.4s ease-out;
}


/* -------- Print-friendly tweaks -------- */
@page {
    size: A4 portrait;
    margin: 18mm 15mm 22mm 15mm;
    /* Footer: page numbers via CSS Paged Media (Chrome/Edge respect this). */
    @bottom-center {
        content: counter(page) " / " counter(pages);
        font: 10pt 'Inter', sans-serif;
        color: #666;
    }
}
@media print {
    .sidebar, header, .voucher-list-topbar, .pager, .filter-card, .filter-trigger-btn,
    .cmdk-backdrop, #toast-container, .btn-row, .modal-backdrop, .skip-link,
    .cmdk-trigger, .chip, #r-print-btn, #r-export-excel, .btn-new-pill,
    .alert-banner button, [data-shortcut="save"], #sidebar-cmdk {
        display: none !important;
    }

    body { background: white !important; color: black !important; font-size: 10pt; }
    .main-content { margin-left: 0 !important; width: 100% !important; }
    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        background: white !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Tables — full width, classic accounting look */
    table { width: 100%; border-collapse: collapse; }
    table th, table td { border: 1px solid #ddd !important; padding: 6px 8px !important; }
    table thead th { background: #f5f5f5 !important; color: #111 !important; }
    table.sticky-thead thead th { position: static !important; box-shadow: none !important; }
    .sortable thead th::after { display: none !important; }

    /* Voided rows: faded with a watermark behind */
    .row-voided td { opacity: 0.65 !important; }

    /* IFRS report — strip backgrounds, keep totals visible */
    .ifrs-line { color: black !important; }
    .ifrs-line.subtotal, .ifrs-line.total {
        border-top: 1px solid #333 !important;
        background: transparent !important;
        font-weight: 700;
    }

    /* Voucher preview — keep the company header, hide modal chrome */
    .voucher-preview {
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
    .v-table thead th { background: #f0f0f0 !important; }

    /* Page-break helpers */
    h1, h2, h3 { page-break-after: avoid; }
    tr, .ifrs-line { page-break-inside: avoid; }

    /* KPI cards: one row per page max to stay legible */
    .stats-grid { display: grid !important; grid-template-columns: repeat(2, 1fr) !important; gap: 8mm !important; }
    .kpi-card { border: 1px solid #ddd !important; background: white !important; }
    .kpi-card .kpi-trend { background: transparent !important; }
}

/* =============================================================
   Responsive utilities + polish
   Breakpoints (kept in sync with the JS sidebar logic at 992px):
       xs <= 480   small phones
       sm <= 768   large phones / small tablets
       md <= 992   tablets / mobile menu trigger
       lg <= 1200  small laptops
   ============================================================= */

/* Visibility utilities — used by index.php on header chips/badges so they
   collapse out of the way on small screens instead of overflowing. */
.hide-sm, .hide-md, .hide-lg { /* shown by default */ }
.show-sm { display: none; }

@media (max-width: 992px) {
    .hide-sm { display: none !important; }
    .show-sm { display: inline-flex !important; }
}
@media (max-width: 1200px) {
    .hide-md { display: none !important; }
}
@media (max-width: 1440px) {
    .hide-lg { display: none !important; }
}

/* Header — keep actions on one row at narrow widths */
@media (max-width: 992px) {
    header { gap: 0.5rem; flex-wrap: nowrap; }
    .header-actions { gap: 0.35rem; flex-wrap: nowrap; }
    .header-title h1 { font-size: 1.05rem; line-height: 1.2; }
    .header-title p  { display: none; }
}

/* Generic table overflow — any table inside a card scrolls horizontally on
   mobile rather than blowing out the viewport. Tables already inside
   .table-responsive keep their existing behaviour. */
@media (max-width: 992px) {
    .card > table,
    .card > .table-wrap > table,
    .card .auto-scroll-x {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
}

/* Touch-friendly tap targets on mobile (WCAG / Apple HIG: 44×44 min) */
@media (max-width: 992px) {
    .btn,
    .nav-item,
    .tab-btn,
    .subtab,
    select, input[type="text"], input[type="email"],
    input[type="password"], input[type="date"], input[type="number"] {
        min-height: 44px;
    }
    .btn-icon { min-width: 44px; }
}

/* Modal sizing on small screens — full-width, scrollable */
@media (max-width: 768px) {
    .modal { width: calc(100% - 16px) !important; max-width: 100% !important; max-height: 92vh; }
    .modal-body { padding: 1rem !important; }
}

/* FY selector + search trigger compress on mobile so the header stays single-row */
@media (max-width: 992px) {
    .fy-selector { display: none; }
    .search-trigger span:not(.kbd) { display: none; }
    .search-trigger .kbd { display: none; }
    .search-trigger { padding: 0.4rem 0.5rem !important; }
}

/* Charts shouldn't overflow card padding on mobile */
@media (max-width: 992px) {
    canvas, .chart-wrap { max-width: 100%; height: auto !important; }
}

/* Sidebar nav items get a comfortable tap height when the mobile menu opens */
@media (max-width: 992px) {
    .nav-item, .cmdk-trigger { min-height: 44px; }
}

/* Voucher / form grids collapse on tablets too — was already 1100px for
   voucher lines, this catches the more generic .grid-2/.grid-3/.grid-4 case
   between 992px and 1200px where 2-column is still OK but 4-column isn't. */
@media (min-width: 993px) and (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
