/* public/assets/css/app.css
   ============================================================
   SBN — Shipping Management Suite
   Design system v3 — "Verdant Ledger"
   Polaris-inspired admin: white surfaces, crisp 1px borders,
   flat depth, emerald accent, single-family app typography.
   Mobile: app shell w/ bottom nav + stacked-card tables
   (no horizontal scrollbars anywhere).
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ====== Design tokens ====== */
:root {
    /* Color — neutrals (Polaris-like) */
    --bg-body: #f6f6f7;
    --bg-panel: #ffffff;
    --bg-soft: #fafbfb;
    --bg-hover: #f1f2f3;
    --text-main: #202223;
    --text-muted: #6d7175;
    --border: #e1e3e5;
    --border-dark: #c9cccf;

    /* Color — brand (emerald) */
    --accent: #008060;
    --accent-strong: #006e52;
    --accent-2: #0d9488;
    --accent-soft: rgba(0, 128, 96, 0.12);
    --accent-tint: #ecfdf5;
    --accent-grad: linear-gradient(135deg, #008060 0%, #00a47c 100%);
    /* legacy alias */
    --accent-amber: #0d9488;

    /* Color — semantic */
    --success: #008060;
    --success-soft: #d1fae5;
    --danger: #d82c0d;
    --danger-soft: #fff4f4;
    --warning: #b98900;
    --warning-soft: #fff8db;

    /* Sidebar (light) */
    --sidebar-bg: #ffffff;
    --sidebar-text: #303234;
    --sidebar-text-dim: #6d7175;
    --sidebar-border: #e1e3e5;
    --sidebar-hover: #f1f2f3;

    /* Shape & depth — flat, bordered, sharp containers */
    --radius: 0;
    --radius-lg: 0;
    --radius-ctl: 4px; /* interactive controls only */
    --shadow-soft: 0 1px 2px rgba(31, 33, 36, 0.06);
    --shadow-pop: 0 8px 28px rgba(31, 33, 36, 0.16);
    --panel-glow: 0 4px 14px rgba(0, 128, 96, 0.25);

    /* Layout */
    --sidebar-width: 252px;
    --bottom-nav-h: 62px;

    /* Z-index scale */
    --z-bottomnav: 80;
    --z-backdrop: 90;
    --z-sidebar: 100;
    --z-header: 60;
    --z-modal: 200;
    --z-loader: 999;
}

/* ====== Base ====== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text-main);
    background: var(--bg-body);
}

h1, h2, h3, h4 {
    font-family: inherit;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
}

p { margin: 0; }

a {
    color: var(--accent-strong);
    text-decoration: none;
}

button, input, select, textarea {
    font-family: inherit;
}

button, a, [role="button"] {
    touch-action: manipulation;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

/* ========= Global page loader ========= */
.page-loader {
    position: fixed;
    inset: 0;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loader);
    transition: opacity .3s ease;
}

.page-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.page-loader .spinner {
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 3.5px solid #e1e3e5;
    border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========= Subscription alert ========= */
.subscription-alert {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 120;
    margin: 0 auto;
    padding: 12px 16px;
    border-radius: 0 0 4px 4px;
    border: 1px solid #e3c200;
    border-top: none;
    background: var(--warning-soft);
    color: #755f00;
    font-size: 13px;
    font-weight: 600;
    display: none;
    max-width: 1180px;
    box-shadow: var(--shadow-pop);
}

body.has-subscription-alert .subscription-alert {
    display: block;
}

/* ========= AUTH / LOGIN (split-screen) ========= */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    background: #f6f6f7;
}

