/* ==========================================================================
   FBRInvoicePro design system (core)
   Identity: deep teal and emerald (Pakistani green family), gold accent for money,
   slate neutrals, 16px card radius, layered soft shadows, one spacing scale.
   Layout breakpoints (mobile first):
     phone    below 768px   bottom navigation, single column, bottom sheets
     tablet   768px-1199px  icon rail on the left, two to three card columns
     desktop  1200px+       full sidebar with groups, wide content, card grids
   Icons: Bootstrap Icons only (<i class="bi bi-...">). Font: Inter (Google Fonts link in the page head).
   Screen-specific rules (dashboard, invoice print, login details) live in app-screens.css.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
    /* Brand: teal and emerald */
    --brand-50: #f0fdfa;
    --brand-100: #ccfbf1;
    --brand-200: #99f6e4;
    --brand-300: #5eead4;
    --brand-400: #2dd4bf;
    --brand-500: #14b8a6;
    --brand-600: #0d9488;
    --brand-700: #0f766e;
    --brand-800: #115e59;
    --brand-900: #134e4a;
    /* RGB triplets for rgba() tints (teal values; the Semexsoft theme redefines them) */
    --brand-rgb-500: 20, 184, 166;
    --brand-rgb-700: 15, 118, 110;

    /* Gold accent for money and highlights */
    --gold-50: #fffbeb;
    --gold-100: #fef3c7;
    --gold-500: #d69e2e;
    --gold-700: #b45309;

    /* Slate neutrals */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* Status */
    --success: #059669;
    --success-bg: #d1fae5;
    --success-ink: #065f46;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --warning-ink: #92400e;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --danger-ink: #991b1b;
    --info: #0284c7;
    --info-bg: #e0f2fe;
    --info-ink: #075985;

    /* Surfaces and text */
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-soft: #e9eef4;
    --text: #0f172a;
    --text-muted: #64748b;

    /* Radius */
    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius: 16px;
    --radius-lg: 24px;
    --radius-xl: 28px;
    --radius-pill: 999px;

    /* Shadows: layered and soft */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 10px 28px -10px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 28px 56px -16px rgba(15, 23, 42, 0.28), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-brand: 0 14px 30px -10px rgba(var(--brand-rgb-700), 0.55);

    /* Spacing scale (4px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Type */
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Layout */
    --appbar-h: 64px;
    --nav-h: 68px;
    --touch: 44px;
    --rail-w: 92px;
    --side-w: 0px;
    --sheet-max: 600px;

    /* Motion (150ms to 300ms) */
    --dur-1: 150ms;
    --dur-2: 220ms;
    --dur-3: 300ms;
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

    /* Legacy names used by older markup and styles */
    --color-primary: var(--brand-700);
    --color-primary-50: var(--brand-50);
    --color-primary-100: var(--brand-100);
    --color-primary-600: var(--brand-600);
    --color-primary-700: var(--brand-700);
    --color-success: var(--success);
    --color-danger: var(--danger);
    --color-warning: var(--warning);
    --bg-app: var(--bg);
    --bg-page: var(--bg);
    --space-5-legacy: var(--space-5);
    --dur-fast: var(--dur-1);
    --dur: var(--dur-2);
    --dur-slow: var(--dur-3);
    --ease: var(--ease-out);
    --app-max: 600px;
}

/* ---------- Base ---------- */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(1100px 520px at -8% -14%, rgba(20, 184, 166, 0.14), transparent 62%),
        radial-gradient(900px 480px at 112% -10%, rgba(214, 158, 46, 0.10), transparent 58%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

img,
svg {
    max-width: 100%;
}

::selection {
    background: var(--brand-200);
    color: var(--brand-900);
}

:focus-visible {
    outline: 3px solid rgba(20, 184, 166, 0.55);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ---------- Shell: sidebar (desktop), rail (tablet), main column ---------- */
.app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
}

.app-sidebar {
    display: none;
}

.app-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* Signed-in pages: the sidebar column is added from 768px */
@media (min-width: 768px) {
    :root {
        --side-w: var(--rail-w);
    }

    body.has-nav .app-shell {
        grid-template-columns: var(--rail-w) minmax(0, 1fr);
    }

    body.has-nav .app-sidebar {
        display: flex;
    }
}

@media (min-width: 1200px) {
    :root {
        --side-w: 272px;
    }

    body.has-nav .app-shell {
        grid-template-columns: 272px minmax(0, 1fr);
    }
}

/* ---------- Sidebar (rail on tablet, full sidebar on desktop) ---------- */
body.has-nav .app-sidebar {
    position: sticky;
    top: 0;
    z-index: 1040;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
    flex-direction: column;
    gap: 4px;
    padding: 18px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border-soft);
}

.side-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 18px;
}

.side-brand-mark {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-800));
    color: #fff;
    font-size: 20px;
    box-shadow: var(--shadow-brand);
}

