/* public/assets/css/app.css
   AB Shipping back office — "ledger" design system.

   Direction (ui-ux-pro-max: Logistics → Minimalism & Swiss + Flat, data-dense tables):
   the screen should read like a well-kept shipping ledger, not a set of floating tiles.
   - flat surfaces, hairline rules, square-ish corners, no decorative shadows or gradients
   - one accent (brand red) for the primary action and the current place only
   - IBM Plex Sans for text (with Arabic), IBM Plex Mono for numbers, codes and tracking ids
   - text left, numbers right, dense rows
   Page styles must use these tokens, not raw values. */

/* Fonts are linked from includes/header.php (non-blocking); never @import them here. */

:root {
    /* surfaces */
    --bg-body: #f4f2ee;
    --bg-panel: #ffffff;
    --bg-soft: #f8f7f4;
    --bg-sunken: #eeebe5;

    /* text */
    --text-main: #1b1917;
    --text-muted: #5f5850;
    --text-faint: #8f877e;

    /* rules */
    --border: #e2ddd5;
    --border-strong: #cdc6bb;
    --rule: #1b1917;

    /* single accent: brand red */
    --accent: #d7261e;
    --accent-strong: #ad1a12;
    --accent-rgb: 215, 38, 30;
    --accent-soft: rgba(215, 38, 30, 0.14);
    --accent-tint: #fbeeed;

    /* neutral series (charts, secondary chips) */
    --accent-2: #857b70;
    --accent-2-rgb: 133, 123, 112;
    --accent-amber: #857b70;

    --ink: #1b1917;
    --ink-rgb: 27, 25, 23;
    --ink-soft: #2a2724;

    /* status (logistics: amber = on the way, green = delivered/paid, red = problem) */
    --danger: #b3261e;
    --danger-soft: #fbeceb;
    --success: #1c6b45;
    --success-soft: #e7f2ec;
    --warning: #8a5300;
    --warning-soft: #fdf3df;
    --info: #2b587f;
    --info-soft: #e8eff6;

    /* shape */
    --radius: 4px;
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-pill: 4px;

    /* depth: only overlays float */
    --shadow-soft: none;
    --shadow-pop: 0 12px 40px rgba(27, 25, 23, 0.18), 0 2px 6px rgba(27, 25, 23, 0.08);
    --panel-glow: none;
    --focus-ring: 0 0 0 3px rgba(215, 38, 30, 0.2);

    /* type */
    --font-sans: 'IBM Plex Sans', 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

    --t-fast: 120ms;
    --t-base: 180ms;
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

    --sidebar-width: 232px;
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text-main);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
    font-family: inherit;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.25;
    margin: 0;
    color: var(--text-main);
}

p {
    margin: 0;
}

a {
    color: var(--text-main);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
}

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

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

button {
    touch-action: manipulation;
}

code,
kbd,
.mono {
    font-family: var(--font-mono);
    font-size: 0.93em;
}

::selection {
    background: rgba(var(--accent-rgb), 0.2);
}

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

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

.muted {
    color: var(--text-muted);
}

/* ========= Page loader: a thin progress line, not a full-screen curtain ========= */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    height: 3px;
    background: transparent;
    z-index: 9999;
    overflow: hidden;
    pointer-events: none;
    transition: opacity var(--t-base) ease;
}

.page-loader::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -40%;
    width: 40%;
    background: var(--accent);
    animation: loader-slide 1s ease-in-out infinite;
}

.page-loader .spinner {
    display: none;
}

.page-loader.hidden {
    opacity: 0;
}

@keyframes loader-slide {
    to {
        left: 100%;
    }
}

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

.subscription-alert {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 120;
    margin: 0 auto;
    padding: 10px 16px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border: 1px solid #e6c17a;
    border-top: none;
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 14px;
    display: none;
    max-width: 1180px;
}

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

/* ========= AUTH / LOGIN ========= */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg-body);
}

.auth-panel {
    width: min(400px, 100%);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: 3px solid var(--rule);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 28px 28px 22px;
}

.auth-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.auth-logo-circle {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #ffffff;
    font-size: 18px;
    flex-shrink: 0;
}

.auth-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.auth-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 2px;
}

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

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

.auth-form input[type="text"],
.auth-form input[type="password"],
.auth-form input[type="email"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    font-size: 16px;
    outline: none;
    background: var(--bg-panel);
}

