/* =========================================================
   SHELL LAYOUT & 3-THEME SYSTEM (HÍBRIDO DESKTOP & MOBILE)
   ========================================================= */

/* --- TEMA 1: CINZA MONOCROMÁTICO (Default / Conforme Referência) --- */
:root,
html[data-theme="gray"] {
    --primary: #1e293b;
    --primary-dark: #0f172a;
    --primary-hover: #334155;
    --primary-soft: #cbd7e6;
    --primary-muted: rgba(30, 41, 59, 0.15);
    --primary-glow: rgba(30, 41, 59, 0.1);
    --accent: #475569;

    --bg: #e2e8f0;
    --bg-canvas: #e2e8f0;
    --rail-bg: #d8e1ec;
    --rail-border: #c8d4e2;
    --rail-link-active: #cbd7e6;
    --rail-link-hover: rgba(203, 215, 230, 0.6);
    --rail-text: #0f172a;
    --rail-text-muted: #5c6b7e;

    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-glass: rgba(255, 255, 255, 0.95);
    
    --card-bg: #ffffff;
    --card-border: #d8e1ec;
    --card-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);

    --border: #d6dfea;
    --border-light: #e8edf4;

    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --avatar-bg: #24303f;
    --avatar-text: #ffffff;
    --chip-bg: #e2e8f0;
    --chip-text: #334155;

    --ok: #15803d;
    --ok-bg: #dcfce7;
    --ok-border: #86efac;
    --error: #be123c;
    --error-light: #e11d48;
    --error-bg: #ffe4e6;
    --error-border: #fecdd3;
    --warn: #854d0e;
    --warn-bg: #fef9c3;
    --warn-border: #fef08a;

    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-2xl: 32px;

    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 28px rgba(15, 23, 42, 0.08);

    --sidebar-w: 240px;
    --dock-h: 62px;
}

/* --- TEMA 2: CLARO (Light Clean) --- */
html[data-theme="light"] {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eff6ff;
    --primary-muted: #bfdbfe;
    --primary-glow: rgba(37, 99, 235, 0.16);
    --accent: #0ea5e9;

    --bg: #f8fafc;
    --bg-canvas: #f8fafc;
    --rail-bg: #ffffff;
    --rail-border: #e2e8f0;
    --rail-link-active: #eff6ff;
    --rail-link-hover: #f1f5f9;
    --rail-text: #0f172a;
    --rail-text-muted: #64748b;

    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-glass: rgba(255, 255, 255, 0.95);

    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --card-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);

    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --avatar-bg: #2563eb;
    --avatar-text: #ffffff;
    --chip-bg: #eff6ff;
    --chip-text: #1e40af;

    --ok-bg: #f0fdf4;
    --ok-border: #bbf7d0;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --warn-bg: #fefce8;
    --warn-border: #fef08a;
}

/* --- TEMA 3: ESCURO (Dark / OLED) --- */
html[data-theme="dark"] {
    --primary: #38bdf8;
    --primary-dark: #0284c7;
    --primary-hover: #0ea5e9;
    --primary-soft: rgba(56, 189, 248, 0.14);
    --primary-muted: rgba(56, 189, 248, 0.28);
    --primary-glow: rgba(56, 189, 248, 0.22);
    --accent: #818cf8;

    --bg: #080a0f;
    --bg-canvas: #080a0f;
    --rail-bg: #0f131c;
    --rail-border: rgba(255, 255, 255, 0.08);
    --rail-link-active: rgba(56, 189, 248, 0.15);
    --rail-link-hover: rgba(255, 255, 255, 0.05);
    --rail-text: #f8fafc;
    --rail-text-muted: #94a3b8;

    --surface: #121824;
    --surface-alt: #182030;
    --surface-glass: rgba(18, 24, 36, 0.92);

    --card-bg: #121824;
    --card-border: rgba(255, 255, 255, 0.08);
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);

    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.05);

    --text: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --avatar-bg: #0284c7;
    --avatar-text: #ffffff;
    --chip-bg: rgba(255, 255, 255, 0.06);
    --chip-text: #94a3b8;

    --ok: #34d399;
    --ok-bg: rgba(6, 78, 59, 0.4);
    --ok-border: rgba(52, 211, 153, 0.25);
    --error: #f43f5e;
    --error-bg: rgba(136, 19, 55, 0.4);
    --error-border: rgba(244, 63, 94, 0.25);
    --warn: #fbbf24;
    --warn-bg: rgba(120, 53, 15, 0.4);
    --warn-border: rgba(251, 191, 36, 0.25);
}