.side-brand-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.side-brand-text strong {
    font-size: 16px;
    font-weight: 750;
    letter-spacing: -0.01em;
    color: var(--slate-900);
}

.side-brand-text small {
    font-size: 12px;
    color: var(--text-muted);
}

.side-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.side-group + .side-group {
    margin-top: 14px;
}

.side-group-title {
    padding: 0 12px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--slate-400);
}

.side-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--touch);
    padding: 0 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--slate-600);
    font: inherit;
    font-size: 14.5px;
    font-weight: 550;
    text-align: left;
    text-decoration: none;
    transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}

.side-link i {
    width: 22px;
    flex: 0 0 auto;
    font-size: 18px;
    text-align: center;
    color: var(--slate-400);
    transition: color var(--dur-1) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}

.side-link span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-link:hover {
    background: var(--slate-100);
    color: var(--slate-900);
}

.side-link:hover i {
    color: var(--brand-600);
    transform: scale(1.08);
}

.side-link:active {
    transform: scale(0.98);
}

.side-link.active {
    background: linear-gradient(90deg, var(--brand-50), #ffffff 110%);
    color: var(--brand-800);
    font-weight: 650;
    box-shadow: inset 0 0 0 1px var(--brand-100);
}

.side-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 10px;
    bottom: 10px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--brand-600);
}

.side-link.active i {
    color: var(--brand-600);
}

.side-link.danger {
    color: var(--danger-ink);
}

.side-link.danger i {
    color: var(--danger);
}

.side-link.danger:hover {
    background: var(--danger-bg);
}

.side-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Tablet: icon rail with a small label under each icon */
@media (min-width: 768px) and (max-width: 1199px) {
    body.has-nav .app-sidebar {
        align-items: stretch;
        padding: 14px 8px;
    }

    .side-brand {
        justify-content: center;
        padding: 4px 0 14px;
    }

    .side-brand-text,
    .side-group-title {
        display: none;
    }

    .side-group + .side-group {
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--border-soft);
    }

    .side-link {
        flex-direction: column;
        justify-content: center;
        gap: 3px;
        min-height: 60px;
        padding: 8px 4px;
        font-size: 11px;
        font-weight: 600;
        text-align: center;
    }

    .side-link i {
        width: auto;
        font-size: 20px;
    }

    .side-link.active::before {
        left: -8px;
    }

    .side-link span {
        max-width: 100%;
        white-space: normal;
        line-height: 1.15;
    }
}

/* ---------- Top app bar ---------- */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--appbar-h);
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    background: rgba(255, 255, 255, 0.82);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    border-bottom: 1px solid var(--border-soft);
}

.app-bar-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--slate-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .app-bar {
        padding: 14px 24px;
        min-height: 72px;
    }

    .app-bar-title {
        font-size: 20px;
    }
}

@media (min-width: 1200px) {
    .app-bar {
        padding: 16px 40px;
    }

    .app-bar-title {
        font-size: 22px;
    }
}

.icon-btn {
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    width: var(--touch);
    height: var(--touch);
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    color: var(--slate-700);
    font-size: 20px;
    text-decoration: none;
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1), border-color var(--dur-1);
}

.icon-btn:hover {
    background: var(--slate-100);
    border-color: var(--border-soft);
}

.icon-btn:active {
    transform: scale(0.92);
}

/* Company chip in the app bar */
.chip {
    flex: 0 1 auto;
    max-width: 48%;
    min-height: var(--touch);
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid var(--brand-100);
    border-radius: var(--radius-pill);
    background: var(--brand-50);
    color: var(--brand-800);
    font-size: 13px;
    font-weight: 650;
    overflow: hidden;
    white-space: nowrap;
    transition: transform var(--dur-1) var(--ease-out), box-shadow var(--dur-2), background-color var(--dur-1);
}

.chip:hover {
    background: var(--brand-100);
    box-shadow: var(--shadow-sm);
}

.chip:active {
    transform: scale(0.97);
}

.chip:disabled {
    cursor: default;
    opacity: 0.85;
}

.chip-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chip-caret {
    flex: 0 0 auto;
    font-size: 11px;
}

/* ---------- Page content ---------- */
.page {
    width: 100%;
    box-sizing: border-box;
    padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 96px);
}

.page-enter {
    animation: page-enter var(--dur-3) var(--ease-out) both;
}

@media (min-width: 768px) {
    .page {
        padding: 24px 24px 120px;
    }
}

@media (min-width: 1200px) {
    .page {
        max-width: 1360px;
        margin: 0 auto;
        padding: 32px 40px 120px;
    }
}

.greeting {
    margin: 0 0 var(--space-4);
    color: var(--text-muted);
    font-size: 15px;
}

.greeting strong {
    color: var(--text);
}