.auth-split {
    display: flex;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ----- Brand side ----- */
.auth-brand {
    flex: 1.15;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 32px;
    padding: 44px 52px;
    padding-top: calc(44px + env(safe-area-inset-top, 0px));
    color: #eafff7;
    background:
        radial-gradient(900px 600px at 85% -10%, rgba(0, 164, 124, 0.35), transparent 60%),
        radial-gradient(700px 500px at -10% 110%, rgba(13, 148, 136, 0.30), transparent 55%),
        linear-gradient(160deg, #00231a 0%, #00382a 55%, #005c44 100%);
    position: relative;
    overflow: hidden;
}

/* ambient drifting glow */
.auth-brand::before,
.auth-brand::after {
    content: '';
    position: absolute;
    width: 480px;
    height: 480px;
    border-radius: 999px;
    filter: blur(70px);
    opacity: 0.5;
    pointer-events: none;
}

.auth-brand::before {
    background: radial-gradient(circle, rgba(0, 164, 124, 0.55), transparent 65%);
    top: -160px;
    right: -120px;
    animation: auth-drift-a 16s ease-in-out infinite alternate;
}

.auth-brand::after {
    background: radial-gradient(circle, rgba(13, 148, 136, 0.45), transparent 65%);
    bottom: -180px;
    left: -140px;
    animation: auth-drift-b 20s ease-in-out infinite alternate;
}

@keyframes auth-drift-a {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(-60px, 50px) scale(1.15); }
}

@keyframes auth-drift-b {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(70px, -40px) scale(1.1); }
}

.auth-brand > * {
    position: relative;
    z-index: 1;
}

.auth-brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
    animation: auth-fade-up .5s ease-out both;
}

.auth-logo-circle {
    width: 46px;
    height: 46px;
    border-radius: 0;
    background: var(--accent-grad);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #ffffff;
    font-size: 17px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    flex-shrink: 0;
}

.auth-brand-name {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.auth-brand-hero {
    max-width: 520px;
}

.auth-brand-headline {
    font-size: clamp(28px, 3.4vw, 42px);
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.12;
    color: #ffffff;
    margin-bottom: 14px;
    animation: auth-fade-up .55s ease-out .08s both;
}

.auth-brand-tagline {
    font-size: 15px;
    line-height: 1.65;
    color: rgba(234, 255, 247, 0.82);
    margin-bottom: 26px;
    animation: auth-fade-up .55s ease-out .16s both;
}

.auth-features {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 13px;
}

.auth-features li {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(234, 255, 247, 0.92);
    animation: auth-fade-up .55s ease-out both;
}

.auth-features li:nth-child(1) { animation-delay: .24s; }
.auth-features li:nth-child(2) { animation-delay: .32s; }
.auth-features li:nth-child(3) { animation-delay: .40s; }

.auth-feature-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    background: rgba(0, 164, 124, 0.25);
    border: 1px solid rgba(0, 164, 124, 0.5);
    color: #5ff0c6;
}

.auth-feature-icon svg {
    width: 14px;
    height: 14px;
}

.auth-brand-footer {
    font-size: 12.5px;
    color: rgba(234, 255, 247, 0.55);
    line-height: 1.6;
    white-space: pre-line;
    animation: auth-fade-up .55s ease-out .5s both;
}

/* ----- Form side ----- */
.auth-form-side {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 32px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    background: #ffffff;
    border-left: 1px solid var(--border);
}

.auth-panel {
    width: min(400px, 100%);
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    animation: auth-fade-up .55s ease-out .12s both;
}

.auth-form-heading h2 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.auth-form-heading p {
    margin-top: 5px;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-form { margin-top: 26px; }

.auth-form .field { margin-bottom: 18px; }

.auth-form label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 7px;
}

.auth-form input[type="text"],
.auth-form input[type="password"],
.auth-form input[type="email"] {
    width: 100%;
    padding: 12px 14px;
    min-height: 50px;
    border-radius: 4px;
    border: 1px solid var(--border-dark);
    font-size: 16px;
    outline: none;
    background: #ffffff;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.auth-form input:hover {
    border-color: #9aa0a5;
}

.auth-form input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* password field with visibility toggle */
.auth-input-wrap {
    position: relative;
}

.auth-input-wrap input {
    padding-right: 52px !important;
}

.auth-eye {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: color .15s ease, background .15s ease;
}

.auth-eye:hover {
    color: var(--accent-strong);
    background: var(--accent-tint);
}

.auth-eye svg {
    width: 20px;
    height: 20px;
}

