/* ==========================================================================
   Bookkeeping — Design System
   Mobile-first, tokenized, light/dark themes, fully responsive.
   ========================================================================== */

/* ---------- Design tokens (light, default) ---------- */
:root {
    /* Color palette */
    --primary: #1f6feb;
    --primary-hover: #1a5fd4;
    --primary-soft: #dbeafe;
    --primary-soft-text: #1e40af;

    --success: #16a34a;
    --success-soft: #dcfce7;
    --success-soft-text: #166534;

    --warning: #d97706;
    --warning-soft: #fef3c7;
    --warning-soft-text: #92400e;

    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --danger-soft-text: #991b1b;

    --info: #0284c7;
    --info-soft: #e0f2fe;
    --info-soft-text: #075985;

    --neutral-soft: #f1f5f9;
    --neutral-soft-text: #475569;

    /* Surfaces */
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-hover: #f1f5f9;

    /* Text */
    --text: #0f172a;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders & shadow */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --ring: #93c5fd;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);

    /* Sidebar (always dark, even in light theme) */
    --sidebar-bg: #0f172a;
    --sidebar-bg-2: #0b1220;
    --sidebar-text: #cbd5e1;
    --sidebar-text-muted: #64748b;
    --sidebar-border: #1e293b;
    --sidebar-hover: #1e293b;
    --sidebar-active-bg: rgba(31, 111, 235, 0.18);
    --sidebar-active-text: #ffffff;
    --sidebar-accent: #3b82f6;

    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;

    /* Layout */
    --sidebar-width: 248px;
    --topbar-height: 60px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    color-scheme: light;
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.15);
    --primary-soft-text: #93c5fd;

    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.15);
    --success-soft-text: #86efac;

    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.15);
    --warning-soft-text: #fcd34d;

    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.15);
    --danger-soft-text: #fca5a5;

    --info: #38bdf8;
    --info-soft: rgba(56, 189, 248, 0.15);
    --info-soft-text: #7dd3fc;

    --neutral-soft: #1f2937;
    --neutral-soft-text: #cbd5e1;

    --bg: #0b1220;
    --surface: #111827;
    --surface-2: #0f172a;
    --surface-hover: #1e293b;

    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --text-inverse: #0f172a;

    --border: #1f2937;
    --border-strong: #334155;
    --ring: #2563eb;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);

    --sidebar-bg: #050a14;
    --sidebar-bg-2: #020409;
    --sidebar-text: #94a3b8;
    --sidebar-text-muted: #475569;
    --sidebar-border: #0f172a;
    --sidebar-hover: #0f172a;
    --sidebar-active-bg: rgba(59, 130, 246, 0.25);
    --sidebar-active-text: #ffffff;
    --sidebar-accent: #60a5fa;

    color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}
img, svg { display: block; max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
hr { border: 0; border-top: 1px solid var(--border); }

/* ---------- Focus ring (accessibility) ---------- */
:focus { outline: none; }
:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------- Skip link ---------- */
.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    background: var(--primary);
    color: var(--text-inverse);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    z-index: 1000;
    transition: top var(--transition);
}
.skip-link:focus { top: 8px; text-decoration: none; color: var(--text-inverse); }

/* ---------- App shell ---------- */
.layout-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding: 0;
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: transform var(--transition-slow);
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, var(--sidebar-accent) 100%);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-title {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.sidebar-subtitle {
    font-size: 11px;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--sidebar-border) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 3px; }

.sidebar-group {
    margin-bottom: 16px;
}

.sidebar-group-label {
    padding: 8px 12px 6px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--sidebar-text-muted);
    letter-spacing: 0.06em;
    font-weight: 600;
}

.sidebar a,
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--radius-md);
    margin: 1px 0;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.sidebar a:hover,
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.sidebar a[aria-current="page"],
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}
.sidebar a[aria-current="page"]::before,
.sidebar-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--sidebar-accent);
    border-radius: 0 2px 2px 0;
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-width: 1.8;
    color: currentColor;
    opacity: 0.85;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: background var(--transition), color var(--transition);
}
.sidebar-logout:hover {
    background: var(--danger-soft);
    color: var(--danger-soft-text);
    text-decoration: none;
}

