/* Cores da Silver Sistemas — Layout A (Rail + Command) */
:root {
    --primary-start: #02577a;
    --primary-end: #89d6fb;
    --primary: #02577a;
    --accent: #89d6fb;
    --dark: #012c39;
    --darker: #001b27;
    --white: #ffffff;
    --light-gray: #f5f5f5;
    --surface: #ffffff;
    --surface-2: #f0f5f7;
    --border: #e2e8ec;
    --gray: #cccccc;
    --text-muted: #5a6a72;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --on-accent: #f4f7f8;
    --rail-bg: #001b27;
    --hover: #f0f5f7;
    --warn-bg: #fff3cd;
    --warn-fg: #856404;
    --warn-border: #ffc107;
    --info-bg: #e7f1ff;
    --info-fg: #084298;
    --rail-width: 220px;
    --rail-collapsed: 56px;
    --command-h: 48px;
    --row-h: 30px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--light-gray);
    min-height: 100vh;
    color: var(--darker);
}

body:not(.app-shell):not(.login-page) {
    background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

/* ========== App shell (Layout A) ========== */
body.app-shell {
    display: flex;
    background: var(--light-gray);
    overflow: hidden;
}

.app-rail {
    width: var(--rail-width);
    flex-shrink: 0;
    background: var(--rail-bg);
    color: #e8eef1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    border-right: 1px solid rgba(137, 214, 251, 0.12);
    z-index: 40;
    transition: width 0.18s ease;
}

.app-rail-brand {
    min-height: 76px;
    display: flex;
    align-items: center;
    padding: 0.9rem 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.app-rail-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    min-width: 0;
    width: 100%;
}

.app-rail-logo-full {
    width: 100%;
    height: auto;
    max-height: 56px;
    object-fit: contain;
    object-position: left center;
    display: block;
    background: transparent;
}

.app-rail-logo-mark {
    display: none;
    width: 36px;
    height: 36px;
    margin: 0 auto;
    object-fit: contain;
    background: transparent;
}

.app-rail-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-rail-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.65rem;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.app-rail-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e8eef1;
}

.app-rail-link.is-active {
    background: rgba(2, 87, 122, 0.55);
    border-color: rgba(137, 214, 251, 0.35);
    color: #e8eef1;
    box-shadow: inset 2px 0 0 var(--accent);
}

.app-rail-ico {
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.9;
}

.app-rail-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-rail-toggle {
    margin: 0.5rem;
    padding: 0.35rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.app-rail-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
}

body.rail-collapsed .app-rail {
    width: var(--rail-collapsed);
}

body.rail-collapsed .app-rail-logo-full {
    display: none;
}

body.rail-collapsed .app-rail-logo-mark {
    display: flex;
}

body.rail-collapsed .app-rail-label {
    display: none;
}

body.rail-collapsed .app-rail-link {
    justify-content: center;
    padding: 0.55rem 0.35rem;
}

body.rail-collapsed .app-rail-brand {
    padding: 0 0.35rem;
    justify-content: center;
}

.app-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--light-gray);
}

.app-command {
    height: var(--command-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem;
    background: var(--white);
    border-bottom: 1px solid var(--border);
}

.app-command-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.app-command-menu {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: var(--dark);
}

.app-command-titles {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}

.app-command-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--darker);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-command-client {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.app-command-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.app-command-user {
    font-size: 0.78rem;
    color: var(--text-muted);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-command-logout {
    margin: 0;
}

.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;
}

.tema-switch {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.tema-switch-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.01em;
    user-select: none;
}

html[data-tema="claro"] #temaLabelClaro,
html[data-tema="escuro"] #temaLabelEscuro {
    color: var(--darker);
}

.tema-switch-ctl.switch {
    width: 40px;
    height: 22px;
}

.tema-switch-ctl .slider:before {
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
}

.tema-switch-ctl input:checked + .slider:before,
.tema-switch-ctl.switch input[type="checkbox"]:checked + .slider:before {
    transform: translateX(18px);
}