.auth-form .error-box {
    background: var(--danger-soft);
    color: #a01c00;
    border-radius: 4px;
    border: 1px solid #f3b7ab;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 14px;
    animation: auth-shake .4s ease-in-out;
}

@keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.auth-form .actions {
    margin-top: 22px;
    display: flex;
    align-items: center;
    justify-content: stretch;
    gap: 12px;
    flex-wrap: wrap;
}

.auth-form .actions .btn-primary {
    width: 100%;
    min-height: 50px;
    font-size: 15.5px;
    letter-spacing: 0.01em;
    background: var(--accent-grad);
    transition: filter .18s ease, transform .15s ease, box-shadow .18s ease;
}

.auth-form .actions .btn-primary:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 10px 26px rgba(0, 128, 96, 0.35);
}

.auth-form .actions .btn-primary:active {
    transform: translateY(0) scale(0.985);
}

.auth-footer-note {
    margin-top: 22px;
    font-size: 12.5px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

@keyframes auth-fade-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ----- Auth responsive ----- */
@media (max-width: 860px) {
    .auth-split {
        flex-direction: column;
    }

    .auth-brand {
        flex: none;
        padding: 24px 22px 26px;
        padding-top: calc(22px + env(safe-area-inset-top, 0px));
        gap: 18px;
    }

    .auth-brand-headline {
        font-size: 24px;
        margin-bottom: 8px;
    }

    .auth-brand-tagline {
        font-size: 13.5px;
        margin-bottom: 0;
    }

    .auth-features,
    .auth-brand-footer {
        display: none; /* keep the mobile screen focused on signing in */
    }

    .auth-form-side {
        flex: 1;
        border-left: none;
        align-items: flex-start;
        padding: 30px 22px 40px;
    }
}

/* ========= Buttons ========= */
.btn-primary {
    border: none;
    border-radius: 4px;
    padding: 10px 18px;
    min-height: 42px;
    font-size: 14.5px;
    font-weight: 700;
    cursor: pointer;
    background: var(--accent);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.18), var(--shadow-soft);
    transition: background .15s ease, transform .12s ease;
}

.btn-primary:hover {
    background: var(--accent-strong);
}

.btn-primary:active {
    transform: scale(0.985);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-sm {
    border-radius: 4px;
    border: 1px solid var(--border-dark);
    background: #ffffff;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 13px;
    min-height: 34px;
    cursor: pointer;
    color: var(--text-main);
    box-shadow: var(--shadow-soft);
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
}

.btn-sm:hover {
    background: var(--bg-hover);
}

.btn-sm:active { transform: scale(0.97); }

.btn-sm.btn-primary {
    border: none;
    background: var(--accent);
    color: #ffffff;
}

.btn-sm.btn-primary:hover {
    background: var(--accent-strong);
}

.btn-sm-danger {
    border-color: #f3b7ab;
    background: var(--danger-soft);
    color: #a01c00;
}

.btn-sm-danger:hover {
    background: #ffe9e4;
    border-color: #eda08f;
}

/* ========= Form controls (global) ========= */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="password"],
select,
textarea {
    border: 1px solid var(--border-dark);
    background: #ffffff;
    color: var(--text-main);
    border-radius: 4px;
    accent-color: var(--accent);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-soft) !important;
    outline: none;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--accent);
    width: 17px;
    height: 17px;
}

::placeholder {
    color: #8c9196;
    opacity: 1;
}

/* ========= APP SHELL ========= */
.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    background: var(--bg-body);
}

/* ========= SIDEBAR (light, Polaris-style) ========= */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 16px 12px 14px;
    /* Fixed to the viewport while the page scrolls; scrolls its own
       content independently (sticky keeps it inside the flex layout) */
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    align-self: flex-start;
    z-index: var(--z-sidebar);
    flex-shrink: 0;
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #c9cccf transparent;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
    background: #d7dadd;
    border-radius: 99px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 4px 6px;
}

.sidebar-logo-circle {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    color: #ffffff;
    box-shadow: var(--panel-glow);
    flex-shrink: 0;
}