/* ---------- Sidebar overlay (mobile) ---------- */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 55;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}
.sidebar-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* ---------- Main column ---------- */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(8px);
}

.topbar-menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.topbar-menu-toggle:hover { background: var(--surface-hover); }

.topbar-brand-mobile {
    display: none;
    font-weight: 700;
    color: var(--text);
    font-size: 15px;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-spacer { flex: 1; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px 4px 12px;
    border-radius: var(--radius-md);
    position: relative;
}

.user-menu-compact {
    padding: 4px 8px 4px 4px;
    gap: 4px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
}
.user-menu-compact:hover,
.user-menu-compact[aria-expanded="true"] {
    background: var(--surface-2);
    border-color: var(--border);
}
.user-menu-compact .user-avatar {
    width: 30px;
    height: 30px;
    font-size: 12px;
}
.user-menu-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
    margin-right: 2px;
    transition: transform 150ms ease;
}
.user-menu-compact[aria-expanded="true"] .user-menu-chevron {
    transform: rotate(180deg);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-soft-text);
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
}
.user-info { text-align: right; }
.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.topbar-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    padding: 6px;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}
.dropdown-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 13.5px;
    text-align: left;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
}
.dropdown-item:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 4px;
}

.dropdown-label {
    padding: 8px 12px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    font-weight: 600;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.theme-option:hover { background: var(--surface-hover); }
.theme-option[aria-checked="true"] {
    background: var(--primary-soft);
    color: var(--primary-soft-text);
    font-weight: 500;
}
.theme-option svg { width: 16px; height: 16px; }
.theme-option .check { margin-left: auto; opacity: 0.7; }

/* ---------- Content area ---------- */
.content {
    padding: 24px;
    flex: 1;
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.page-title--sm { font-size: 16px; }
.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}
.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .page-header-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .page-actions {
        margin-top: 8px;
    }
}

.danger-divider {
    border: 0;
    border-top: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
    margin: 32px 0 20px;
}

/* ---------- Card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-xs);
    margin-bottom: 20px;
    transition: background var(--transition), border-color var(--transition);
}
.card:last-child { margin-bottom: 0; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.card-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.card h1 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.card h2 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.card h3 { font-size: 14px; font-weight: 600; color: var(--text); margin: 16px 0 8px; }
.card p { color: var(--text-muted); font-size: 14px; }
.card.text-center { text-align: center; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    line-height: 1;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); filter: brightness(0.92); color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-icon {
    width: 36px;
    padding: 0;
    flex-shrink: 0;
}

.btn-sm, button.btn-sm {
    height: 30px;
    padding: 0 10px;
    font-size: 12.5px;
}
.btn-lg {
    height: 44px;
    padding: 0 20px;
    font-size: 15px;
}
.btn-block { width: 100%; }

.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--primary);
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    font-size: inherit;
    text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }

button.btn-link, button.btn-link-sm {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}

/* Loading spinner inside button */
.btn .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label,
.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.form-group label.required::after,
.form-label.required::after {
    content: " *";
    color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea,
.form-control {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.form-group textarea, .form-control[type="textarea"], textarea.form-control {
    height: auto;
    min-height: 80px;
    padding: 10px 12px;
    line-height: 1.5;
    resize: vertical;
}
.form-group select, select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    appearance: none;
}
:root[data-theme="dark"] .form-group select,
:root[data-theme="dark"] select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-control.is-invalid,
.form-group input.is-invalid,
.form-group select.is-invalid,
.form-group textarea.is-invalid {
    border-color: var(--danger);
}
.form-control.is-invalid:focus,
.form-group input.is-invalid:focus,
.form-group select.is-invalid:focus,
.form-group textarea.is-invalid:focus {
    box-shadow: 0 0 0 3px var(--danger-soft);
}
.form-help {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.form-error {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--danger);
}
input[type="checkbox"], input[type="radio"] {
    width: auto;
    height: auto;
    accent-color: var(--primary);
    cursor: pointer;
}
select[readonly], input[readonly], textarea[readonly] {
    background: var(--surface-2);
    color: var(--text-muted);
}

/* Password field with inline show/hide toggle */
.password-field { position: relative; }
.password-field .form-control { padding-right: 44px; }
.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    display: grid;
    place-items: center;
    transition: background var(--transition), color var(--transition);
}
.password-toggle:hover { background: var(--surface-hover); color: var(--text); }