/* ---------- Phone bottom navigation ---------- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    box-sizing: border-box;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr));
    background: rgba(255, 255, 255, 0.86);
    -webkit-backdrop-filter: blur(18px) saturate(170%);
    backdrop-filter: blur(18px) saturate(170%);
    border-top: 1px solid rgba(15, 23, 42, 0.07);
    box-shadow: 0 -10px 30px -12px rgba(15, 23, 42, 0.18);
}

body.has-nav .bottom-nav {
    display: grid;
}

@media (min-width: 768px) {
    body.has-nav .bottom-nav {
        display: none;
    }
}

.nav-pill {
    position: absolute;
    top: 8px;
    left: calc(var(--active, 0) * 100% / var(--n, 5) + 8px);
    width: calc(100% / var(--n, 5) - 16px);
    height: calc(var(--nav-h) - 16px);
    border-radius: var(--radius-pill);
    background: linear-gradient(180deg, var(--brand-100), var(--brand-50));
    transition: left var(--dur-2) var(--ease-spring), opacity var(--dur-2) var(--ease-out);
    pointer-events: none;
}

.bottom-nav.no-active .nav-pill {
    opacity: 0;
}

.nav-item {
    position: relative;
    z-index: 1;
    height: var(--nav-h);
    min-width: var(--touch);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--slate-500);
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    text-decoration: none;
    transition: color var(--dur-1) var(--ease-out);
}

.nav-item i {
    font-size: 21px;
    line-height: 1;
    transition: transform var(--dur-2) var(--ease-spring);
}

.nav-item.active {
    color: var(--brand-800);
}

.nav-item.active i {
    transform: translateY(-1px);
}

.nav-item:active i {
    transform: scale(0.86);
}

.nav-item:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: -6px;
    border-radius: 16px;
}

/* ---------- Floating action button ---------- */
.fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
    z-index: 1025;
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-800));
    color: #fff;
    font-size: 24px;
    box-shadow: var(--shadow-brand);
    transition: transform var(--dur-2) var(--ease-spring), box-shadow var(--dur-2);
}

.fab:hover {
    box-shadow: 0 18px 34px -10px rgba(15, 118, 110, 0.65);
}

.fab:active {
    transform: scale(0.9);
}

@media (min-width: 768px) {
    .fab {
        right: 28px;
        bottom: 28px;
        width: auto;
        height: 56px;
        padding: 0 22px 0 18px;
        border-radius: 18px;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-size: 18px;
    }

    .fab::after {
        content: "New";
        font-size: 15px;
        font-weight: 650;
    }
}

/* ---------- Buttons ---------- */
.btn {
    min-height: var(--touch);
    border-radius: 14px;
    font-weight: 650;
    letter-spacing: -0.005em;
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1), box-shadow var(--dur-2), border-color var(--dur-1), color var(--dur-1);
}

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

.btn:disabled {
    opacity: 0.55;
}

.btn-lg {
    min-height: 52px;
    border-radius: 16px;
    font-size: 16px;
}

.btn-sm {
    min-height: 36px;
    border-radius: 12px;
}

.btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--brand-700);
    --bs-btn-border-color: var(--brand-700);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand-800);
    --bs-btn-hover-border-color: var(--brand-800);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--brand-900);
    --bs-btn-active-border-color: var(--brand-900);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--brand-600);
    --bs-btn-disabled-border-color: var(--brand-600);
    --bs-btn-focus-shadow-rgb: 13, 148, 136;
    box-shadow: 0 8px 18px -10px rgba(15, 118, 110, 0.7);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 12px 24px -10px rgba(15, 118, 110, 0.8);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-700);
    --bs-btn-border-color: var(--brand-300);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--brand-700);
    --bs-btn-hover-border-color: var(--brand-700);
    --bs-btn-active-bg: var(--brand-800);
    --bs-btn-active-border-color: var(--brand-800);
    --bs-btn-focus-shadow-rgb: 13, 148, 136;
    background-color: #fff;
}

.btn-outline-secondary {
    --bs-btn-color: var(--slate-700);
    --bs-btn-border-color: var(--slate-300);
    --bs-btn-hover-color: var(--slate-900);
    --bs-btn-hover-bg: var(--slate-100);
    --bs-btn-hover-border-color: var(--slate-300);
    background-color: #fff;
}

.btn-danger {
    --bs-btn-bg: var(--danger);
    --bs-btn-border-color: var(--danger);
    --bs-btn-hover-bg: #b91c1c;
    --bs-btn-hover-border-color: #b91c1c;
}

.btn .spinner-border {
    width: 1.1rem;
    height: 1.1rem;
    margin-right: var(--space-2);
    vertical-align: -0.2em;
}

.btn.is-loading {
    cursor: progress;
}

/* Full-width action bars inside sheets and forms */
.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.header-actions .btn {
    min-height: 44px;
}

.ms-auto {
    margin-left: auto;
}

.flex-fill {
    flex: 1 1 0 !important;
}