/* =========================================================
   BASE STYLES & LAYOUT SHELL
   ========================================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 15px;
    height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background-color 0.25s ease, color 0.25s ease;
    -webkit-font-smoothing: antialiased;
}

body.is-login {
    height: 100dvh;
    overflow: hidden;
}

body.is-login .container {
    max-width: none;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    margin: 0;
    padding: 14vh 0 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
}

body.is-login .alert {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    width: min(420px, calc(100% - 32px));
    margin: 0;
    box-sizing: border-box;
}

.shell {
    display: flex;
    min-height: 100vh;
}

.shell-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* =========================================================
   DESKTOP SIDEBAR (RAIL)
   ========================================================= */
.rail {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--rail-bg);
    border-right: 1px solid var(--rail-border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: all 0.25s ease;
    z-index: 50;
}

.rail__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--rail-text);
    padding: 0 6px 20px;
    border-bottom: 1px solid var(--rail-border);
    margin-bottom: 18px;
}

.rail__mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--avatar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

.rail__brand-text {
    display: flex;
    flex-direction: column;
}

.rail__brand-name {
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.rail__brand-sub {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--rail-text-muted);
}

.rail__sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
}

.rail__section-title {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rail-text-muted);
    padding: 0 10px;
    margin-bottom: 6px;
}

.rail__nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rail__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--rail-text-muted);
    transition: all 0.18s ease;
}

.rail__icon-box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.rail__icon-box svg {
    width: 16px;
    height: 16px;
}

.rail__link:hover {
    color: var(--rail-text);
    background: var(--rail-link-hover);
}

.rail__link.is-active {
    background: var(--rail-link-active);
    color: var(--rail-text);
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

/* Sidebar Foot (3-Theme Toggle & User Card) */
.rail__foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--rail-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 3-Theme Segmented Switcher */
.theme-switcher {
    display: flex;
    background: var(--chip-bg);
    padding: 3px;
    border-radius: 10px;
    border: 1px solid var(--rail-border);
}

.theme-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 5px 8px;
    font-size: 0.74rem;
    font-weight: 700;
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.18s ease;
}

.theme-btn:hover {
    color: var(--text);
}

.theme-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

/* User Profile Card in Sidebar */
.rail__user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 12px;
    background: var(--chip-bg);
}

.rail__user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--avatar-bg);
    color: var(--avatar-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.rail__user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.rail__user-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rail__user-role {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 600;
}

.rail__out {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.15s ease;
}

.rail__out:hover {
    color: var(--error);
    background: var(--error-bg);
}

/* =========================================================
   CONTAINER & STAGE
   ========================================================= */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 28px 40px;
}

.container--wide {
    max-width: 1440px;
}

.pagehead {
    margin-bottom: 24px;
}

.pagehead h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin: 0;
    color: var(--text);
}

/* =========================================================
   MOBILE TOPBAR & BOTTOM DOCK
   ========================================================= */
.mobar {
    display: none;
}

.dock {
    display: none;
}

.sheet {
    border: none;
    border-radius: 24px 24px 0 0;
    background: transparent;
    padding: 0;
    max-width: 100%;
    width: 100%;
    margin: auto 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
}

.sheet::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.sheet__card {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 20px 18px calc(24px + env(safe-area-inset-bottom, 0px));
    border-radius: 24px 24px 0 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.sheet__title-group {
    display: flex;
    flex-direction: column;
}

.sheet__title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
}

.sheet__user {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.sheet__theme-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sheet__section-label {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.sheet__nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sheet__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    background: var(--chip-bg);
}

.sheet__link.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.sheet__link--danger {
    color: var(--error);
}

.sheet__icon-box {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sheet__icon-box svg {
    width: 18px;
    height: 18px;
}

/* =========================================================
   RESPONSIVE MEDIA QUERIES (MOBILE HYBRID)
   ========================================================= */
@media (max-width: 860px) {
    .rail {
        display: none;
    }

    .mobar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: var(--rail-bg);
        border-bottom: 1px solid var(--rail-border);
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .mobar__brand {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 1rem;
        font-weight: 800;
        text-decoration: none;
        color: var(--text);
    }

    .mobar__actions {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobar__user-avatar {
        width: 28px;
        height: 28px;
        border-radius: 8px;
        background: var(--avatar-bg);
        color: var(--avatar-text);
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 800;
        font-size: 0.78rem;
    }

    .container {
        padding: 12px 10px calc(24px + var(--dock-h) + env(safe-area-inset-bottom, 0px));
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .dock {
        display: flex;
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        height: var(--dock-h);
        background: var(--surface-glass);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid var(--border);
        border-radius: 20px;
        padding: 4px 6px;
        z-index: 90;
        box-shadow: var(--shadow-lg);
        align-items: center;
        justify-content: space-around;
    }

    .dock__a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: transparent;
        border: none;
        color: var(--text-muted);
        text-decoration: none;
        font-size: 0.68rem;
        font-weight: 700;
        padding: 4px 10px;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.18s ease;
    }

    .dock__icon svg {
        width: 18px;
        height: 18px;
    }

    .dock__a.is-active {
        color: var(--text);
        background: var(--chip-bg);
    }
}
