/* ==========================================================================
   CSS RESET & MODERN DESIGN VARIABLES (LIQUID GLASS THEME - HIGH-FIDELITY REFERENCE MATCH)
   ========================================================================== */
:root {
    /* ====================================================================
       DARK THEME (default) — the original ring + dark liquid glass
       ==================================================================== */
    --bg-main: #060509;

    --bg-glass: rgba(255, 255, 255, 0.04);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --bg-glass-secondary: rgba(255, 255, 255, 0.02);

    --bg-input: rgba(255, 255, 255, 0.04);
    --bg-input-focus: rgba(255, 255, 255, 0.08);

    /* Unified green accent */
    --color-primary: #2fd968;
    --color-primary-hover: #25c25a;
    --accent-gradient: linear-gradient(180deg, #38df73 0%, #23c55e 100%);
    --accent-gradient-hover: linear-gradient(180deg, #44e87f 0%, #28cf66 100%);
    --color-primary-glow: rgba(47, 217, 104, 0.45);

    --color-success: #14b8a6;
    --color-success-bg: rgba(20, 184, 166, 0.12);
    --color-success-border: rgba(20, 184, 166, 0.4);

    --color-danger: #f43f5e;
    --color-danger-bg: rgba(244, 63, 94, 0.12);
    --color-danger-border: rgba(244, 63, 94, 0.4);

    --color-warning: #f59e0b;

    --text-primary: #ffffff;
    --text-secondary: #f1f5f9;
    --text-muted: #cbd5e1;
    --text-disabled: #64748b;

    --border-color: rgba(255, 255, 255, 0.15);
    --border-hover: rgba(255, 255, 255, 0.3);
    --border-focus: #2fd968;

    /* Semantic surface tints & hairlines (flip per theme) */
    --surface: rgba(255, 255, 255, 0.05);
    --surface-strong: rgba(255, 255, 255, 0.08);
    --surface-hover: rgba(255, 255, 255, 0.14);
    --hairline: rgba(255, 255, 255, 0.1);
    --hairline-strong: rgba(255, 255, 255, 0.2);

    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-code: 'JetBrains Mono', monospace;

    /* ===== DARK LIQUID GLASS ENGINE (clear glass) ===== */
    --glass-blur: blur(9px) saturate(135%);
    --glass-blur-strong: blur(14px) saturate(140%);

    --glass-fill: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 70%, rgba(0, 0, 0, 0.14) 100%);
    --glass-fill-hover: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 35%, rgba(0, 0, 0, 0.1) 100%);

    /* Blur-free panel fills for scroll-path elements (dark theme) */
    --panel: rgba(24, 26, 34, 0.55);
    --panel-hover: rgba(34, 37, 48, 0.66);

    --glass-rim: linear-gradient(
        160deg,
        rgba(255, 255, 255, 0.85) 0%,
        rgba(255, 255, 255, 0.35) 20%,
        rgba(255, 255, 255, 0.16) 45%,
        rgba(255, 255, 255, 0.16) 60%,
        rgba(255, 255, 255, 0.3) 82%,
        rgba(255, 255, 255, 0.55) 100%
    );
    --glass-inset: inset 0 1px 0.5px rgba(255, 255, 255, 0.5),
                   inset 0 -1px 1.5px rgba(0, 0, 0, 0.3);
    --glass-sheen: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.06) 0%,
        rgba(255, 255, 255, 0) 22%
    );

    --color-live: #2fd968;
    --color-live-soft: rgba(47, 217, 104, 0.16);
    --color-live-glow: rgba(47, 217, 104, 0.55);

    --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.4), var(--glass-inset);
    --shadow-md: 0 14px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3), var(--glass-inset);
    --shadow-lg: 0 26px 64px rgba(0, 0, 0, 0.62), 0 8px 22px rgba(0, 0, 0, 0.4), var(--glass-inset);

    --modal-bg: linear-gradient(180deg, rgba(20, 26, 38, 0.55) 0%, rgba(8, 12, 21, 0.5) 100%);

    --transition-fast: 0.18s cubic-bezier(0.32, 0.72, 0, 1);
    --transition-normal: 0.34s cubic-bezier(0.32, 0.72, 0, 1);

    /* iOS continuous-corner radius scale (consistent across the whole app) */
    --r-xs: 8px;
    --r-sm: 12px;
    --r-md: 16px;
    --r-lg: 22px;
    --r-xl: 28px;
    --r-pill: 999px;
}