/* Readonly inputs in line-item tables (used by JS-generated rows) */
.lines-table input[readonly] {
    background: var(--surface-2);
    color: var(--text-muted);
    border-color: var(--border);
}
.lines-table .cell-narrow input { width: 80px; text-align: right; }
.lines-table .cell-price input { width: 120px; text-align: right; }

/* Inline form rows (date pickers, search bars) */
.form-inline {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.form-inline .form-group { margin-bottom: 0; flex: 0 0 auto; }
.form-inline label { margin-bottom: 0; margin-right: 4px; color: var(--text-muted); font-size: 12.5px; }
.form-inline input, .form-inline select { height: 36px; }
.form-inline .btn { height: 36px; }
.form-inline .form-control { width: auto; min-width: 160px; flex: 0 0 auto; }

/* Form grids (responsive) */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
.form-grid-2 { grid-template-columns: 1fr; }
.form-grid-3 { grid-template-columns: 1fr; }
.form-grid-4 { grid-template-columns: 1fr; }

.form-grid-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 8px;
}

/* Keep legacy grid classes working */
.grid { display: grid; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.gap-16 { gap: 16px; } .gap-20 { gap: 20px; } .gap-24 { gap: 24px; }
.gap-32 { gap: 32px; }
.grid-col-span-2 { grid-column: span 1; }

/* ---------- Toolbar / filters ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex: 1; min-width: 0; }

/* Toolbar form controls sit inline; don't stretch to 100% width. */
.toolbar .form-control {
    width: auto;
    min-width: 160px;
    flex: 0 0 auto;
}
.toolbar .toolbar-search {
    position: relative;
    flex: 1 1 200px;
    min-width: 200px;
    max-width: 360px;
}

.toolbar-search input { padding-left: 36px; padding-right: 32px; }
.toolbar-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.toolbar-search .search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.toolbar-search.has-value .search-clear { display: inline-flex; }
.toolbar-search .search-clear:hover { background: var(--surface-hover); color: var(--text); }
.toolbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
}

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

thead th {
    background: var(--surface-2);
    padding: 11px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
thead th.text-right { text-align: right; }

tbody td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text);
    vertical-align: middle;
}
tbody td a { font-weight: 500; }
tbody td a.text-muted, tbody td .text-muted { font-weight: 400; }

tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-hover); }

tfoot td {
    padding: 12px 14px;
    font-weight: 600;
    background: var(--surface-2);
    border-top: 2px solid var(--border-strong);
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-normal { font-weight: 400; }

.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 22px; }

.text-muted { color: var(--text-muted); }
.text-dark { color: var(--text); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.text-primary { color: var(--primary); }

.bg-success { background: var(--success-soft); }
.bg-warning { background: var(--warning-soft); }
.bg-danger { background: var(--danger-soft); }
.bg-muted { background: var(--surface-2); }
.bg-info { background: var(--info-soft); }

.border { border: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-t { border-top: 2px solid var(--border-strong); }
.border-r { border-right: 1px solid var(--border); }

.rounded { border-radius: var(--radius-md); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: 999px; }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Status / Badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    text-transform: capitalize;
    border: 1px solid transparent;
}
.badge-success { background: var(--success-soft); color: var(--success-soft-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-soft-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-soft-text); }
.badge-info { background: var(--info-soft); color: var(--info-soft-text); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral-soft-text); }
.badge-primary { background: var(--primary-soft); color: var(--primary-soft-text); }
.badge-secondary { background: var(--neutral-soft); color: var(--neutral-soft-text); }