.sidebar-company {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.sidebar-company-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-company-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Profile chip */
.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-soft);
}

.sidebar-profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: var(--accent);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
}

.sidebar-profile-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.sidebar-profile-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-profile-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.sidebar-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    min-height: 42px;
    margin-bottom: 14px;
    border-radius: 4px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    border: none;
    text-decoration: none;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.18), var(--shadow-soft);
    transition: background .15s ease;
}

.sidebar-cta:hover {
    background: var(--accent-strong);
}

/* Nav */
.sidebar-nav-heading {
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    padding: 12px 8px 5px;
}

.sidebar-nav {
    margin-top: 2px;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 8px 9px;
    min-height: 40px;
    border-radius: 4px;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    color: var(--sidebar-text);
    margin-bottom: 2px;
    transition: background-color .15s ease, color .15s ease;
    border: none;
    position: relative;
}

.sidebar-nav a span.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 9px;
    width: 27px;
    height: 27px;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color .15s ease, background .15s ease;
}

.sidebar-nav a .chevron {
    margin-left: auto;
    font-size: 13px;
    color: var(--border-dark);
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: var(--text-main);
}

.sidebar-nav a:hover span.icon {
    color: var(--text-main);
}

.sidebar-nav a.active {
    background: var(--accent-tint);
    color: var(--accent-strong);
    font-weight: 700;
    box-shadow: none;
}

.sidebar-nav a.active .icon {
    background: rgba(0, 128, 96, 0.12);
    color: var(--accent-strong);
}

.sidebar-nav a.active .chevron {
    color: var(--accent);
}

.sidebar-nav a::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: transparent;
    transition: background .15s ease;
}

.sidebar-nav a.active::before {
    background: var(--accent);
}

.sidebar-section {
    margin-top: 10px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.sidebar-section-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--text-muted);
    padding: 6px 4px 5px 10px;
}

.sidebar-subnav {
    margin: 2px 0 5px;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    margin-left: 21px;
}

.sidebar-subnav a {
    font-size: 13px;
    min-height: 36px;
    padding: 6px 8px;
    font-weight: 500;
}

.sidebar-subnav a .icon {
    width: 23px;
    height: 23px;
    border-radius: 7px;
    margin-right: 7px;
}

.sidebar-subnav a::before { content: none; }

/* Finance highlight group */
.sidebar-highlight-box {
    margin: 4px 0 6px;
    padding: 7px;
    border-radius: 0;
    background: var(--bg-soft);
    border: 1px solid var(--border);
}

.sidebar-highlight-box > a {
    display: flex;
    margin-left: 0;
}

.sidebar-highlight-box > a::before { content: none; }

/* Sidebar footer */
.sidebar-footer {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 11px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.sidebar-logout-form {
    margin-top: 10px;
}

.sidebar-logout-form button {
    width: 100%;
    border-radius: 4px;
    border: 1px solid #f3b7ab;
    padding: 9px 0;
    min-height: 40px;
    font-size: 13px;
    font-weight: 700;
    background: #ffffff;
    color: #a01c00;
    cursor: pointer;
    transition: background-color .15s ease;
}

.sidebar-logout-form button:hover {
    background: var(--danger-soft);
}

/* Backdrop for mobile overlay */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 33, 36, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease;
    z-index: var(--z-backdrop);
}

/* ========= MAIN AREA ========= */
.main {
    flex: 1;
    padding: 20px 24px 32px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-body);
}

/* Full-bleed app header attached to the top (Stripe/Shopify style) */
.main-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: -20px -24px 20px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.94);
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: var(--z-header);
}

.main-title-block {
    min-width: 0;
}