/* ========================================================================
   LIGHT THEME OVERRIDES (body.light-theme) — same liquid glass, light frost
   ======================================================================== */
body.light-theme {
    --bg-main: #eef1f7;

    --bg-glass: rgba(255, 255, 255, 0.55);
    --bg-glass-hover: rgba(255, 255, 255, 0.72);
    --bg-glass-secondary: rgba(255, 255, 255, 0.4);

    --bg-input: rgba(255, 255, 255, 0.7);
    --bg-input-focus: rgba(255, 255, 255, 0.95);

    --color-primary: #16a34a;
    --color-primary-hover: #15803d;
    --accent-gradient: linear-gradient(180deg, #34d36e 0%, #1fbf5a 100%);
    --accent-gradient-hover: linear-gradient(180deg, #3de07a 0%, #23c963 100%);
    --color-primary-glow: rgba(34, 197, 94, 0.32);

    --color-success: #0d9488;
    --color-success-bg: rgba(13, 148, 136, 0.1);
    --color-success-border: rgba(13, 148, 136, 0.35);

    --color-danger: #e11d48;
    --color-danger-bg: rgba(225, 29, 72, 0.08);
    --color-danger-border: rgba(225, 29, 72, 0.3);

    --color-warning: #d97706;

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-disabled: #94a3b8;

    --border-color: rgba(15, 23, 42, 0.1);
    --border-hover: rgba(15, 23, 42, 0.2);
    --border-focus: #16a34a;

    --surface: rgba(15, 23, 42, 0.04);
    --surface-strong: rgba(15, 23, 42, 0.06);
    --surface-hover: rgba(15, 23, 42, 0.1);
    --hairline: rgba(15, 23, 42, 0.1);
    --hairline-strong: rgba(15, 23, 42, 0.18);

    /* Light frosted glass engine */
    --glass-blur: blur(10px) saturate(150%);
    --glass-blur-strong: blur(15px) saturate(160%);

    --glass-fill: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.24) 100%);
    --glass-fill-hover: linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0.34) 100%);

    /* Blur-free panel fills for scroll-path elements (light theme) */
    --panel: rgba(255, 255, 255, 0.62);
    --panel-hover: rgba(255, 255, 255, 0.78);

    --glass-rim: linear-gradient(
        160deg,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(255, 255, 255, 0.5) 18%,
        rgba(15, 23, 42, 0.08) 50%,
        rgba(15, 23, 42, 0.08) 62%,
        rgba(15, 23, 42, 0.12) 100%
    );
    --glass-inset: inset 0 1px 0.5px rgba(255, 255, 255, 0.9),
                   inset 0 -1px 1.5px rgba(15, 23, 42, 0.05);
    --glass-sheen: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.5) 0%,
        rgba(255, 255, 255, 0) 26%
    );

    --color-live: #16a34a;
    --color-live-soft: rgba(34, 197, 94, 0.14);
    --color-live-glow: rgba(34, 197, 94, 0.4);

    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08), var(--glass-inset);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1), 0 2px 6px rgba(15, 23, 42, 0.06), var(--glass-inset);
    --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.14), 0 6px 16px rgba(15, 23, 42, 0.08), var(--glass-inset);

    --modal-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.74) 100%);
}