/* ---------- Cards and lists ---------- */
.rec-card {
    position: relative;
    display: flex;
    flex-direction: column;
    margin-bottom: var(--space-3);
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out), border-color var(--dur-2);
}

@media (hover: hover) {
    .rec-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow);
        border-color: var(--brand-100);
    }
}

.rec-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.rec-title {
    min-width: 0;
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--slate-900);
    overflow-wrap: anywhere;
}

.rec-subtitle {
    margin-top: 2px;
    font-size: 13.5px;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

.rec-meta {
    display: grid;
    gap: 6px;
    margin-top: 12px;
}

.rec-meta-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: 14px;
}

.rec-meta-row .label {
    flex: 0 0 auto;
    color: var(--text-muted);
}

.rec-meta-row .value {
    min-width: 0;
    color: var(--slate-900);
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.rec-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.rec-action {
    min-height: var(--touch);
    min-width: var(--touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--slate-800);
    font: inherit;
    font-size: 14px;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1);
}

.rec-action:hover {
    border-color: var(--brand-300);
    color: var(--brand-800);
    background: var(--brand-50);
}

.rec-action:active {
    transform: scale(0.95);
}

.rec-action.primary {
    border-color: var(--brand-700);
    background: var(--brand-700);
    color: #fff;
}

.rec-action.primary:hover {
    background: var(--brand-800);
    border-color: var(--brand-800);
    color: #fff;
}

.rec-action.danger {
    border-color: #fecaca;
    background: #fff5f5;
    color: var(--danger);
}

.rec-action.danger:hover {
    background: var(--danger-bg);
    border-color: #fca5a5;
    color: var(--danger-ink);
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.invoice-text {
    flex: 1 1 auto;
    min-width: 0;
}

/* Invoice card: status stripe on the left, amount on the right */
.invoice-card {
    padding-left: 22px;
    overflow: hidden;
}

.invoice-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--slate-300);
}

.invoice-card:has(.status-posted)::before {
    background: var(--success);
}

.invoice-card:has(.status-failed)::before {
    background: var(--danger);
}

.invoice-card:has(.status-draft)::before {
    background: var(--gold-500);
}

/* Invoice actions sit in an even two-column grid */
.invoice-card .rec-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
}

.invoice-card .rec-action {
    width: 100%;
}

.inv-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.inv-amount {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.inv-amount-label {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--slate-400);
}

.inv-amount-value {
    font-size: 19px;
    font-weight: 750;
    letter-spacing: -0.02em;
    color: var(--slate-900);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Customer, product and company cards */
.customer-card,
.product-card,
.company-card,
.user-card,
.log-card {
    border-left-width: 1px;
}

.customer-card.is-inactive,
.product-card.is-inactive,
.company-card.is-inactive {
    opacity: 0.72;
}

.customer-code,
.product-code {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    min-width: 52px;
    height: 44px;
    padding: 0 10px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
    color: var(--brand-800);
    font-weight: 750;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

.customer-text {
    flex: 1 1 auto;
    min-width: 0;
}

.user-id {
    min-width: 0;
    flex: 1 1 auto;
}

.company-logo {
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
    color: var(--brand-700);
    font-size: 22px;
}

.company-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.company-id {
    flex: 1 1 auto;
    min-width: 0;
}

.env-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.env-badge i {
    font-size: 12px;
}

.env-sandbox {
    background: var(--warning-bg);
    color: var(--warning-ink);
}

.env-production {
    background: var(--success-bg);
    color: var(--success-ink);
}

/* Status, state and role badges */
.status-badge,
.state-badge,
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 650;
    line-height: 1.2;
    white-space: nowrap;
}

.status-badge i,
.state-badge i,
.role-badge i {
    font-size: 12px;
}

.status-draft {
    background: var(--gold-100);
    color: var(--warning-ink);
}

.status-posted {
    background: var(--success-bg);
    color: var(--success-ink);
}

.status-failed {
    background: var(--danger-bg);
    color: var(--danger-ink);
}

.state-active {
    background: var(--success-bg);
    color: var(--success-ink);
}

.state-inactive {
    background: var(--danger-bg);
    color: var(--danger-ink);
}

.state-unreg {
    background: var(--slate-100);
    color: var(--slate-600);
}

.role-admin {
    background: var(--brand-100);
    color: var(--brand-800);
}

.role-user {
    background: var(--slate-100);
    color: var(--slate-600);
}

.fbr-no {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 650;
    color: var(--success);
    white-space: nowrap;
}

.type-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: var(--gold-100);
    color: var(--warning-ink);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.code-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    background: var(--slate-100);
    color: var(--slate-600);
    font-size: 12px;
    font-weight: 650;
}

.unit-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: var(--slate-100);
    color: var(--slate-600);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.2;
    white-space: nowrap;
}

.unit-chip i {
    font-size: 12px;
}

.unit-chip-sm {
    font-size: 12px;
    padding: 4px 8px;
}

.you-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    background: var(--brand-100);
    color: var(--brand-800);
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
}