.auth-form input:focus {
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.auth-form .error-box {
    background: var(--danger-soft);
    color: var(--danger);
    border-left: 3px solid var(--danger);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 9px 12px;
    font-size: 14px;
    margin-bottom: 12px;
}

.auth-form .actions {
    margin-top: 6px;
    display: flex;
    gap: 12px;
}

.auth-form .actions .btn-primary {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
}

.auth-footer-note {
    margin-top: 18px;
    font-size: 12.5px;
    color: var(--text-faint);
    white-space: pre-line;
}

/* ========= BUTTONS: rectangular, flat ========= */
.btn-primary {
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    min-height: 36px;
    padding: 7px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: none;
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease;
}

.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: #ffffff;
    text-decoration: none;
    transform: none;
    filter: none;
    box-shadow: none;
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary[disabled],
.btn-primary.is-loading {
    opacity: 0.5;
    cursor: default;
}

.btn-secondary,
.btn-sm {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-panel);
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    text-decoration: none;
    box-shadow: none;
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
}

.btn-secondary {
    min-height: 36px;
    padding: 7px 14px;
    font-size: 14px;
}

.btn-sm {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 13px;
}

.btn-secondary:hover,
.btn-sm:hover {
    background: var(--bg-soft);
    border-color: var(--text-main);
    color: var(--text-main);
    text-decoration: none;
}

.btn-sm[disabled],
.btn-secondary[disabled] {
    opacity: 0.5;
    cursor: default;
}

/* .btn-sm.btn-primary is used by a few pages for compact primary actions */
.btn-sm.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

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

.btn-sm-danger {
    border-color: transparent;
    background: transparent;
    color: var(--danger);
}

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

/* ========= FORMS ========= */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="password"],
input[type="date"],
select,
textarea {
    border: 1px solid var(--border-strong);
    background: var(--bg-panel);
    color: var(--text-main);
    border-radius: var(--radius);
    transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

input[type="number"] {
    font-family: var(--font-mono);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-faint);
    opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: var(--focus-ring) !important;
    background: #ffffff;
    outline: none;
}

input[disabled],
select[disabled],
textarea[disabled] {
    background: var(--bg-sunken);
    color: var(--text-muted);
}

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

/* ---- Sidebar: ink column, text-first navigation ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--ink);
    color: #cfc9c0;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
    flex-shrink: 0;
    border-right: none;
    box-shadow: none;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #4a4540 transparent;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 16px 16px 14px;
    border-bottom: 1px solid #34302c;
}

.sidebar-logo-circle {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: #ffffff;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-logo-circle img,
.auth-logo-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}
.auth-logo-circle {
    overflow: hidden;
}
.auth-logo-circle[data-has-logo],
.sidebar-logo-circle[data-has-logo] {
    background: #ffffff;
}
.auth-logo-circle[data-has-logo] {
    border: 1px solid var(--border);
}

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

.sidebar-company-name {
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-company-sub {
    font-size: 11.5px;
    color: #9d968c;
}

.sidebar-profile,
.sidebar-cta {
    display: none;
}

.sidebar-nav {
    margin: 0;
    padding: 6px 0 12px;
    flex: 1;
}

.sidebar-nav-heading {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #857d73;
    padding: 16px 16px 6px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 16px 6px 13px;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0;
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
    color: #cfc9c0;
    margin: 0;
    position: relative;
    transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

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

.sidebar-nav a span.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    width: 18px;
    height: 18px;
    border-radius: 0;
    background: transparent;
    color: #857d73;
    flex-shrink: 0;
}

.sidebar-nav a .chevron {
    margin-left: auto;
    font-size: 15px;
    line-height: 1;
    color: #6f685f;
}

.sidebar-nav a:hover {
    background: var(--ink-soft);
    color: #ffffff;
    transform: none;
    box-shadow: none;
}

.sidebar-nav a:hover span.icon {
    color: #cfc9c0;
}

.sidebar-nav a.active {
    background: var(--ink-soft);
    color: #ffffff;
    font-weight: 600;
    border-left-color: var(--accent);
    box-shadow: none;
}

.sidebar-nav a.active .icon {
    background: transparent;
    color: #ffffff;
}

/* an open group header is just a label; its child carries the marker */
.sidebar-nav a.sidebar-toggle-open {
    background: transparent;
    border-left-color: transparent;
    color: #ffffff;
    font-weight: 500;
}