/* Logo: invert to white on dark, keep black on light */
body:not(.light-theme) .login-logo img,
body:not(.light-theme) .nav-brand img {
    filter: invert(1) brightness(2.5) contrast(1.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
    font-size: 0.875rem;
    letter-spacing: -0.011em;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ==========================================================================
   DYNAMIC LIQUID BACKDROP ORBS WITH DIGITAL GRID OVERLAY
   ========================================================================== */
.global-liquid-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
    /* DARK theme default: premium Crystal-branded backdrop */
    background:
        linear-gradient(rgba(6, 5, 10, 0.35), rgba(6, 5, 10, 0.55)),
        url('/crystal-dark-bg.webp') no-repeat center center,
        #060509;
    background-size: auto, cover, auto;
}

/* Soft edge vignette to deepen the corners (dark theme) */
.global-liquid-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(135% 135% at 50% 40%, rgba(0, 0, 0, 0) 55%, rgba(5, 4, 9, 0.55) 100%);
    z-index: 4;
    pointer-events: none;
}

/* LIGHT theme: premium white Crystal-branded backdrop */
body.light-theme .global-liquid-bg {
    background:
        linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.55)),
        url('/crystal-light-bg.webp') no-repeat center center,
        #eef1f7;
    background-size: auto, cover, auto;
}
body.light-theme .global-liquid-bg::after {
    background: radial-gradient(135% 135% at 50% 40%, rgba(255, 255, 255, 0) 60%, rgba(210, 216, 228, 0.5) 100%);
}
body.light-theme .liquid-orb { display: none; }

/* ==========================================================================
   SHARED LIQUID GLASS SURFACE ENGINE
   Every glass pane gets: a gradient specular rim that follows its rounded
   corners (::before) + a top-down sheen reflection (::after).
   ========================================================================== */
.login-card-wrapper,
.system-card,
.modal-card,
.portal-navbar {
    position: relative;
    isolation: isolate;
}

/* The wrapping specular rim — a true edge of glass that catches light all the
   way around, brightest top-left, glinting again bottom-right. */
.login-card-wrapper::before,
.system-card::before,
.modal-card::before,
.portal-navbar::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;                   /* hairline rim thickness */
    background: var(--glass-rim);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    z-index: 2;
}

/* The surface sheen — a soft reflection sliding off the top of the pane. */
.login-card-wrapper::after,
.system-card::after,
.modal-card::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--glass-sheen);
    pointer-events: none;
    z-index: -1;
}