.money {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.hs-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.perm-label {
    font-weight: 600;
}

/* List containers become responsive card grids */
#companyCards,
#customerCards,
#productCards,
#invoiceCards,
#reportCards,
#logCards,
#recentCards,
#userList {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

#companyCards > *,
#customerCards > *,
#productCards > *,
#invoiceCards > *,
#reportCards > *,
#logCards > *,
#recentCards > *,
#userList > * {
    min-width: 0;
}

#companyCards .rec-card,
#customerCards .rec-card,
#productCards .rec-card,
#invoiceCards .rec-card,
#reportCards .rec-card,
#logCards .rec-card,
#recentCards .rec-card,
#userList .rec-card {
    height: 100%;
    margin-bottom: 0;
}

@media (min-width: 600px) {
    #companyCards,
    #customerCards,
    #productCards,
    #invoiceCards,
    #reportCards,
    #logCards,
    #recentCards,
    #userList {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }
}

@media (min-width: 768px) {
    #companyCards,
    #customerCards,
    #productCards,
    #invoiceCards,
    #reportCards,
    #logCards,
    #recentCards,
    #userList {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 16px;
    }
}

@media (min-width: 1200px) {
    #companyCards,
    #customerCards,
    #productCards,
    #invoiceCards,
    #reportCards,
    #logCards,
    #recentCards,
    #userList {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 18px;
    }
}

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.stat-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    animation: card-in 300ms var(--ease-out) both;
    transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}

.stat-card:nth-child(2) { animation-delay: 60ms; }
.stat-card:nth-child(3) { animation-delay: 120ms; }
.stat-card:nth-child(4) { animation-delay: 180ms; }
.stat-card:nth-child(5) { animation-delay: 240ms; }

a.stat-card {
    color: inherit;
    text-decoration: none;
}

a.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

a.stat-card:active {
    transform: scale(0.98);
}

.stat-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: 19px;
}

.stat-card.tone-success .stat-icon { background: var(--success-bg); color: var(--success-ink); }
.stat-card.tone-danger .stat-icon { background: var(--danger-bg); color: var(--danger-ink); }
.stat-card.tone-gold .stat-icon { background: var(--gold-100); color: var(--warning-ink); }

.stat-label {
    margin-top: 14px;
    font-size: 13px;
    font-weight: 550;
    color: var(--text-muted);
}

.stat-value {
    min-height: 30px;
    margin-top: 2px;
    font-size: 24px;
    font-weight: 750;
    letter-spacing: -0.02em;
    color: var(--slate-900);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.stat-sub {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.stat-card.is-loading .stat-value {
    width: 62%;
    color: transparent;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--slate-200) 25%, var(--slate-100) 37%, var(--slate-200) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
}

.stat-card.is-loading .stat-sub {
    visibility: hidden;
}

.stat-value.is-money {
    font-size: 19px;
    line-height: 1.25;
}

.stat-value-text {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.stat-card.span-2 {
    grid-column: span 2;
}

@media (min-width: 768px) {
    .stat-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: var(--space-4);
    }

    .stat-value {
        font-size: 26px;
    }

    .stat-value.is-money {
        font-size: 22px;
    }
}

/* ---------- Quick actions ---------- */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.quick-action {
    min-height: 96px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--slate-800);
    font-size: 14.5px;
    font-weight: 650;
    line-height: 1.25;
    text-decoration: none;
    transition: transform var(--dur-2) var(--ease-spring), box-shadow var(--dur-2), border-color var(--dur-2);
}

.quick-action i {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: 19px;
    transition: transform var(--dur-2) var(--ease-spring);
}

@media (hover: hover) {
    .quick-action:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow);
        border-color: var(--brand-100);
    }

    .quick-action:hover i {
        transform: scale(1.08) rotate(-3deg);
    }
}

.quick-action:active {
    transform: scale(0.96);
}

.quick-action.primary {
    background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
    border-color: transparent;
    color: #fff;
    box-shadow: var(--shadow-brand);
}

.quick-action.primary i {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.quick-action.tone-danger i {
    background: var(--danger-bg);
    color: var(--danger-ink);
}

@media (min-width: 768px) {
    .quick-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1200px) {
    .quick-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: var(--space-4);
    }
}

/* ---------- Section headings ---------- */
.section-title {
    margin: 0 0 var(--space-4);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--slate-900);
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin: 28px 0 14px;
}

.section-head .section-title {
    margin: 0;
}

.section-link {
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    font-size: 14px;
    font-weight: 650;
    color: var(--brand-700);
    text-decoration: none;
}

.section-link:hover {
    color: var(--brand-900);
}