.tema-switch-ctl input:focus-visible + .slider {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-nav-logout {
    background: transparent;
    color: var(--dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
}

.btn-nav-logout:hover {
    background: var(--light-gray);
    border-color: var(--primary);
    color: var(--primary);
}

/* Main content — full-bleed no shell */
body.app-shell .main-content,
body.app-shell .main-content-full {
    flex: 1;
    min-height: 0;
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 0.75rem 1rem 1rem;
    overflow: auto;
    scrollbar-gutter: stable;
}

/* Barras sempre visíveis quando há overflow (Windows overlay esconde). */
body.app-shell .main-content::-webkit-scrollbar,
body.app-shell .main-content-full::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}
body.app-shell .main-content::-webkit-scrollbar-thumb,
body.app-shell .main-content-full::-webkit-scrollbar-thumb {
    background: #9aa7ad;
    border-radius: 6px;
}
body.app-shell .main-content::-webkit-scrollbar-track,
body.app-shell .main-content-full::-webkit-scrollbar-track {
    background: #e8eef1;
}

/* Páginas legadas que forçavam altura pela navbar antiga */
body.app-shell .dashboard-page,
body.app-shell .fila-page,
body.app-shell .chaves-geradas-page,
body.app-shell .chaves-page,
body.app-shell .integracoes-page {
    min-height: 0 !important;
}

/* Legacy navbar (páginas sem shell / compat) */
.navbar {
    background: var(--darker);
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.navbar-inner {
    max-width: 100%;
    margin: 0 auto;
}

.navbar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-brand h1 {
    color: var(--white);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
}

.nav-user-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.nav-user-email {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.8125rem;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-logout-form {
    margin: 0;
}

.navbar-nav {
    display: flex;
    justify-content: center;
    padding: 0.7rem 1.5rem 0.85rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    padding: 0;
    max-width: 1400px;
}

.nav-menu li {
    display: flex;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    display: inline-block;
    line-height: 1.2;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.24);
    color: var(--white);
}

.nav-link.active {
    background: linear-gradient(135deg, var(--primary-start) 0%, #037ba8 100%);
    border-color: transparent;
    color: var(--white);
    box-shadow: 0 2px 8px rgba(2, 87, 122,.35);
}

/* Cards */
.card {
    background: var(--white);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    box-shadow: none;
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--darker);
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--darker);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s;
    background: var(--white);
    color: var(--darker);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-start);
    box-shadow: 0 0 0 3px rgba(2, 87, 122, 0.1);
}

.form-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--white);
    color: var(--darker);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--darker);
}

.btn-primary {
    background: var(--primary-start);
    color: var(--on-accent);
}

.btn-primary:hover {
    background: #036a94;
    box-shadow: 0 2px 6px rgba(2, 87, 122, 0.25);
}

.btn-success {
    background: var(--success);
    color: var(--on-accent);
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: var(--danger);
    color: var(--on-accent);
}

.btn-danger:hover {
    background: #c82333;
}

.btn-secondary {
    background: var(--gray);
    color: var(--on-accent);
}

.btn-secondary:hover {
    background: #5a6a72;
}

.btn-outline-secondary {
    background: var(--white);
    color: var(--darker);
    border: 1px solid var(--border);
}

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.table th,
.table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.table th {
    background: var(--light-gray);
    font-weight: 600;
    color: var(--darker);
}

.table tr:hover {
    background: var(--hover);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-success {
    background: var(--success);
    color: var(--on-accent);
}

.badge-danger {
    background: var(--danger);
    color: var(--on-accent);
}

.badge-warning {
    background: var(--warning);
    color: var(--darker);
}

.badge-info {
    background: var(--primary-start);
    color: var(--on-accent);
}

.badge-secondary {
    background: var(--gray);
    color: var(--on-accent);
}

.badge-light {
    background: var(--surface-2);
    color: var(--darker);
    border: 1px solid var(--border);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-start);
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--darker);
    font-size: 1rem;
    font-weight: 500;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray);
    transition: background-color 0.4s ease;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: var(--white);
    transition: transform 0.4s ease;
    border-radius: 50%;
    will-change: transform;
}