.sidebar-section {
    margin: 0;
    padding: 0;
    border: none;
}

.sidebar-section-label {
    display: none;
}

.sidebar-subnav {
    margin: 0 0 4px;
    padding: 0;
}

.sidebar-subnav a {
    font-size: 13.5px;
    min-height: 30px;
    padding-left: 41px;
    color: #a9a298;
    background: transparent;
}

.sidebar-nav .sidebar-subnav a span.icon {
    display: none;
}

/* Admin > Users sits at top level, so it keeps its icons */
.sidebar-section .sidebar-subnav a {
    padding-left: 13px;
    font-size: 14px;
    min-height: 34px;
    color: #cfc9c0;
}

.sidebar-nav .sidebar-section .sidebar-subnav a span.icon {
    display: inline-flex;
}

.sidebar-highlight-box {
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: none;
}

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

.sidebar-footer {
    margin: 0;
    border-top: 1px solid #34302c;
    padding: 12px 16px 14px;
    font-size: 12px;
    line-height: 1.45;
    color: #857d73;
}

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

.sidebar-logout-form button {
    width: 100%;
    min-height: 34px;
    border-radius: var(--radius);
    border: 1px solid #4a4540;
    padding: 6px 0;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: #cfc9c0;
    cursor: pointer;
    transition: background-color var(--t-fast) ease, color var(--t-fast) ease, border-color var(--t-fast) ease;
}

.sidebar-logout-form button:hover {
    background: var(--ink-soft);
    border-color: #857d73;
    color: #ffffff;
    box-shadow: none;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(27, 25, 23, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) ease;
    z-index: 20;
}

/* ---- Main column ---- */
.main {
    flex: 1;
    padding: 0 32px 40px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-body);
}

/* Page head: title on the left, tools on the right, one heavy rule under it */
.main-header {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    margin: 0 0 20px;
    padding: 22px 0 14px;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--rule);
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
}

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

.main-title-block h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.main-title-block p {
    margin: 3px 0 0;
    font-size: 14px;
    color: var(--text-muted);
    max-width: 70ch;
}

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

/* who is signed in: plain text, role as a small mono tag */
.user-badge {
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    white-space: nowrap;
}

.user-badge-role {
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.08em;
}

.mobile-sidebar-toggle {
    display: none;
    min-height: 44px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--bg-panel);
    padding: 9px 12px;
    font-size: 14px;
    font-weight: 600;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    color: var(--text-main);
    box-shadow: none;
}

.mobile-sidebar-toggle .icon {
    width: 18px;
    height: 18px;
    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;
    background: var(--text-main);
}

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

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

/* ---- Search field (top bar + dashboard) ---- */
.header-search,
.global-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 4px 10px;
    border-radius: var(--radius);
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    box-shadow: none;
    max-width: 340px;
    width: 100%;
    font-size: 14px;
    transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

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

.header-search-icon,
.global-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 0;
    background: transparent;
    font-size: 0;
    position: relative;
}

.header-search-icon::before,
.global-search-icon::before {
    content: '';
    width: 15px;
    height: 15px;
    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='%235f5850' stroke-width='2'/%3E%3Cpath d='M15.5 15.5L21 21' stroke='%235f5850' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

.header-search-input,
.global-search-input,
.header-search input[type="text"],
.global-search input[type="text"] {
    border: none !important;
    background: transparent;
    padding: 0;
    border-radius: 0;
    outline: none;
    font-size: 14px;
    color: var(--text-main);
    width: 100%;
    min-width: 160px;
    box-shadow: none !important;
}

.header-search:focus-within,
.global-search:focus-within {
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
    transform: none;
    background: var(--bg-panel);
}

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

.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: 600;
    color: var(--text-main);
}

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

.global-search-group-title {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 4px;
}

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

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

.global-search-item-main {
    font-size: 14px;
    font-weight: 500;
}

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

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

/* ========= PANELS (class name .card kept for the pages) ========= */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

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

.card::before {
    content: none;
}

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

.card-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1px;
    letter-spacing: -0.005em;
}

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