/* status shortcuts (replaces inline style badges) */
.status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: capitalize;
    line-height: 1.5;
}
.status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.status-draft, .status-pending { background: var(--warning-soft); color: var(--warning-soft-text); }
.status-posted, .status-completed, .status-success, .status-active { background: var(--success-soft); color: var(--success-soft-text); }
.status-cancelled, .status-failed { background: var(--danger-soft); color: var(--danger-soft-text); }
.status-in { background: var(--success-soft); color: var(--success-soft-text); }
.status-out { background: var(--danger-soft); color: var(--danger-soft-text); }
.status-neutral, .status-default { background: var(--neutral-soft); color: var(--neutral-soft-text); }
.status-type-asset { background: var(--info-soft); color: var(--info-soft-text); }
.status-type-liability { background: var(--danger-soft); color: var(--danger-soft-text); }
.status-type-equity { background: #ede9fe; color: #5b21b6; }
:root[data-theme="dark"] .status-type-equity { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
.status-type-income { background: var(--success-soft); color: var(--success-soft-text); }
.status-type-expense { background: var(--warning-soft); color: var(--warning-soft-text); }

/* ---------- Alerts ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
    line-height: 1.5;
}
.alert-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.alert-content { flex: 1; }
.alert-success { background: var(--success-soft); color: var(--success-soft-text); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-error   { background: var(--danger-soft);  color: var(--danger-soft-text);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning-soft-text); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-info    { background: var(--info-soft);    color: var(--info-soft-text);    border-color: color-mix(in srgb, var(--info) 25%, transparent); }

/* ---------- Toasts ---------- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: calc(100vw - 32px);
    width: 360px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    animation: toast-in 200ms ease-out;
    position: relative;
    overflow: hidden;
}
.toast::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--info);
}
.toast-success::before { background: var(--success); }
.toast-error::before { background: var(--danger); }
.toast-warning::before { background: var(--warning); }
.toast.is-leaving { animation: toast-out 200ms ease-in forwards; }
.toast-icon { flex-shrink: 0; width: 18px; height: 18px; }
.toast-content { flex: 1; }
.toast-close {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: grid;
    place-items: center;
}
.toast-close:hover { background: var(--surface-hover); color: var(--text); }
@keyframes toast-in {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
    to { transform: translateX(20px); opacity: 0; }
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-subtle);
    display: grid;
    place-items: center;
}
.empty-state-icon svg { width: 28px; height: 28px; }
.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.empty-state-text {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ---------- Stat cards (dashboard) ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-sm); }
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stat-label svg { width: 14px; height: 14px; }
.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: -0.01em;
    line-height: 1.1;
}
.stat-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}
.stat-card.accent-primary { border-top: 3px solid var(--primary); }
.stat-card.accent-success { border-top: 3px solid var(--success); }
.stat-card.accent-warning { border-top: 3px solid var(--warning); }
.stat-card.accent-danger  { border-top: 3px solid var(--danger); }
.stat-card.accent-info    { border-top: 3px solid var(--info); }

/* ---------- Callouts (reports) ---------- */
.callout {
    margin-top: 24px;
    padding: 18px 20px;
    border-radius: var(--radius-lg);
    text-align: center;
    font-size: 14px;
    border: 1px solid transparent;
}
.callout-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 6px;
    opacity: 0.85;
}
.callout-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.01em;
}
.callout-success { background: var(--success-soft); color: var(--success-soft-text); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.callout-danger  { background: var(--danger-soft);  color: var(--danger-soft-text);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.callout-warning { background: var(--warning-soft); color: var(--warning-soft-text); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.callout-info    { background: var(--info-soft);    color: var(--info-soft-text);    border-color: color-mix(in srgb, var(--info) 25%, transparent); }

/* ---------- Section titles (reports) ---------- */
.section-title {
    color: var(--success-soft-text);
    border-bottom: 2px solid color-mix(in srgb, var(--success) 35%, transparent);
    padding-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}
.section-title-danger {
    color: var(--danger-soft-text);
    border-bottom: 2px solid color-mix(in srgb, var(--danger) 35%, transparent);
    padding-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}
.section-title-dark {
    color: var(--text);
    border-bottom: 2px solid var(--border-strong);
    padding-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ---------- Login layout ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg);
}
.auth-brand {
    display: none;
    background:
        radial-gradient(at 30% 20%, rgba(59, 130, 246, 0.4) 0, transparent 50%),
        radial-gradient(at 80% 80%, rgba(139, 92, 246, 0.35) 0, transparent 50%),
        linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #fff;
    padding: 48px;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.auth-brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 18px;
    z-index: 1;
}
.auth-brand-logo .sidebar-logo { width: 40px; height: 40px; font-size: 20px; }
.auth-brand-content { z-index: 1; max-width: 460px; }
.auth-brand-content h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-bottom: 12px; }
.auth-brand-content p { font-size: 15px; color: #cbd5e1; line-height: 1.6; }
.auth-brand-foot { z-index: 1; font-size: 12px; color: #94a3b8; }

.auth-form-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-form {
    width: 100%;
    max-width: 400px;
}
.auth-form h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-form .auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.auth-form .form-group { margin-bottom: 16px; }
.auth-form .btn { height: 44px; font-size: 14px; }
.auth-form .auth-foot { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 24px; }
.auth-form .theme-toggle-inline { display: flex; justify-content: flex-end; margin-bottom: 8px; }

/* ---------- Dashboard ---------- */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
.dashboard-grid--split { grid-template-columns: 1fr 2fr; align-items: stretch; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.quick-actions--four { grid-template-columns: repeat(4, 1fr); }
.quick-actions--four .quick-action { min-height: 110px; padding: 16px; }
.quick-action-title { white-space: nowrap; }
.quick-action {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
    min-height: 96px;
}
.quick-action:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--text);
    text-decoration: none;
    transform: translateY(-1px);
}
.quick-action-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
}
.quick-action-icon svg { width: 16px; height: 16px; }
.quick-action-title { font-size: 13px; font-weight: 600; }
.quick-action-desc { font-size: 11.5px; color: var(--text-muted); }

.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.recent-list li:last-child { border-bottom: 0; }
.recent-list .recent-meta { color: var(--text-muted); font-size: 12px; }

/* ---------- Line-item tables (invoice/expense/order/adjustment) ---------- */
.lines-table { width: 100%; }
.lines-table input, .lines-table select {
    width: 100%;
    min-width: 0;
}
.lines-table td { padding: 8px 10px; vertical-align: middle; }
.lines-table .cell-narrow input { width: 80px; }
.lines-table .cell-price input { width: 120px; }
.lines-table .cell-total { font-family: var(--font-mono); }
.lines-table .cell-remove { width: 40px; text-align: center; }
.btn-remove-line {
    background: transparent;
    border: 0;
    color: var(--danger);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-grid;
    place-items: center;
    font-size: 16px;
}
.btn-remove-line:hover { background: var(--danger-soft); }

.totals-block {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}
.totals-block-inner {
    min-width: 260px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
}
.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13.5px;
}
.totals-row.total {
    border-top: 1px solid var(--border-strong);
    margin-top: 6px;
    padding-top: 8px;
    font-size: 16px;
    font-weight: 700;
}
.totals-row .value { font-family: var(--font-mono); }