.sheet-section {
    margin: var(--space-4) 0 var(--space-3);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ---------- Search and filter chips ---------- */
.search-box {
    position: relative;
    margin-bottom: var(--space-4);
}

.search-box > i {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    color: var(--slate-400);
    font-size: 18px;
    pointer-events: none;
}

.search-box .form-control {
    min-height: 50px;
    padding-left: 44px;
    border-radius: 16px;
    font-size: 16px;
    border-color: var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.search-box .form-control:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 4px var(--brand-100);
}

@media (min-width: 768px) {
    .search-box {
        max-width: 560px;
    }
}

.filter-row {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding: 2px 0 var(--space-3);
    scrollbar-width: none;
}

.filter-row::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: var(--touch);
    padding: 0 16px;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--slate-600);
    font: inherit;
    font-size: 14px;
    font-weight: 620;
    cursor: pointer;
    transition: background-color var(--dur-1), color var(--dur-1), border-color var(--dur-1), transform var(--dur-1), box-shadow var(--dur-2);
}

.filter-chip:hover {
    border-color: var(--brand-300);
    color: var(--brand-800);
}

.filter-chip:active {
    transform: scale(0.96);
}

.filter-chip.is-active {
    background: var(--brand-700);
    border-color: var(--brand-700);
    color: #fff;
    box-shadow: 0 8px 18px -10px rgba(15, 118, 110, 0.8);
}

.filter-date i {
    font-size: 15px;
}

/* ---------- Empty and notice states ---------- */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
    animation: card-in 300ms var(--ease-out) both;
}

.empty-state .empty-icon {
    width: 76px;
    height: 76px;
    margin: 0 auto 18px;
    display: grid;
    place-items: center;
    border-radius: 26px;
    background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
    color: var(--brand-700);
    font-size: 34px;
    box-shadow: inset 0 0 0 1px var(--brand-100);
}

.empty-state h2 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
    color: var(--slate-900);
}

.empty-state p {
    margin: 0 auto;
    max-width: 420px;
    font-size: 14.5px;
}

.notice-card {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: 16px 18px;
    border: 1px solid var(--brand-100);
    border-radius: var(--radius);
    background: var(--brand-50);
    color: var(--brand-800);
}

.notice-card i {
    font-size: 22px;
    margin-top: 2px;
}

.notice-card p {
    margin: 4px 0 10px;
    font-size: 14px;
    color: var(--slate-700);
}

.alert-danger-note {
    display: flex;
    gap: var(--space-2);
    align-items: flex-start;
    margin-bottom: var(--space-3);
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--danger-bg);
    color: var(--danger-ink);
    font-size: 14px;
}

.alert-danger-note i {
    margin-top: 2px;
}

.alert-note {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--brand-50);
    border: 1px solid var(--brand-100);
    color: var(--brand-800);
    font-size: 14px;
    font-weight: 500;
}

.alert-note i {
    font-size: 18px;
    margin-top: 1px;
}

.form-note {
    margin: 0 0 var(--space-3);
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--slate-100);
    color: var(--slate-600);
    font-size: 14px;
}

.form-alert {
    margin-bottom: var(--space-4);
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--danger-bg);
    color: var(--danger-ink);
    font-size: 14px;
    font-weight: 550;
}

.code-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-bottom: var(--space-4);
    padding: 14px 16px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--slate-50), var(--slate-100));
    border: 1px solid var(--border-soft);
}

.code-row .label {
    color: var(--text-muted);
    font-size: 14px;
}

.code-value {
    font-size: 20px;
    font-weight: 750;
    letter-spacing: 1.5px;
    color: var(--slate-900);
    font-variant-numeric: tabular-nums;
}

.code-row .form-text {
    margin: 0;
    flex-basis: 100%;
}

.spacer-16 {
    height: var(--space-4);
}

.dash-company {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 var(--space-3);
    font-size: 13px;
    color: var(--text-muted);
}

.dash-company i {
    color: var(--brand-700);
}