/* Ring backdrop retired in favour of the Crystal image background */
.liquid-orb {
    display: none;
    position: absolute;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    z-index: 1;
}
.liquid-orb-1 {
    width: 78vmin;
    height: 78vmin;
    transform: translate(-50%, -50%);
    background: conic-gradient(from 200deg,
        #ff2f2f 0deg, #ff5a2a 50deg, #ff2f6b 105deg,
        #8b1fd6 160deg, #3b46ff 215deg, #2b8bff 270deg,
        #6a1fc4 320deg, #ff2f2f 360deg);
    -webkit-mask: radial-gradient(circle, transparent 60%, #000 61.5%, #000 70%, transparent 72.5%);
            mask: radial-gradient(circle, transparent 60%, #000 61.5%, #000 70%, transparent 72.5%);
    filter: blur(5px) saturate(135%);
    opacity: 0.95;
    animation: ring-spin 90s linear infinite;
}
.liquid-orb-center {
    width: 80vmin;
    height: 80vmin;
    transform: translate(-50%, -50%);
    background: conic-gradient(from 200deg,
        #ff2f2f 0deg, #ff5a2a 50deg, #ff2f6b 105deg,
        #8b1fd6 160deg, #3b46ff 215deg, #2b8bff 270deg,
        #6a1fc4 320deg, #ff2f2f 360deg);
    -webkit-mask: radial-gradient(circle, transparent 54%, #000 60%, #000 72%, transparent 80%);
            mask: radial-gradient(circle, transparent 54%, #000 60%, #000 72%, transparent 80%);
    filter: blur(45px) saturate(150%);
    opacity: 0.5;
    animation: ring-spin 90s linear infinite;
}
@keyframes ring-spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}
.liquid-orb-2,
.liquid-orb-3,
.liquid-orb-4 { display: none; }

@keyframes drift-1 {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(10vw, 5vh) scale(1.1); }
}
@keyframes drift-2 {
    0% { transform: translate(0, 0) scale(1.1); }
    100% { transform: translate(-8vw, -10vh) scale(0.9); }
}
@keyframes drift-3 {
    0% { transform: translate(0, 0) scale(0.95); }
    100% { transform: translate(5vw, -8vh) scale(1.05); }
}
@keyframes drift-4 {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-5vw, 8vh) scale(1.1); }
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--hairline-strong);
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(47, 217, 104, 0.55);
}

/* ==========================================================================
   UTILITY & BADGES
   ========================================================================== */
.hidden {
    display: none !important;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 700;
    border-radius: 999px;
    text-transform: capitalize;
}

.badge-admin {
    background-color: var(--color-live-soft);
    color: var(--color-primary);
    border: 1px solid var(--color-live-glow);
}

.badge-user {
    background-color: var(--surface-strong);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
}

.status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.status-dot.active {
    background-color: var(--color-live);
    box-shadow: 0 0 8px rgba(47, 217, 104, 0.8);
}

/* ==========================================================================
   BUTTONS (CAPSULE / ROUNDED CAPSULE STYLING)
   ========================================================================== */
.btn {
    font-family: var(--font-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.45rem 1.1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    border-radius: var(--r-pill);
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
    user-select: none;
    text-decoration: none;
    height: 34px;
}

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

.btn-primary {
    background: linear-gradient(180deg, #38df73 0%, #23c55e 100%);
    color: #04220f;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(35, 197, 94, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #44e87f 0%, #28cf66 100%);
    box-shadow: 0 8px 22px rgba(35, 197, 94, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 3px 10px rgba(35, 197, 94, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-secondary {
    background-color: var(--surface-strong);
    color: var(--text-primary);
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
}

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

.btn-outline {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--hairline-strong);
}

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

.btn-danger {
    background-color: rgba(244, 63, 94, 0.08);
    color: #fda4af;
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.btn-danger:hover {
    background-color: #f43f5e;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.3);
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-primary);
    padding: 0;
    cursor: pointer;
    font-weight: 700;
    height: auto;
}

.btn-link:hover {
    color: #5cf08f;
}

.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    height: 26px;
}

.btn-block {
    width: 100%;
}

.btn-icon-only {
    padding: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border-color);
}

.btn-icon-only:hover {
    background-color: var(--surface-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

/* ==========================================================================
   REFERENCE CONTROL PRIMITIVES (circular glass buttons + toggle switches)
   ========================================================================== */
/* Circular frosted icon button — bell, search, dock controls, etc. */
.glass-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    flex-shrink: 0;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    background: var(--panel);
    border: 1px solid var(--hairline);
    box-shadow: var(--glass-inset);
    transition: transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}
.glass-icon-btn:hover {
    background: var(--glass-fill-hover);
    border-color: var(--hairline-strong);
}
.glass-icon-btn:active { transform: scale(0.94); }
.glass-icon-btn.sm { width: 36px; height: 36px; font-size: 0.85rem; }

/* Floating theme toggle — always reachable (login + dashboard) */
.theme-toggle {
    position: fixed;
    bottom: 18px;
    left: 18px;
    z-index: 300;
    width: 44px;
    height: 44px;
}
.theme-toggle i { transition: transform var(--transition-normal); }
.theme-toggle:hover i { transform: rotate(-20deg); }

/* iOS-style pill toggle with green live-glow knob */
.toggle-switch {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 50px;
    height: 28px;
    border-radius: 99px;
    background: var(--surface-hover);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.toggle-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #d4d4d4;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: left var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.toggle-switch:checked {
    background: linear-gradient(180deg, rgba(54, 224, 122, 0.28), rgba(54, 224, 122, 0.12));
    box-shadow: inset 0 0 0 1px rgba(54, 224, 122, 0.5);
}
.toggle-switch:checked::after {
    left: 25px;
    background: radial-gradient(circle at 40% 35%, #7dffae, #20c25a);
    box-shadow: 0 0 12px var(--color-live-glow);
}

/* ==========================================================================
   APP SHELL LAYOUT & LOADERS
   ========================================================================== */
#app-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.view-section {
    display: none;
    width: 100%;
    min-height: 100vh;
}

.view-section.active {
    display: flex;
    flex-direction: column;
}

/* Spinner Loader */
#view-loading {
    justify-content: center;
    align-items: center;
    background-color: transparent;
}

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner-container p {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 700;
}

.double-bounce1, .double-bounce2 {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--color-primary);
    opacity: 0.5;
    animation: sk-bounce 1.6s infinite ease-in-out;
}

.double-bounce2 {
    animation-delay: -0.8s;
}

@keyframes sk-bounce {
    0%, 100% { transform: scale(0.0) }
    50% { transform: scale(1.0) }
}

/* ==========================================================================
   LOGIN SCREEN (LIQUID GLASS IMPLEMENTATION)
   ========================================================================== */
#view-login {
    justify-content: center;
    align-items: center;
    background-color: transparent;
    padding: 1rem;
    position: relative;
    z-index: 5;
}

.login-card-wrapper {
    background: var(--glass-fill);
    border: none;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 28px;
    width: 100%;
    max-width: 360px;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-logo {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.875rem;
}

/* Keep the black Crystal logo as-is on the light theme */
.login-logo img,
.nav-brand img {
    filter: none;
}

.login-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.login-form .form-group {
    margin-bottom: 1.125rem;
}

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    letter-spacing: -0.005em;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper input,
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    padding: 0.6rem 1rem;
    font-size: 0.8125rem;
    letter-spacing: -0.005em;
    border-radius: var(--r-pill);
    outline: none;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.18);
    transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper input::placeholder,
.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-disabled);
}