input:checked + .slider {
    background-color: var(--primary-start);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.switch input[type="checkbox"]:checked + .slider {
    background-color: var(--primary-start);
}

.switch input[type="checkbox"]:checked + .slider:before {
    transform: translateX(26px);
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--darker);
}

.spinner {
    border: 4px solid var(--light-gray);
    border-top: 4px solid var(--primary-start);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

/* Category Cards */
.category-card {
    margin-bottom: 0.75rem !important;
    border-left: 3px solid var(--primary-start) !important;
    border-radius: 6px;
    padding: 0.5rem !important;
}

.category-card .card-header {
    background: var(--primary-start) !important;
    color: var(--on-accent) !important;
    padding: 0.5rem 0.75rem !important;
    border-radius: 0 !important;
    border-bottom: none !important;
    margin-bottom: 0.5rem !important;
}

.category-card .card-header h3 {
    color: var(--on-accent) !important;
    margin: 0 !important;
    font-weight: 600;
    font-size: 0.9rem !important;
}

.category-card .table-container {
    padding: 0;
}

.category-card .table {
    margin-top: 0;
    font-size: 0.875rem;
}

/* Login */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: var(--darker);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: 8px;
    padding: 2rem;
    border: 1px solid var(--border);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.login-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.login-brand img {
    height: 56px;
    width: auto;
    max-width: 280px;
    background: transparent;
}

.login-card h1 {
    font-size: 1.15rem;
    color: var(--darker);
    margin-bottom: 0.35rem;
    text-align: center;
}

.login-card .subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-erro {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
    border-radius: 4px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.login-card .btn-primary {
    width: 100%;
    margin-top: 0.5rem;
}

.login-ok {
    background: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
    border-radius: 4px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.login-links {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
}

.login-links a {
    color: #1a5f7a;
    text-decoration: none;
}

.login-links a:hover {
    text-decoration: underline;
}

.modal-reset-senha {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 80;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    padding: 1rem;
}

.modal-reset-senha.is-open {
    display: flex;
}

.modal-reset-senha .login-card {
    margin: 0;
    max-width: 400px;
}

/* Responsive */
@media (max-width: 900px) {
    .app-rail {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    body.rail-open-mobile .app-rail {
        transform: translateX(0);
    }

    body.rail-collapsed .app-rail {
        width: var(--rail-width);
    }

    body.rail-collapsed .app-rail-logo-full {
        display: block;
    }

    body.rail-collapsed .app-rail-logo-mark {
        display: none;
    }

    body.rail-collapsed .app-rail-label {
        display: inline;
    }

    .app-command-menu {
        display: inline-flex;
    }

    .app-rail-toggle {
        display: none;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .app-command-user {
        display: none;
    }
}

/*
 * Tema escuro — fotofobia / estresse visual (Irlen) / WCAG 2.2
 * Fundo off-black (#12171b) e texto off-white (#e8eef1): evita glare de #FFF e
 * blooming de #000. Contraste texto ≥ 4,5:1. Rail permanece navy (--rail-bg).
 */
html[data-tema="escuro"] {
    color-scheme: dark;
    --white: #1c242b;
    --surface: #1c242b;
    --surface-2: #243039;
    --light-gray: #12171b;
    --darker: #e8eef1;
    --dark: #d5dee3;
    --border: #3d4f58;
    --gray: #4a5c66;
    --text-muted: #a8b6bd;
    --on-accent: #f4f7f8;
    --rail-bg: #001b27;
    --hover: #243039;
    --success: #2f9e57;
    --danger: #d4535f;
    --warning: #d4a017;
    --warn-bg: #3d3214;
    --warn-fg: #f0d78c;
    --warn-border: #7a6828;
    --info-bg: #16343d;
    --info-fg: #a8e4ef;
}