/* ---------- Skeleton loaders ---------- */
.skeleton-card {
    margin-bottom: var(--space-3);
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

.skeleton-line {
    height: 12px;
    margin-bottom: 10px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--slate-200) 25%, var(--slate-100) 37%, var(--slate-200) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-80 { width: 80%; }

/* ---------- Toasts ---------- */
.toast-stack {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: var(--side-w);
    right: 0;
    z-index: 1085;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: 0 16px;
    pointer-events: none;
}

.toast-item {
    width: min(100%, 440px);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    border-radius: 16px;
    background: var(--slate-900);
    color: var(--slate-50);
    box-shadow: var(--shadow-lg);
    font-size: 14.5px;
    cursor: pointer;
    animation: toast-in var(--dur-2) var(--ease-spring) both;
}

.toast-item.is-leaving {
    animation: toast-out var(--dur-1) var(--ease-out) both;
}

.toast-item i {
    flex: 0 0 auto;
    font-size: 19px;
}

.toast-item.success i { color: #34d399; }
.toast-item.error i { color: #f87171; }
.toast-item.warning i { color: #fbbf24; }
.toast-item.info i { color: #38bdf8; }

.toast-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ---------- Bottom sheets (offcanvas-bottom) ---------- */
.offcanvas-bottom.sheet {
    left: 0;
    right: 0;
    height: auto;
    max-width: 100%;
    max-height: 92vh;
    margin: 0 auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-top: 0;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.sheet-handle {
    width: 44px;
    height: 5px;
    margin: 10px auto 2px;
    border-radius: var(--radius-pill);
    background: var(--slate-300);
}

@media (min-width: 768px) {
    /* Centred and floating on tablet and desktop, still sliding up */
    .offcanvas.offcanvas-bottom.sheet {
        left: 50%;
        right: auto;
        bottom: 24px;
        width: min(var(--sheet-max), calc(100vw - 48px));
        max-width: var(--sheet-max);
        max-height: calc(100dvh - 48px);
        border-radius: var(--radius-lg);
        transform: translate(-50%, calc(100% + 48px));
    }

    .offcanvas.offcanvas-bottom.sheet.show {
        transform: translate(-50%, 0);
    }

    .sheet-handle {
        display: none;
    }
}

.sheet .offcanvas-header {
    align-items: center;
    padding: 12px 20px 8px;
}

.sheet .offcanvas-title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sheet .offcanvas-body {
    padding: var(--space-2) 20px calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
}

.sheet-form-body {
    max-height: calc(92vh - 150px);
    padding: 0 20px;
    overflow-y: auto;
}

@media (min-width: 768px) {
    .sheet-form-body {
        max-height: calc(100dvh - 260px);
    }
}

.save-bar {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    gap: var(--space-3);
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border-soft);
    box-shadow: 0 -10px 24px -14px rgba(15, 23, 42, 0.18);
}

.save-bar .btn {
    flex: 1 1 0;
    min-height: 52px;
}

/* ---------- Form controls and floating labels ---------- */
.form-control,
.form-select {
    font-size: 16px;
    border-radius: 14px;
    border-color: var(--border);
    background-color: var(--surface);
    transition: border-color var(--dur-1), box-shadow var(--dur-2);
}

.form-control:hover,
.form-select:hover {
    border-color: var(--slate-300);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 4px var(--brand-100);
}

.form-floating > .form-control {
    height: 58px;
    min-height: 56px;
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
}

.form-floating > label {
    color: var(--text-muted);
    font-size: 15px;
}

.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
    color: var(--brand-700);
}

.form-floating > .form-control.is-invalid {
    border-color: var(--danger);
}

.form-floating > .form-control.is-invalid:focus {
    box-shadow: 0 0 0 4px var(--danger-bg);
}

.form-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--slate-700);
}

.invalid-feedback {
    font-size: 13px;
}

.form-text {
    font-size: 13px;
    color: var(--text-muted);
}

.field-caption {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-600);
}

/* Show and hide password, inside a floating input */
.input-action {
    position: absolute;
    top: 50%;
    right: 6px;
    z-index: 5;
    width: var(--touch);
    height: var(--touch);
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--slate-500);
    font-size: 20px;
}

.input-action:hover {
    background: var(--slate-100);
    color: var(--slate-800);
}

.form-floating > .form-control.has-action-pad {
    padding-right: 52px;
}

/* Segmented control (Sandbox and Production) */
.segmented {
    position: relative;
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: var(--space-3);
    border-radius: 16px;
    background: var(--slate-100);
}

.segmented-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.segmented-label {
    flex: 1 1 0;
    min-height: var(--touch);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 12px;
    color: var(--slate-600);
    font-weight: 650;
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1), box-shadow var(--dur-2);
}

.segmented-label:hover {
    color: var(--slate-900);
}

.segmented-input:checked + .segmented-label {
    background: var(--surface);
    color: var(--brand-800);
    box-shadow: var(--shadow-sm);
}

.segmented-input:focus-visible + .segmented-label {
    outline: 2px solid var(--brand-600);
    outline-offset: 2px;
}

/* Custom switch (appearance none), at least 44px tall */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 64px;
    margin-bottom: var(--space-3);
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    cursor: pointer;
}

.switch-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.switch-title {
    font-size: 16px;
    font-weight: 620;
    color: var(--text);
}

.switch-sub {
    font-size: 13px;
    color: var(--text-muted);
}

.ui-switch {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    flex: 0 0 auto;
    width: 52px;
    height: 32px;
    margin: 0;
    border-radius: var(--radius-pill);
    background: var(--slate-300);
    cursor: pointer;
    transition: background-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}

.ui-switch::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.25);
    transition: transform var(--dur-2) var(--ease-spring);
}

.ui-switch:checked {
    background: var(--brand-600);
}

.ui-switch:checked::before {
    transform: translateX(20px);
}

.ui-switch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ui-switch:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 3px;
}

/* ---------- "More" sheet items ---------- */
.more-item {
    width: 100%;
    min-height: 60px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
    padding: 10px 14px;
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px;
    font-weight: 620;
    text-align: left;
    text-decoration: none;
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1), border-color var(--dur-1);
}