/* Keep textareas and select slightly less rounded but still smooth */
.form-group textarea {
    border-radius: var(--r-md);
}
.form-group select {
    border-radius: var(--r-pill);
    padding-right: 2rem;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M7 10l5 5 5-5H7z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
}

.input-wrapper input {
    padding-left: 2rem;
}

.input-wrapper .input-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    pointer-events: none;
}

.password-toggle-btn {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 0.75rem;
}

.password-toggle-btn:hover {
    color: var(--text-primary);
}

.input-wrapper input:focus,
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--border-focus);
    background-color: var(--bg-input-focus);
    box-shadow: 0 0 0 3px rgba(47, 217, 104, 0.25);
}

.form-group select option {
    background-color: var(--bg-main);
    color: var(--text-primary);
}

.form-help {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding-left: 0.5rem;
}

.login-footer {
    margin-top: 1.75rem;
    text-align: center;
    border-top: 1px solid var(--hairline);
    padding-top: 1.125rem;
}

.login-footer p {
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 700;
}

/* ==========================================================================
   NAVIGATION BAR (COMPACT LIQUID GLASS PORTAL HEADER)
   ========================================================================== */
.portal-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem 0.5rem 1.25rem;
    background: var(--panel);
    border: none;
    position: sticky;
    top: 12px;
    z-index: 10;
    box-shadow: var(--shadow-md);
    height: 56px;
    margin: 12px 12px 0 12px;
    border-radius: var(--r-pill);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-text {
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-primary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.user-badge i {
    color: var(--color-primary);
}

.user-badge #nav-username {
    font-weight: 700;
    color: var(--text-primary);
}

.nav-btn {
    height: 28px;
    padding: 0 0.75rem;
    font-size: 0.75rem;
}

/* ==========================================================================
   DASHBOARD / VIEW SUBPORTALS
   ========================================================================== */
.dashboard-content {
    flex: 1;
    padding: 1.5rem 1.5rem;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 5;
}

.subview {
    display: none;
    animation: fade-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.subview.active {
    display: block;
}

.subview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.subview-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.75rem;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   A. USER PORTAL VIEW: CARD DESIGN (LIQUID GLASS CAPSULE STYLING)
   ========================================================================== */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 240px;
}

.search-box input {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--hairline);
    color: var(--text-primary);
    padding: 0.45rem 0.75rem 0.45rem 1.875rem;
    font-size: 0.75rem;
    border-radius: 99px;
    outline: none;
    box-shadow: var(--glass-inset);
    transition: all var(--transition-fast);
}