/* ---------- Utility classes ---------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.block { display: block; }
.hidden { display: none !important; }
.relative { position: relative; }
.absolute { position: absolute; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.cursor-pointer { cursor: pointer; }
.pointer-events-none { pointer-events: none; }

.mb-0 { margin-bottom: 0; } .mb-4 { margin-bottom: 4px; } .mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-20 { margin-bottom: 20px; } .mb-24 { margin-bottom: 24px; } .mb-32 { margin-bottom: 32px; }
.mt-0 { margin-top: 0; } .mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-20 { margin-top: 20px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.m-0 { margin: 0; }
.p-0 { padding: 0; } .p-4 { padding: 4px; } .p-8 { padding: 8px; } .p-12 { padding: 12px; }
.p-16 { padding: 16px; } .p-20 { padding: 20px; } .p-24 { padding: 24px; }
.pr-20 { padding-right: 20px; }

.w-full { width: 100%; }
.w-auto { width: auto; }
.w-80 { width: 80px; }
.w-100px { width: 100px; }
.w-120px { width: 120px; }
.w-130px { width: 130px; }
.w-200px { width: 200px; }
.th-40 { width: 40px; }

.mobile-only { display: none; }
.desktop-only { display: initial; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Responsive tables (label-value on mobile) ---------- */
@media (max-width: 767px) {
    .table-responsive-stack thead { display: none; }
    .table-responsive-stack, .table-responsive-stack tbody, .table-responsive-stack tr, .table-responsive-stack td { display: block; width: 100%; }
    .table-responsive-stack tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: 12px;
        padding: 8px 12px;
        background: var(--surface);
    }
    .table-responsive-stack tr:hover { background: var(--surface); }
    .table-responsive-stack td {
        padding: 6px 0;
        border-bottom: 1px dashed var(--border);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
    }
    .table-responsive-stack td:last-child { border-bottom: 0; }
    .table-responsive-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex: 0 0 auto;
    }
    .table-responsive-stack td.text-right { text-align: right; }
    .table-responsive-stack td.text-left, .table-responsive-stack td.text-center { text-align: right; }
}