.main-title-block h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-title-block p {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.user-badge {
    padding: 7px 11px;
    min-height: 38px;
    border-radius: 4px;
    background: var(--bg-soft);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    border: 1px solid var(--border);
    font-weight: 700;
    white-space: nowrap;
}

.user-badge-role {
    padding: 3px 8px;
    border-radius: 7px;
    background: var(--accent);
    color: #ffffff;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* Mobile sidebar toggle (icon button) */
.mobile-sidebar-toggle {
    display: none;
    border-radius: 4px;
    border: 1px solid var(--border-dark);
    background: #ffffff;
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    flex-shrink: 0;
    box-shadow: var(--shadow-soft);
}

.mobile-sidebar-toggle:active {
    background: var(--bg-hover);
}

.mobile-sidebar-toggle .icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    position: relative;
}

.mobile-sidebar-toggle .icon::before,
.mobile-sidebar-toggle .icon::after {
    content: '';
    position: absolute;
    left: 2px;
    right: 2px;
    height: 2px;
    border-radius: 2px;
    background: var(--text-main);
}

.mobile-sidebar-toggle .icon::before {
    top: 6px;
    box-shadow: 0 5px 0 var(--text-main);
}

.mobile-sidebar-toggle .icon::after {
    top: 16px;
}

.mobile-sidebar-toggle .label {
    display: none;
}

/* ========= TOP BAR SEARCH ========= */
.header-search,
.global-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 13px;
    min-height: 42px;
    border-radius: 4px;
    background: #ffffff;
    border: 1px solid var(--border-dark);
    max-width: 380px;
    width: 100%;
    transition: border-color .15s ease, box-shadow .15s ease;
    font-size: 14px;
    box-shadow: var(--shadow-soft);
}

.header-search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.header-search-icon,
.global-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--accent-tint);
    color: var(--accent-strong);
    font-size: 0;
    position: relative;
}