.card-value {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

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

/* ========= TABLES: text left, numbers right, dense ========= */
.users-toolbar,
.table-toolbar {
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

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

.users-table-wrap,
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--rule);
    background: var(--bg-panel);
    box-shadow: none;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

table {
    font-size: 13.5px !important;
    font-variant-numeric: tabular-nums;
}

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

table th {
    font-size: 12px !important;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
    color: var(--text-muted);
    white-space: nowrap;
}

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

/* numeric columns are tagged by app.js (tagNumericCells) */
table td.num,
table th.num {
    text-align: end !important;
}

table td.num {
    font-family: var(--font-mono);
    font-size: 13px !important;
}

/* dates and timestamps stay on one line */
table td.cell-date {
    font-family: var(--font-mono);
    font-size: 12.5px !important;
    white-space: nowrap;
    color: var(--text-muted);
}

/* last column usually holds row actions */
table td.cell-actions,
table th.cell-actions {
    text-align: end !important;
    white-space: nowrap;
}

/* empty / loading rows span the table and stay centred */
table td[colspan]:only-child {
    text-align: center !important;
}

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

.users-table thead th {
    border-bottom-color: var(--border-strong);
}

.users-table tbody tr:nth-child(even),
table tbody tr:nth-child(even) {
    background: transparent;
}

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

/* ---- status tags: small rectangles, readable without colour ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 7px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    border: 1px solid transparent;
}

.badge-role-admin {
    background: var(--ink);
    color: #ffffff;
}

.badge-role-user {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-main);
}

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

.badge-status-inactive {
    background: var(--danger-soft);
    color: var(--danger);
}

.users-error,
.users-success {
    margin-bottom: 10px;
    border-radius: 0 var(--radius) var(--radius) 0;
    border: none;
    border-left: 3px solid;
    padding: 9px 12px;
    font-size: 14px;
}

.users-error {
    background: var(--danger-soft);
    color: var(--danger);
    border-left-color: var(--danger);
}

.users-success {
    background: var(--success-soft);
    color: var(--success);
    border-left-color: var(--success);
}

/* ========= EMPTY STATES: a sentence and a next step ========= */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--text-muted);
    white-space: normal;
}

.empty-state-icon {
    display: none;
}

.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 2px;
}

.empty-state-text {
    font-size: 14px;
    max-width: 440px;
    margin: 0 auto;
}