.search-box input:focus {
    border-color: rgba(47, 217, 104, 0.6);
    box-shadow: 0 0 0 3px rgba(47, 217, 104, 0.25), var(--glass-inset);
}

.search-box .search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Card Grid layout */
.systems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: 1rem;
    min-width: 0;
}

/* Rounded Frosted Liquid Glass Cards */
.system-card {
    background: var(--panel);
    border: none;
    border-radius: 26px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), background var(--transition-normal);
    box-shadow: var(--shadow-md);
    contain: layout paint style;
}

.system-card:hover {
    transform: translateY(-4px);
    background: var(--panel-hover);
    box-shadow: var(--shadow-lg),
                0 0 22px var(--color-live-glow);
}

/* Brighten the rim to a green-tinted glint on hover (reference live-glow) */
.system-card:hover::before {
    background: linear-gradient(
        160deg,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(47, 217, 104, 0.5) 30%,
        rgba(255, 255, 255, 0.05) 55%,
        rgba(47, 217, 104, 0.35) 100%
    );
}

/* Circular icon envelope */
.card-icon-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 34px;
    height: 34px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--color-live);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--glass-inset);
    transition: all var(--transition-fast);
}

.system-card:hover .card-icon-wrapper {
    background: var(--color-live-soft);
    border-color: rgba(47, 217, 104, 0.5);
    color: #4cf587;
    box-shadow: 0 0 12px rgba(47, 217, 104, 0.4);
}

.system-card h3 {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.375rem;
    color: var(--text-primary);
}

.system-card p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1.125rem;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--hairline);
    padding-top: 0.75rem;
    margin-top: auto;
}

.card-link-preview {
    font-family: var(--font-code);
    font-size: 0.6875rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    font-weight: 500;
}

/* Empty View */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--panel);
    border: 1px solid var(--hairline);
    border-radius: var(--r-xl);
    max-width: 420px;
    margin: 3rem auto 0 auto;
    box-shadow: var(--shadow-md);
}

.empty-icon {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ==========================================================================
   B. ADMIN CONTROL PANEL TABS & TABLES
   ========================================================================== */
.admin-tabs {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.3rem;
    margin-bottom: 1.25rem;
    background: var(--panel);
    border-radius: 99px;
    box-shadow: var(--glass-inset);
}

.tab-btn {
    font-family: var(--font-main);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 99px;
    color: var(--text-muted);
    padding: 0.5rem 1.125rem;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    transition: all var(--transition-fast);
}

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

/* Active tab = frosted green-lit pill (reference selected-room look) */
.tab-btn.active {
    color: var(--text-primary);
    background: var(--panel-hover);
    border-color: rgba(47, 217, 104, 0.45);
    box-shadow: 0 0 16px rgba(47, 217, 104, 0.3),
                inset 0 1px 0.5px rgba(255, 255, 255, 0.4);
}

.tab-btn.active i {
    color: var(--color-live);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.tab-panel-header h3 {
    font-size: 0.875rem;
    font-weight: 700;
}

/* Admin Table Design */
.table-container {
    background: var(--panel);
    border: 1px solid var(--hairline);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.75rem;
}

.admin-table th {
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--hairline);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.04em;
}

.admin-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--hairline);
    color: var(--text-secondary);
    vertical-align: middle;
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-table tbody tr {
    transition: background-color var(--transition-fast);
}

.admin-table tbody tr:hover {
    background-color: var(--surface);
}

/* System specific fields */
.admin-table td .system-name-wrapper {
    font-weight: 700;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
}