/* ==========================================================================
   Role badges (superadmin / admin / editor / viewer)
   ========================================================================== */
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.6;
}
.role-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.7;
}
.role-badge--superadmin {
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
    color: var(--primary);
    border-color: color-mix(in srgb, var(--primary) 25%, transparent);
}
.role-badge--admin {
    background: color-mix(in srgb, var(--info) 12%, var(--surface));
    color: var(--info);
    border-color: color-mix(in srgb, var(--info) 25%, transparent);
}
.role-badge--editor {
    background: color-mix(in srgb, var(--success) 12%, var(--surface));
    color: var(--success);
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
}
.role-badge--viewer {
    background: var(--neutral-soft);
    color: var(--neutral-soft-text);
    border-color: color-mix(in srgb, var(--text-muted) 20%, transparent);
}

.badge-success { background: var(--success-soft); color: var(--success-soft-text); padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }
.badge-warning { background: var(--warning-soft); color: var(--warning-soft-text); padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }

/* ==========================================================================
   Form helpers (shared by companies, settings/users, etc.)
   ========================================================================== */
.form-section-title {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 24px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.form-section-title:first-of-type {
    border-top: 0;
    padding-top: 0;
}
.form-grid-full { grid-column: 1 / -1; }
.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.form-hint {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
    display: block;
}
fieldset {
    border: 0;
    padding: 0;
    margin: 0;
}
legend {
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}
.radio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
}
.radio-row input[type="radio"] { width: 16px; height: 16px; flex-shrink: 0; }
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }

/* ==========================================================================
   Companies (superadmin)
   ========================================================================== */
.definition-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 12px 24px;
    margin: 0;
}
.definition-list dt { font-weight: 600; color: var(--text-muted); font-size: 13px; }
.definition-list dd { margin: 0; color: var(--text); font-size: 14px; }
.card-inner { padding: 20px 0; }

.password-reset-details {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    background: var(--surface-2);
}
.password-reset-details summary {
    cursor: pointer;
    font-weight: 600;
    padding: 4px 0;
    list-style: revert;
}
.password-reset-details[open] summary { margin-bottom: 12px; }
.password-reset-details .form-grid { margin-top: 8px; }

/* ==========================================================================
   Password reveal block (used in company + settings/users)
   ========================================================================== */
.password-reveal {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.password-reveal-row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 16px;
    align-items: center;
}
.password-reveal-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.password-reveal-value {
    font-size: 15px;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    word-break: break-all;
}
.password-reveal-value code {
    font-size: 16px;
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
}
@media (max-width: 640px) {
    .password-reveal-row { grid-template-columns: 1fr; gap: 4px; }
    .password-reveal-row .password-reveal-label { font-size: 12px; }
    .definition-list { grid-template-columns: 1fr; gap: 4px 0; }
    .definition-list dt { margin-top: 8px; }
}

/* ==========================================================================
   Settings — Team (users)
   ========================================================================== */
.btn-link-action {
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--primary);
    cursor: pointer;
    font: inherit;
    text-decoration: none;
    margin-left: 12px;
}
.btn-link-action:hover { text-decoration: underline; }
.inline-form { display: inline; }
.inline-form button { margin-left: 12px; }

/* ==========================================================================
   Auth (change password) — single-column variant
   ========================================================================== */
.auth-shell-single {
    grid-template-columns: 1fr !important;
    max-width: 720px;
    margin: 0 auto;
    min-height: 100vh;
}
@media (min-width: 768px) {
    .auth-shell-single { grid-template-columns: 1fr !important; }
}
@media (max-width: 767px) {
    .auth-shell-single { grid-template-columns: 1fr !important; }
}
.auth-shell-single .auth-brand { display: none !important; }

/* ==========================================================================
   Error pages (403, 404)
   ========================================================================== */