.empty-state-actions {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

table td.muted,
.exp-empty,
.inc-empty,
.gov-empty {
    color: var(--text-muted);
}

/* ========= MODAL ========= */
.user-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(27, 25, 23, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 16px;
}

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

.user-modal {
    width: min(480px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    border-top: 3px solid var(--rule);
    box-shadow: var(--shadow-pop);
    padding: 18px 20px 16px;
    animation: modal-in var(--t-base) var(--ease-out);
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.user-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.user-modal-title {
    font-size: 17px;
    font-weight: 600;
}

.user-modal-close {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--text-muted);
}

.user-modal-close:hover {
    background: var(--bg-sunken);
    color: var(--text-main);
}

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

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

.user-modal-form input,
.user-modal-form select {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    font-size: 14px;
    outline: none;
    background: var(--bg-panel);
}

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

.user-modal-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.user-modal-error {
    margin-top: 4px;
    font-size: 13px;
    color: var(--danger);
}

/* ========= Reduced motion ========= */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========= PRINT ========= */
@media print {
    body {
        background: #ffffff;
        font-size: 14px;
    }
    .sidebar,
    .mobile-sidebar-toggle,
    .sidebar-backdrop,
    .page-loader {
        display: none !important;
    }
    .main {
        padding: 0;
        background: #ffffff;
    }
    .card {
        border-radius: 0;
        border: 1px solid #e2e8f0;
    }
    .subscription-alert,
    body.has-subscription-alert .subscription-alert {
        display: none !important;
    }
}

/* ========= Responsive ========= */
@media (max-width: 1100px) {
    .main {
        padding: 0 20px 32px;
    }
}

@media (max-width: 900px) {
    .app-shell {
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: auto;
        transform: translateX(-100%);
        transition: transform var(--t-base) var(--ease-out);
        width: min(84vw, 300px);
        box-shadow: var(--shadow-pop);
        padding-top: env(safe-area-inset-top, 0);
    }

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

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

    .sidebar-nav a {
        min-height: 44px;
    }

    .sidebar-subnav a {
        min-height: 40px;
    }

    .main {
        padding: 0 16px 28px;
    }

    .main-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding-top: 14px;
    }

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

    .main-header-right {
        justify-content: space-between;
        width: 100%;
        flex-wrap: wrap;
        margin-left: 0;
    }

    .header-search,
    .global-search {
        max-width: 100%;
        min-height: 44px;
    }

    .mobile-sidebar-toggle {
        display: inline-flex;
        justify-content: space-between;
        width: 100%;
    }

    .btn-primary,
    .btn-secondary {
        min-height: 44px;
    }

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

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

@media (max-width: 540px) {
    .sidebar {
        width: 100vw;
    }
    .card {
        padding: 14px;
    }
}

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

.sidebar-nav [data-sidebar-toggle] .chevron {
    transition: transform var(--t-fast) ease;
}

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

/* =====================================================================
   PHONE: behaves like an app
   - bottom tab bar for the places used all day, "More" opens the full menu
   - compact sticky app bar with the page title
   - tables become stacked cards (labels come from app.js), no sideways scrolling
   - dialogs slide up as bottom sheets; inputs are 16px so iOS never zooms
   ===================================================================== */
.bottom-nav,
.sidebar-close {
    display: none;
}

@media (max-width: 900px) {
    html {
        scroll-padding-top: 64px;
    }

    .bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 15;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        background: var(--bg-panel);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .bottom-nav a,
    .bottom-nav button {
        min-height: 56px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 2px;
        border: none;
        background: transparent;
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 500;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav a span,
    .bottom-nav button span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .bottom-nav a.active {
        color: var(--accent);
        font-weight: 600;
        box-shadow: inset 0 2px 0 var(--accent);
    }

    .bottom-nav a:active,
    .bottom-nav button:active {
        background: var(--bg-soft);
    }

    body.sidebar-open .bottom-nav button[data-open-sidebar] {
        color: var(--text-main);
    }

    /* the menu drawer */
    .sidebar {
        z-index: 50;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .sidebar-backdrop {
        z-index: 45;
    }

    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: calc(10px + env(safe-area-inset-top, 0));
        right: 8px;
        width: 44px;
        height: 44px;
        border: none;
        border-radius: var(--radius);
        background: transparent;
        color: #cfc9c0;
        font-size: 26px;
        line-height: 1;
        cursor: pointer;
    }

    .sidebar-brand {
        padding-right: 56px;
    }

    /* room for the tab bar */
    .main {
        padding-bottom: calc(76px + env(safe-area-inset-bottom, 0));
    }

    /* app bar */
    .mobile-sidebar-toggle {
        display: none !important;
    }

    .main-header {
        position: sticky;
        top: 0;
        z-index: 12;
        margin: 0 -16px 14px;
        padding: calc(10px + env(safe-area-inset-top, 0)) 16px 10px;
        background: var(--bg-body);
        border-bottom: 2px solid var(--rule);
        gap: 8px;
    }

    .main-title-block h1 {
        font-size: 20px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .main-title-block p {
        font-size: 13px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .main-header-right {
        gap: 8px;
    }

    .main-header-right .user-badge {
        display: none;
    }

    .main-header-right > a,
    .main-header-right > button {
        flex: 1 1 auto;
    }

    .content-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .content-grid > * {
        grid-column: 1 / -1 !important;
        min-width: 0;
    }

    /* forms: thumb-sized, no zoom on focus */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="search"],
    input[type="password"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
        min-height: 44px;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }

    /* dialogs become bottom sheets */
    .user-modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .user-modal {
        width: 100% !important;
        max-width: none;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 14px 14px 0 0;
        border-top: none;
        padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0));
        animation: sheet-in var(--t-base) var(--ease-out);
    }

    .user-modal::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        margin: 0 auto 10px;
        border-radius: 2px;
        background: var(--border-strong);
    }

    .user-modal-footer {
        position: sticky;
        bottom: calc(-16px - env(safe-area-inset-bottom, 0));
        margin: 16px -16px calc(-16px - env(safe-area-inset-bottom, 0));
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
        background: var(--bg-panel);
    }

    .user-modal-footer > * {
        flex: 1 1 0;
    }
}

@keyframes sheet-in {
    from {
        transform: translateY(24px);
        opacity: 0;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

/* ---- tables as cards on phones ---- */
@media screen and (max-width: 640px) {
    .users-table-wrap,
    .table-wrap {
        overflow: visible;
        border-top: none;
        background: transparent;
    }

    table.stackable {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        border: none !important;
    }

    table.stackable thead {
        display: none;
    }

    table.stackable tbody,
    table.stackable tr {
        display: block;
        width: 100%;
    }

    table.stackable tr {
        width: 100% !important;
        box-sizing: border-box;
        margin: 0 0 10px;
        padding: 2px 12px;
        background: var(--bg-panel);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
    }

    table.stackable tbody tr:hover {
        background: var(--bg-panel);
    }

    table.stackable td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        box-sizing: border-box;
        min-height: 40px;
        padding: 8px 0 !important;
        border: none !important;
        border-bottom: 1px solid var(--border) !important;
        text-align: end !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    table.stackable tr td:last-child {
        border-bottom: none !important;
    }

    table.stackable td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        font-family: var(--font-sans);
        font-size: 12px;
        font-weight: 600;
        color: var(--text-muted);
        text-align: start;
        white-space: normal;
    }

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

    table.stackable td[colspan] {
        display: block;
        text-align: center !important;
    }

    table.stackable td[colspan]::before {
        content: none;
    }

    table.stackable td.cell-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
    }

    table.stackable td.cell-actions .btn-sm,
    table.stackable td.cell-actions button,
    table.stackable td.cell-actions a {
        min-height: 40px;
        padding-left: 14px;
        padding-right: 14px;
    }

    table.stackable tr.empty-row,
    table.stackable tr.empty-row td {
        border: none !important;
        background: transparent;
    }
}

@media print {
    .bottom-nav,
    .sidebar-close {
        display: none !important;
    }
}

/* ========= TABS ========= */
/* <div class="tabs" role="tablist"> <button class="tab" role="tab" aria-selected> ... */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-strong);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 8px 14px;
    margin-bottom: -1px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--t-fast) ease, border-color var(--t-fast) ease;
}