.admin-table td .system-desc {
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-table td .system-link {
    font-family: var(--font-code);
    font-size: 0.7rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.admin-table td .system-link:hover {
    text-decoration: underline;
    color: #5cf08f;
}

/* Users badge tags list */
.permitted-users-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    max-width: 280px;
}

.permitted-users-list .user-tag {
    background: var(--surface);
    border: 1px solid var(--border-color);
    font-size: 0.6875rem;
    color: var(--text-secondary);
    padding: 0.05rem 0.5rem;
    border-radius: 99px;
    font-weight: 600;
}

.table-actions {
    display: flex;
    gap: 0.25rem;
}

/* ==========================================================================
   MODAL SYSTEMS (LIQUID GLASS CARDS)
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--modal-bg);
    border: none;
    backdrop-filter: var(--glass-blur-strong);
    -webkit-backdrop-filter: var(--glass-blur-strong);
    border-radius: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform var(--transition-normal);
    overflow: hidden;
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
}

.modal-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.15rem;
    padding: 0.25rem;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-form {
    padding: 1.5rem;
}

.modal-form .form-group {
    margin-bottom: 1rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 1.25rem;
}

/* ==========================================================================
   CHOICE CARDS FOR ACCESS PERMISSIONS (LIQUID GLASS ROWS)
   ========================================================================== */
.permission-selector-wrapper {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    padding: 0.5rem;
    margin-top: 0.375rem;
}

.selector-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--hairline);
}

.checkbox-scroll-list {
    max-height: 140px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-right: 0.25rem;
}

/* Glass choice card row */
.checkbox-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    user-select: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.checkbox-label:hover {
    border-color: var(--hairline-strong);
    background-color: var(--surface-strong);
}

.checkbox-label input[type="checkbox"]:checked + span {
    color: var(--text-primary);
}

/* Checkbox visual structure */
.checkbox-label-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--hairline-strong);
    border-radius: 4px;
    background-color: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked {
    background: linear-gradient(180deg, #38df73 0%, #23c55e 100%);
    border-color: var(--color-live);
    box-shadow: 0 0 8px rgba(35, 197, 94, 0.4);
}

.checkbox-label input[type="checkbox"]:checked::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    color: #04220f;
    font-size: 0.55rem;
}

.checkbox-user-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.checkbox-username {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.checkbox-role-badge {
    font-size: 0.625rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Highlighted Choice Card border when selected */
.checkbox-label.selected {
    border-color: rgba(47, 217, 104, 0.5);
    background-color: rgba(47, 217, 104, 0.08);
}

/* ==========================================================================
   TOAST NOTIFICATION SYSTEM (LIQUID GLASS STYLE)
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 300px;
    width: 100%;
    pointer-events: none;
}

.toast {
    background: rgba(18, 22, 30, 0.72);
    border-left: 3px solid var(--color-live);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    padding: 0.8rem 1rem;
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    transform: translateX(120%);
    opacity: 0;
    pointer-events: auto;
    transition: transform var(--transition-normal), opacity var(--transition-normal);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-icon {
    font-size: 0.875rem;
    margin-top: 0.1rem;
}

.toast-content {
    flex-grow: 1;
}

.toast-title {
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 0.1rem;
    color: #ffffff; /* toast stays dark in both themes */
}

.toast-msg {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.78);
}

.toast-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 0.7rem;
    margin-left: 0.25rem;
}

.toast-close:hover {
    color: #ffffff;
}