.more-item:hover {
    border-color: var(--brand-100);
    background: var(--brand-50);
}

.more-item:active {
    transform: scale(0.98);
}

.more-item.is-current {
    border-color: var(--brand-200);
    background: var(--brand-50);
    color: var(--brand-800);
}

.more-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: 19px;
}

.more-chevron {
    margin-left: auto;
    color: var(--slate-400);
}

.more-item.danger {
    color: var(--danger-ink);
}

.more-item.danger .more-icon {
    background: var(--danger-bg);
    color: var(--danger-ink);
}

/* ---------- Company switcher sheet ---------- */
.company-option {
    width: 100%;
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
    padding: 10px 14px;
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    text-align: left;
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1), border-color var(--dur-1);
}

.company-option:hover {
    border-color: var(--brand-200);
}

.company-option:active {
    transform: scale(0.98);
}

.company-option.is-current {
    border-color: var(--brand-600);
    background: var(--brand-50);
}

.co-code {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: var(--brand-100);
    color: var(--brand-800);
    font-weight: 750;
}

.co-text {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.co-name {
    max-width: 100%;
    font-weight: 650;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.co-check {
    flex: 0 0 auto;
    font-size: 18px;
    color: var(--brand-700);
}

/* ---------- Motion (CSS only) ---------- */
/* Fade only: a transform on the page would make it the reference point for fixed bars and sheets */
@keyframes page-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes card-in {
    from { opacity: 0; transform: translateY(12px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

@keyframes shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-16px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(-10px); }
}

@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-8px); }
    40%, 60% { transform: translateX(8px); }
}

/* Stagger: JS sets --i on each card */
.stagger-item {
    animation: card-in 300ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 45ms);
}

.shake {
    animation: shake 360ms var(--ease-out);
}

/* Focus helpers for rows that act as buttons */
.line-card,
.log-card,
.rec-card[role="button"] {
    cursor: pointer;
}

.is-flagged {
    outline: 2px solid var(--danger);
    outline-offset: 2px;
}

/* ---------- Reduced motion ---------- */
/* Install steps (iPhone and iPad "Add to Home Screen" sheet, used on every page) */
.install-steps {
    display: grid;
    gap: 12px;
    margin: 4px 0 20px;
    padding: 0;
    list-style: none;
}

.install-steps li {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border-radius: 18px;
    background: #f1f8f7;
    font-size: 15px;
    line-height: 1.45;
    color: #0f172a;
    animation: card-in 360ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 90ms + 120ms);
}

.step-badge {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    font-size: 14px;
    font-weight: 800;
}

/* ---------- Colour themes ----------
   Default: the teal tokens in :root above.
   Semexsoft: navy taken from the Semexsoft logo. Set by Scripts/theme.js on <html data-theme="semexsoft">. */
:root[data-theme="semexsoft"] {
    --brand-50: #eef5f9;
    --brand-100: #d6e7f1;
    --brand-200: #adcfe2;
    --brand-300: #7fb2cf;
    --brand-400: #4a8fb5;
    --brand-500: #2a72a0;
    --brand-600: #1a5b84;
    --brand-700: #0b4a6f;
    --brand-800: #002840;
    --brand-900: #001b2d;
    --brand-rgb-500: 42, 114, 160;
    --brand-rgb-700: 11, 74, 111;
}

/* Theme picker cards (Profile page) */
.theme-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

@media (min-width: 480px) {
    .theme-options {
        grid-template-columns: 1fr 1fr;
    }
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 60px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--dur-1), box-shadow var(--dur-2), transform var(--dur-1);
}

.theme-option:hover {
    border-color: var(--brand-300);
}

.theme-option:active {
    transform: scale(0.98);
}

.theme-option:focus-visible {
    outline: 3px solid rgba(var(--brand-rgb-500), 0.45);
    outline-offset: 2px;
}

.theme-option.active {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb-500), 0.18);
}

.theme-swatch {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.theme-swatch.sw-teal {
    background: linear-gradient(135deg, #14b8a6, #0f766e 60%, #115e59);
}

.theme-swatch.sw-semexsoft {
    background: linear-gradient(135deg, #2a72a0, #0b4a6f 60%, #002840);
}

.theme-option-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
}

.theme-option-text strong {
    font-size: 15px;
    font-weight: 700;
}

.theme-option-text small {
    font-size: 12.5px;
    color: var(--text-muted);
}

.theme-check {
    flex: 0 0 auto;
    font-size: 20px;
    color: var(--brand-600);
    opacity: 0;
    transition: opacity var(--dur-1);
}

.theme-option.active .theme-check {
    opacity: 1;
}

/* Semexsoft tile in the sidebar brand */
.side-brand-mark {
    background: none;
    box-shadow: none;
    overflow: hidden;
}

.side-brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-delay: 0ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
}