.tab:hover {
    color: var(--text-main);
}

.tab[aria-selected="true"] {
    color: var(--text-main);
    font-weight: 600;
    border-bottom-color: var(--accent);
}

.tab-count {
    padding: 0 6px;
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.6;
}

.tab[aria-selected="true"] .tab-count {
    background: var(--ink);
    color: #ffffff;
}

.tab-panel[hidden] {
    display: none !important;
}

@media (max-width: 900px) {
    .tabs {
        margin: 0 -16px;
        padding: 0 12px;
        background: var(--bg-body);
    }

    .tab {
        min-height: 46px;
    }
}

@media print {
    .tabs {
        display: none !important;
    }
    .tab-panel[hidden] {
        display: block !important;
    }
}

/* Range rules editor (assets/js/range-rules.js): Settings package weights, AB Coins earning rules */
.custom-rules-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.custom-rule {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.rule-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}
.rule-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.rule-inputs input[type="number"] {
    width: 90px;
    padding: 6px 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: #ffffff;
    font-size: 13px;
}
.rule-sep {
    color: var(--text-muted);
    font-size: 12px;
}
.rule-else {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}
.rule-delete {
    color: #ef4444;
    font-size: 12px;
    border: 1px solid #fecdd3;
    background: #fff1f2;
    border-radius: var(--radius);
    padding: 4px 8px;
    cursor: pointer;
}

/* Toggle switch: <label class="switch"><input type="checkbox" role="switch"><span class="switch-knob"></span></label> */
.switch {
    position: relative;
    display: inline-flex;
    flex: none;
    width: 44px;
    height: 24px;
}
.switch input {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
    cursor: pointer;
    transition: background-color .18s ease;
}
.switch input:checked { background: var(--success); }
.switch input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; opacity: .45; }
.switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(var(--ink-rgb), .25);
    pointer-events: none;
    transition: transform .18s cubic-bezier(.2, .8, .2, 1);
}
.switch input:checked + .switch-knob { transform: translateX(20px); }
[dir="rtl"] .switch input:checked + .switch-knob { transform: translateX(-20px); }
[dir="rtl"] .switch-knob { left: auto; right: 3px; }
@media (prefers-reduced-motion: reduce) {
    .switch input, .switch-knob { transition: none; }
}