.header-search-icon::before,
.global-search-icon::before {
    content: '';
    width: 12px;
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='11' cy='11' r='7' stroke='%23006e52' stroke-width='2'/%3E%3Cpath d='M15.5 15.5L21 21' stroke='%23006e52' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

.header-search-input,
.global-search-input {
    border: none !important;
    background: transparent !important;
    outline: none;
    font-size: 14px;
    color: var(--text-main);
    width: 100%;
    min-width: 120px;
    box-shadow: none !important;
}

.header-search-input::placeholder,
.global-search-input::placeholder {
    color: #8c9196;
}

.header-search:focus-within,
.global-search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== Global search results panel ===== */
.global-search-results {
    margin-bottom: 14px;
}

.global-search-results-card {
    background: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 12px 12px 10px;
    box-shadow: var(--shadow-soft);
}

.global-search-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.global-search-results-header .q {
    font-weight: 700;
    color: var(--text-main);
}

.global-search-results-groups {
    display: grid;
    gap: 10px;
}

.global-search-group-title {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.global-search-item {
    padding: 6px 0;
    border-top: 1px dashed var(--border);
}

.global-search-item:first-of-type { border-top: none; }

.global-search-item-main {
    font-size: 13px;
    font-weight: 600;
}

.global-search-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.global-search-results-empty {
    font-size: 13px;
    color: var(--text-muted);
}

/* ========= CARDS / GRID ========= */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.card {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.card::before { content: none; }

.card > * {
    position: relative;
    z-index: 1;
}

.card-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 7px;
}

.card-value {
    font-size: 25px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    margin-bottom: 3px;
}

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

/* ========= TABLES / BADGES ========= */
.users-toolbar {
    margin-top: 8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

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

.users-table-wrap,
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-panel);
    box-shadow: var(--shadow-soft);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.users-table thead {
    background: var(--bg-soft);
    color: var(--text-muted);
}

.users-table th {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.users-table th,
.users-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: center;
    white-space: nowrap;
}

.users-table tbody tr:hover {
    background: var(--bg-soft);
}

/* Global table sizing */
table {
    font-size: 13px !important;
    font-variant-numeric: tabular-nums;
}

table th,
table td {
    text-align: center !important;
    font-size: inherit !important;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-role-admin {
    background: var(--accent-tint);
    color: var(--accent-strong);
}

.badge-role-user {
    background: #eef0f2;
    color: #44474a;
}

.badge-status-active {
    background: var(--success-soft);
    color: #045c46;
}

.badge-status-inactive {
    background: #ffe9e4;
    color: #a01c00;
}

.users-error {
    margin-bottom: 8px;
    background: var(--danger-soft);
    color: #a01c00;
    border-radius: 4px;
    border: 1px solid #f3b7ab;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
}

.users-success {
    margin-bottom: 8px;
    background: var(--success-soft);
    color: #045c46;
    border-radius: 4px;
    border: 1px solid #8fdcc3;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
}

/* ========= MODAL ========= */
.user-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 33, 36, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.user-modal-backdrop.show {
    display: flex;
}

.user-modal {
    width: min(480px, 100%);
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    background: #ffffff;
    border-radius: 0;
    box-shadow: var(--shadow-pop);
    padding: 20px 20px 18px;
    border: 1px solid var(--border);
    animation: modal-in .22s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.user-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.user-modal-title {
    font-size: 16.5px;
    font-weight: 800;
}

.user-modal-close {
    border: 1px solid var(--border);
    background: #ffffff;
    border-radius: 4px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.user-modal-close:hover {
    background: var(--danger-soft);
    border-color: #f3b7ab;
    color: #a01c00;
}

.user-modal-form .field { margin-bottom: 13px; }

.user-modal-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 5px;
}

.user-modal-form input,
.user-modal-form select {
    width: 100%;
    padding: 10px 12px;
    min-height: 44px;
    border-radius: 4px;
    border: 1px solid var(--border-dark);
    font-size: 15px;
    outline: none;
    background: #ffffff;
}

.user-modal-form input:focus,
.user-modal-form select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.user-modal-footer {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.user-modal-error {
    margin-top: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #a01c00;
}

/* ========= BOTTOM NAVIGATION (mobile app bar) ========= */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-bottomnav);
    background: rgba(255, 255, 255, 0.97);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-inner {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    height: var(--bottom-nav-h);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border: none;
    background: transparent;
    cursor: pointer;
    min-height: 44px;
    padding: 6px 2px;
    position: relative;
    transition: color .15s ease;
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.8;
}

.bottom-nav-item.active {
    color: var(--accent-strong);
    font-weight: 700;
}

.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 34px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--accent);
}

.bottom-nav-item:active {
    color: var(--accent);
}

/* ========= RESPONSIVE CARD TABLES (mobile app style) =========
   On phones, tables become stacked cards: no horizontal scrolling.
   app.js assigns data-label (from thead) to each td and adds the
   .cards-mobile class to eligible tables. */
@media screen and (max-width: 900px) {
    .table-scroll,
    .users-table-wrap {
        overflow-x: hidden;
        border: none;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    table.cards-mobile {
        display: block !important;
        width: 100% !important;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    table.cards-mobile thead {
        display: none !important;
    }

    table.cards-mobile tbody,
    table.cards-mobile tfoot {
        display: block !important;
        width: 100%;
    }

    table.cards-mobile tr {
        display: block !important;
        background: var(--bg-panel) !important;
        border: 1px solid var(--border) !important;
        border-radius: 0 !important;
        margin: 0 0 10px !important;
        padding: 4px 14px !important;
        box-shadow: var(--shadow-soft);
    }

    table.cards-mobile tfoot tr {
        background: var(--bg-soft) !important;
        border-style: dashed !important;
    }

    table.cards-mobile td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        gap: 14px;
        text-align: right !important;
        white-space: normal !important;
        border: none !important;
        border-bottom: 1px dashed var(--border) !important;
        padding: 9px 0 !important;
        min-height: 38px;
        font-size: 13.5px !important;
        overflow-wrap: anywhere;
    }

    table.cards-mobile td:last-child {
        border-bottom: none !important;
    }

    table.cards-mobile td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: 11.5px;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        text-align: left;
        flex-shrink: 0;
        max-width: 46%;
    }

    table.cards-mobile td:not([data-label])::before,
    table.cards-mobile td[data-label=""]::before {
        content: none;
    }

    /* cells with no label (e.g. checkboxes) center their content */
    table.cards-mobile td[data-label=""] {
        justify-content: flex-end;
    }

    table.cards-mobile tr:hover {
        background: var(--bg-panel) !important;
    }

    /* Rows hidden by JS (pagination, search filters, collapsed detail rows)
       must stay hidden in card mode too */
    table.cards-mobile tr[style*="display: none"],
    table.cards-mobile tr[style*="display:none"] {
        display: none !important;
    }
}

/* ========= PRINT OVERRIDES ========= */
@media print {
    body {
        background: #ffffff;
        font-size: 14px;
    }
    .sidebar,
    .mobile-sidebar-toggle,
    .sidebar-backdrop,
    .bottom-nav,
    .subscription-alert,
    body.has-subscription-alert .subscription-alert {
        display: none !important;
    }
    .main {
        padding: 0;
        background: #ffffff;
    }
    .main-header {
        position: static;
        margin: 0 0 12px;
        box-shadow: none;
    }
    .card {
        box-shadow: none;
        border-radius: 0;
        border: 1px solid #e1e3e5;
    }
}

/* ========= Responsive: tablet & phone ========= */
@media (max-width: 900px) {
    .app-shell {
        position: relative;
        flex-direction: column;
    }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-104%);
        transition: transform .26s cubic-bezier(0.32, 0.72, 0, 1);
        width: min(84vw, 300px);
        max-width: 100%;
        box-shadow: 20px 0 50px rgba(31, 33, 36, 0.28);
        padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(14px + env(safe-area-inset-bottom, 0px)) 12px;
        border-radius: 0 0 0 0;
        border-right: 1px solid var(--border);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

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

    body.sidebar-open {
        overflow: hidden;
    }

    /* Main becomes app screen */
    .main {
        padding: 12px 14px calc(var(--bottom-nav-h) + 24px + env(safe-area-inset-bottom, 0px));
    }

    .main-header {
        margin: -12px -14px 14px;
        padding: 10px 14px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        top: 0;
        gap: 10px;
        flex-wrap: wrap;
    }

    .main-title-block {
        flex: 1;
        min-width: 0;
    }

    .main-title-block h1 {
        font-size: 16.5px;
    }

    .main-title-block p {
        font-size: 12px;
    }

    .main-header-right {
        gap: 8px;
        width: 100%;
        justify-content: stretch;
    }

    .header-search,
    .global-search {
        max-width: 100%;
        flex: 1;
    }

    .user-badge {
        display: none; /* identity lives in the sidebar drawer on mobile */
    }

    /* Top-left hamburger stays hidden on mobile — the bottom-nav
       Menu button is the single way to open the drawer */
    .mobile-sidebar-toggle {
        display: none;
    }

    /* Bottom app navigation */
    .bottom-nav {
        display: block;
    }

    /* Cards: tighter */
    .content-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 10px;
    }

    .card {
        padding: 13px 14px;
        border-radius: var(--radius);
    }

    .card-value {
        font-size: 20px;
    }

    /* Comfortable touch targets */
    .btn-sm {
        min-height: 38px;
        padding: 8px 14px;
    }
}

@media (min-width: 901px) {
    .sidebar-backdrop { display: none; }
    .bottom-nav { display: none !important; }
}

/* Phone-specific */
@media (max-width: 540px) {
    body { font-size: 14px; }

    /* Prevent iOS zoom-on-focus: inputs must be >=16px */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="date"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important;
    }

    .main {
        padding-left: 10px;
        padding-right: 10px;
    }

    .main-header {
        margin: -12px -10px 12px;
        padding: 10px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    .auth-panel {
        padding: 26px 20px 22px;
    }

    .user-modal {
        padding: 18px 16px 16px;
    }

    .content-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Collapsible subnav */
.sidebar-subnav.collapsed {
    display: none;
}

.sidebar-nav [data-sidebar-toggle] .chevron {
    transition: transform .18s ease;
}

.sidebar-nav [data-sidebar-toggle].sidebar-toggle-open .chevron {
    transform: rotate(90deg);
}