/* Toast modifiers */
.toast-success { border-left-color: #10b981; }
.toast-success .toast-icon { color: #10b981; }

.toast-error { border-left-color: #f43f5e; }
.toast-error .toast-icon { color: #f43f5e; }

.toast-warning { border-left-color: #f59e0b; }
.toast-warning .toast-icon { color: #f59e0b; }

/* ==========================================================================
   DEPARTMENT SIDEBAR (Windows-explorer style folder tree) + PORTAL LAYOUT
   ========================================================================== */
.portal-layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}
/* Prevent grid/flex children from forcing horizontal overflow */
.portal-main, .portal-sidebar, .system-card, .systems-grid, .dashboard-content { min-width: 0; }
html, body { max-width: 100%; overflow-x: hidden; }

.portal-sidebar {
    position: sticky;
    top: 80px;
    background: var(--panel);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    padding: 0.85rem 0.7rem;
    isolation: isolate;
}
.portal-sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: var(--glass-rim);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
}

.sidebar-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0.35rem 0.5rem 0.6rem;
}

.folder-tree { display: flex; flex-direction: column; gap: 2px; }

/* A row in the tree */
.tree-node { display: flex; flex-direction: column; }
.tree-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
    user-select: none;
}
.tree-row:hover { background: var(--surface); color: var(--text-primary); }
.tree-row.active {
    background: var(--color-live-soft);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px var(--color-live-glow);
}
.tree-row .twisty {
    width: 14px;
    flex-shrink: 0;
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}
.tree-row .twisty.spacer { visibility: hidden; }
.tree-node.collapsed > .tree-children { display: none; }
.tree-node:not(.collapsed) > .tree-row > .twisty.open { transform: rotate(90deg); }
.tree-row .folder-ico { width: 16px; text-align: center; color: var(--color-live); font-size: 0.82rem; }
.tree-row .tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .tree-count {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-strong);
    border-radius: 99px;
    padding: 0.05rem 0.4rem;
    min-width: 18px;
    text-align: center;
}
.tree-children { display: flex; flex-direction: column; gap: 2px; }

/* ==========================================================================
   ADMIN DEPARTMENT TREE (manage folders)
   ========================================================================== */
.admin-folder-tree { padding: 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.admin-folder-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--r-sm);
    transition: background var(--transition-fast);
}
.admin-folder-row:hover { background: var(--surface); }
.admin-folder-row .folder-ico { color: var(--color-live); width: 18px; text-align: center; }
.admin-folder-row .af-name { font-weight: 600; color: var(--text-primary); font-size: 0.85rem; }
.admin-folder-row .af-count { font-size: 0.7rem; color: var(--text-muted); }
.admin-folder-row .af-actions { margin-left: auto; display: flex; gap: 0.25rem; opacity: 0; transition: opacity var(--transition-fast); }
.admin-folder-row:hover .af-actions { opacity: 1; }
.admin-folder-empty { text-align: center; color: var(--text-muted); font-size: 0.85rem; padding: 2rem 0; }

@media (max-width: 820px) {
    /* Stack the department sidebar above the grid, full width */
    .portal-layout { grid-template-columns: 1fr; gap: 0.85rem; }
    .portal-sidebar { position: static; top: 0; max-height: 260px; overflow-y: auto; }
}

/* ==========================================================================
   RESPONSIVE DESIGN MEDIA QUERIES
   ========================================================================== */
@media (max-width: 900px) {
    .subview-header {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: 100%;
    }
}

/* ---- Tablets & small laptops ---- */
@media (max-width: 768px) {
    .portal-navbar {
        padding: 0.4rem 0.5rem 0.4rem 1rem;
        gap: 0.4rem;
        height: 52px;
        margin: 8px 8px 0 8px;
    }
    .nav-actions { gap: 0.35rem; }

    /* Collapse text labels on nav buttons to icons to save room */
    .nav-btn span { display: none; }
    .nav-btn { padding: 0 0.6rem; }
    .user-badge .badge { display: none; }

    .dashboard-content { padding: 1rem; }

    .admin-tabs { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
    .tab-btn { padding: 0.5rem 0.85rem; font-size: 0.78rem; white-space: nowrap; }

    /* Allow wide admin tables to scroll horizontally */
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .admin-table { min-width: 560px; }

    /* Modals fit the viewport and scroll internally */
    .modal-card { max-height: 90vh; overflow-y: auto; }
}

/* ---- Phones ---- */
@media (max-width: 560px) {
    .systems-grid { grid-template-columns: 1fr; }

    .brand-text { font-size: 0.8rem; }
    .user-badge #nav-username { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .subview-header h2 { font-size: 1.05rem; }
    .dashboard-content { padding: 0.85rem; }

    .login-card-wrapper { padding: 2rem 1.5rem; }

    /* Modal padding tightens on phones */
    .modal-form { padding: 1.1rem; }
    .modal-header { padding: 0.85rem 1.1rem; }

    .theme-toggle { bottom: 12px; left: 12px; width: 40px; height: 40px; }
    .toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* ---- Very small phones ---- */
@media (max-width: 360px) {
    .nav-brand img { height: 16px !important; }
    .user-badge { padding: 0.2rem 0.45rem; }
    .btn { padding: 0.4rem 0.8rem; }
}