.error-illustration {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--primary);
}
.error-illustration svg { opacity: 0.7; }
:root[data-theme="dark"] .error-illustration svg { opacity: 0.85; }

.error-message {
    margin-bottom: 12px;
    color: var(--text-muted);
}

.error-meta {
    font-size: 12.5px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin: 0 0 20px;
    text-align: center;
    word-break: break-all;
}
.error-meta strong {
    color: var(--text);
    font-weight: 600;
}

.error-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .sidebar-overlay, .toast-container, .skip-link, .no-print, .page-actions, .toolbar, form { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; max-width: 100%; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    body { background: #fff; }
    thead th { background: #f5f5f5; color: #333; }
    a { color: inherit; text-decoration: none; }
    .table-responsive-stack thead { display: table-header-group; }
    .table-responsive-stack tr, .table-responsive-stack td { display: table-row; display: revert; }
    .table-responsive-stack td { display: table-cell; }
    .table-responsive-stack td::before { display: none; }
    @page { margin: 1.5cm; }
}

/* ==========================================================================
   Breakpoint: ≥ 480px (small mobile)
   ========================================================================== */
@media (min-width: 480px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .form-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .form-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ==========================================================================
   Breakpoint: ≥ 768px (tablet)
   ========================================================================== */
@media (min-width: 768px) {
    .topbar { padding: 0 32px; }
    .content { padding: 32px; }
    .card { padding: 28px; }

    .grid-2 { grid-template-columns: 1fr 1fr; }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .form-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .form-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-col-span-2 { grid-column: span 2; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: repeat(2, 1fr); }

     .quick-actions { grid-template-columns: repeat(3, 1fr); }
     .quick-actions--four { grid-template-columns: repeat(2, 1fr); }
     .dashboard-grid--split { grid-template-columns: 1fr; }

     .page-title { font-size: 24px; }

     .auth-shell { grid-template-columns: 1fr 1fr; }
     .auth-brand { display: flex; }
     .auth-form-wrap { padding: 32px; }
 }

/* ==========================================================================
   Breakpoint: ≥ 1024px (laptop / small desktop)
   ========================================================================== */
@media (min-width: 1024px) {
    body { font-size: 14px; }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .form-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .form-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .form-grid-4 { grid-template-columns: repeat(4, 1fr); }

    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid--split { grid-template-columns: 1fr 2fr; }

    .quick-actions { grid-template-columns: repeat(3, 1fr); }
    .quick-actions--four { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Breakpoint: ≥ 1280px (desktop)
   ========================================================================== */
@media (min-width: 1280px) {
    .content { max-width: var(--content-max); }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .dashboard-grid { grid-template-columns: repeat(3, 1fr); }
    .quick-actions { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Breakpoint: ≥ 1536px (large desktop)
   ========================================================================== */
@media (min-width: 1536px) {
    .content {
        max-width: 100%;
        padding: 16px;
    }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Mobile-only (< 1024px): drawer behavior
   ========================================================================== */
@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.is-open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar-menu-toggle { display: inline-flex; }
    .topbar-brand-mobile { display: inline-block; }
    .topbar-title { display: none; }
    .user-name, .user-role { display: none; }
    .mobile-only { display: initial; }
    .desktop-only { display: none !important; }
}

@media (max-width: 480px) {
    .content { padding: 16px; }
    .card { padding: 18px; }
    .topbar { padding: 0 14px; }
    .stat-value { font-size: 20px; }
    .page-title { font-size: 20px; }
    .toolbar-search { min-width: 0; max-width: none; flex: 1; }
    .form-inline { flex-direction: column; align-items: stretch; }
    .form-inline .form-group { width: 100%; }
    .form-inline input, .form-inline select, .form-inline .btn { width: 100%; }
    .form-inline label { margin-bottom: 4px; }
    .totals-block-inner { min-width: 0; }
}

/* ==========================================================================
   Field validation (inline error messages + invalid state)
   ========================================================================== */
.field-error {
    display: none;
    margin-top: 6px;
    font-size: 12px;
    color: var(--danger-soft-text);
    line-height: 1.4;
}
.field-error.has-error {
    display: block;
}
.form-control.is-invalid,
.form-control[aria-invalid="true"] {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}
.form-control.is-invalid:focus,
.form-control[aria-invalid="true"]:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent);
}

/* ==========================================================================
   Password strength meter + rules checklist (change-password form)
   ========================================================================== */
.password-strength {
    display: none;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.password-strength.is-empty { display: none; }
.password-strength:not(.is-empty) { display: flex; }
.password-strength-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.password-strength-bar > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--text-muted);
    border-radius: inherit;
    transition: width 250ms ease, background-color 250ms ease;
}
.password-strength.is-weak      .password-strength-bar > span { background: var(--danger); }
.password-strength.is-fair      .password-strength-bar > span { background: var(--warning); }
.password-strength.is-good      .password-strength-bar > span { background: var(--info); }
.password-strength.is-strong    .password-strength-bar > span { background: var(--success); }
.password-strength.is-excellent .password-strength-bar > span { background: var(--success); }
.password-strength-label {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
.password-strength-label em {
    font-style: normal;
    color: var(--text);
    font-weight: 600;
}
.password-strength.is-weak      .password-strength-label em { color: var(--danger); }
.password-strength.is-fair      .password-strength-label em { color: var(--warning); }
.password-strength.is-good      .password-strength-label em { color: var(--info); }
.password-strength.is-strong,
.password-strength.is-excellent  .password-strength-label em { color: var(--success); }

.password-rules {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin: 16px 0 24px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-muted);
}
.password-rule {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 150ms ease;
}
.password-rule-mark {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    transition: background-color 150ms ease, color 150ms ease;
}
.password-rule.is-met {
    color: var(--success);
}
.password-rule.is-met .password-rule-mark {
    background: var(--success);
    color: #fff;
}
.password-rule.is-met .password-rule-mark::before {
    content: "\2713";
}
.password-rule.is-met .password-rule-mark {
    font-size: 0;
}
.password-rule.is-met .password-rule-mark::before {
    font-size: 11px;
}
.password-rule.is-fail {
    color: var(--text);
}
.password-rule.is-fail .password-rule-mark {
    background: var(--border);
    color: var(--text-muted);
}

/* ==========================================================================
   Dropdown user header (topbar)
   ========================================================================== */
.dropdown-menu-wide {
    min-width: 260px;
    padding: 0;
    overflow: hidden;
}
.dropdown-user-header {
    padding: 14px 16px 12px;
    background: var(--surface-2);
}
.dropdown-user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}
.dropdown-user-email {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    word-break: break-all;
}
.dropdown-user-role {
    display: inline-flex;
    margin-top: 8px;
}
.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0;
}
.dropdown-menu .dropdown-divider + .dropdown-item:first-child {
    border-top: 0;
}
.dropdown-menu .dropdown-item {
    padding: 10px 16px;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 6px);
    text-decoration: none;
    transition: background var(--transition, 0.15s), border-color var(--transition, 0.15s), color var(--transition, 0.15s);
}
.pagination-link:hover {
    background: var(--surface-hover, #f1f5f9);
    border-color: var(--border-strong, #cbd5e1);
    text-decoration: none;
}
.pagination-link.is-active {
    background: var(--primary, #1f6feb);
    border-color: var(--primary, #1f6feb);
    color: #fff;
    cursor: default;
}
.pagination-link.is-active:hover {
    background: var(--primary, #1f6feb);
    border-color: var(--primary, #1f6feb);
    color: #fff;
}
.pagination-link.is-disabled {
    color: var(--text-subtle, #94a3b8);
    pointer-events: none;
    background: var(--surface-2, #f8fafc);
    border-color: var(--border, #e2e8f0);
}
.pagination-ellipsis {
    color: var(--text-muted, #64748b);
    padding: 0 4px;
    user-select: none;
}
.pagination-meta {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

/* ---------- Table totals row ---------- */
.table-wrap tfoot { display: table-footer-group; }
.table-wrap tfoot tr { display: table-row; }
.table-wrap tfoot td {
    background: var(--surface-2, #f8fafc);
    border-top: 2px solid var(--border-strong, #cbd5e1);
    padding-top: 10px;
    padding-bottom: 10px;
    color: var(--text, #0f172a);
    font-weight: 500;
    vertical-align: middle;
    display: table-cell;
}
.table-wrap tfoot .font-semibold { font-weight: 600; }
.totals-row { font-weight: 500; }

