/* ============================================================
   VARIÁVEIS GLOBAIS
   ============================================================ */
:root {
    --primary: #0a1a3a;
    --primary-light: #1a3f7a;
    --primary-dark: #07122c;
    --secondary: #2563eb;
    --secondary-light: #3b82f6;
    --secondary-dark: #1e40af;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --topbar-height: 60px;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================================
   BODY
   ============================================================ */
body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f8fafc;
    background-image:
        radial-gradient(at 0% 0%,   rgba(37, 99, 235, 0.06)  0px, transparent 50%),
        radial-gradient(at 100% 0%,  rgba(16, 185, 129, 0.05)  0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.06) 0px, transparent 50%),
        radial-gradient(at 0%   100%, rgba(139, 92, 246, 0.04) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.5;
    overflow-x: hidden;
}

body.menu-open {
    overflow: hidden;
}

/* ============================================================
   LAYOUT CONTAINER
   ============================================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   OVERLAY DO SIDEBAR (mobile)
   ============================================================ */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    cursor: pointer;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================================
   SIDEBAR — REDESIGN
   ============================================================ */
:root {
    --sb-bg:        #0c1b3b;
    --sb-bg-end:    #0f2454;
    --sb-border:    rgba(255,255,255,0.07);
    --sb-hover:     rgba(255,255,255,0.07);
    --sb-text:      rgba(255,255,255,0.72);
    --sb-muted:     rgba(148,163,184,0.5);
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(175deg, var(--sb-bg) 0%, var(--sb-bg-end) 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: visible;
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1),
                width  0.35s cubic-bezier(0.4,0,0.2,1);
    z-index: 1000;
    box-shadow: 4px 0 32px rgba(0,0,0,0.28);
    border-right: 1px solid var(--sb-border);
    flex-shrink: 0;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 55%, transparent 100%);
    pointer-events: none;
}

.sidebar::-webkit-scrollbar       { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* ---- Brand ---- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1.3rem 1.1rem 1.15rem;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
    overflow: hidden;
}

.brand-icon {
    width: 37px;
    height: 37px;
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(37,99,235,0.4);
    overflow: hidden;
}
.brand-icon-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.brand-text { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.brand-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 0.64rem;
    color: var(--sb-muted);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-top: 1px;
}

/* ---- User card ---- */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin: 0.8rem 0.8rem;
    padding: 0.75rem 0.875rem;
    background: rgba(255,255,255,0.055);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 12px;
    text-decoration: none;
    color: white;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-user:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-1px);
}

/* ---- Avatar (shared between sidebar-user and global.js) ---- */
.user-avatar {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--secondary), var(--secondary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}

.user-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ---- User details ---- */
.user-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.user-details h4 {
    font-size: 0.83rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.12rem;
}

.user-details span {
    font-size: 0.72rem;
    color: var(--sb-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.sidebar-user-arrow {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.25);
    flex-shrink: 0;
    transition: transform 0.2s, color 0.2s;
}

.sidebar-user:hover .sidebar-user-arrow {
    transform: translateX(3px);
    color: rgba(255,255,255,0.5);
}

/* ---- Navigation ---- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.4rem 0.7rem;
}

.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section { margin-bottom: 0.25rem; }

.nav-label {
    display: block;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--sb-muted);
    padding: 0.6rem 0.6rem 0.3rem;
}

.nav-menu { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.nav-item { margin: 0; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.65rem 0.8rem;
    color: var(--sb-text);
    text-decoration: none;
    border-radius: 9px;
    font-size: 0.86rem;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    transition: background 0.16s ease, color 0.16s ease;
}

.nav-link i {
    width: 18px;
    font-size: 0.92rem;
    flex-shrink: 0;
    text-align: center;
    transition: transform 0.16s ease;
}

.nav-link:hover              { background: var(--sb-hover); color: #fff; }
.nav-link:hover i            { transform: scale(1.12); }

.nav-link.active {
    background: linear-gradient(135deg, rgba(37,99,235,0.82), rgba(59,130,246,0.68));
    color: #fff;
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(37,99,235,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Tooltip when collapsed */
.nav-link[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(15,23,42,0.96);
    color: #fff;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.78rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    z-index: 2000;
}

.sidebar.collapsed .nav-link[data-tooltip]:hover::after { opacity: 1; }

/* ---- Admin collapsible ---- */
.nav-admin-toggle {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.nav-admin-chevron {
    margin-left: auto;
    font-size: 0.7rem !important;
    width: auto !important;
    transition: transform 0.22s ease;
}
.nav-admin-toggle[aria-expanded="true"] .nav-admin-chevron { transform: rotate(180deg); }
.sidebar.collapsed .nav-admin-chevron { display: none; }

.nav-admin-submenu {
    list-style: none;
    display: none;
    padding: 0;
    margin: 0;
}
.nav-admin-submenu.open { display: block; }

.nav-sublink {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.5rem 0.8rem 0.5rem 2.5rem;
    color: var(--sb-text);
    text-decoration: none;
    border-radius: 9px;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.16s ease, color 0.16s ease;
}
.nav-sublink i { width: 16px; font-size: 0.82rem; flex-shrink: 0; text-align: center; }
.nav-sublink:hover { background: var(--sb-hover); color: #fff; }
.nav-sublink.active {
    background: linear-gradient(135deg, rgba(37,99,235,0.82), rgba(59,130,246,0.68));
    color: #fff;
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(37,99,235,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}
.sidebar.collapsed .nav-admin-submenu { display: none; }

/* ---- Footer / Logout ---- */
.sidebar-footer {
    padding: 0.7rem;
    border-top: 1px solid var(--sb-border);
    flex-shrink: 0;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.65rem 0.8rem;
    border-radius: 9px;
    color: rgba(255,255,255,0.42);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.16s, color 0.16s;
}

.sidebar-logout:hover { background: rgba(239,68,68,0.12); color: #f87171; }

.sidebar-logout i { width: 18px; font-size: 0.92rem; text-align: center; flex-shrink: 0; }

/* ============================================================
   COLLAPSE BUTTON (desktop only)
   ============================================================ */
.collapse-btn {
    position: absolute;
    top: 22px;
    right: -13px;
    z-index: 1001;
    width: 26px;
    height: 26px;
    background: #2563eb;
    color: white;
    border-radius: 50%;
    border: 2px solid #0c1b3b;
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    transition: background 0.2s, transform 0.2s;
}

.collapse-btn:hover { background: #1d4ed8; transform: scale(1.12); }

/* ============================================================
   HAMBURGER (mobile only)
   ============================================================ */
.hamburger {
    display: none;
    position: fixed;
    top: 0.875rem;
    right: 0.875rem;
    z-index: 1002;
    width: 44px;
    height: 44px;
    background: white;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
    transition: box-shadow 0.2s, transform 0.2s;
}

.hamburger:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.15); transform: scale(1.04); }

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #1e40af;
    border-radius: 2px;
    transition: all 0.28s cubic-bezier(0.4,0,0.2,1);
    pointer-events: none;
}

.hamburger.active span:nth-child(1) { transform: translateY(7px)  rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; transform: translateX(-8px); }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   CONTEÚDO PRINCIPAL
   ============================================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
    background: transparent;
    transition: margin-left 0.3s ease;
    min-width: 0;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    border: 1px solid var(--gray-200);
    margin-top: 20px;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.card-header h3 { font-size: 1.2rem; color: var(--gray-800); font-weight: 600; }
.card-header i  { color: var(--secondary); font-size: 1.5rem; }

/* ============================================================
   SISTEMA DE GRIDS
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; }

/* ============================================================
   BOTÕES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }

/* ============================================================
   BARRA DE FILTROS
   ============================================================ */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
    padding: 1rem;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--gray-100);
    padding: 0.5rem;
    border-radius: var(--radius-md);
}

.filter-group i { color: var(--gray-500); margin-left: 0.5rem; }

.filter-select {
    padding: 0.5rem 2rem 0.5rem 1rem;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    color: var(--gray-700);
    cursor: pointer;
    outline: none;
    min-width: 0;
}

.filter-select:hover { color: var(--secondary); }

/* ============================================================
   TABELAS
   ============================================================ */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

th {
    background: var(--gray-100);
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 1rem;
    text-align: left;
    white-space: nowrap;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-600);
}

tr:hover td { background: var(--gray-50); }

/* ============================================================
   METRIC CARDS
   ============================================================ */
.metric-card {
    background: linear-gradient(135deg, white, var(--gray-50));
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--gray-200);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.3rem;
}

.metric-label {
    font-size: 0.9rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   GRÁFICOS
   ============================================================ */
.chart-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--gray-200);
}

/* ============================================================
   RANKING
   ============================================================ */
.ranking-list { list-style: none; }

.ranking-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.ranking-item:last-child { border-bottom: none; }

.ranking-position {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.ranking-position.top-1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.ranking-position.top-2 { background: linear-gradient(135deg, #94a3b8, #64748b); }
.ranking-position.top-3 { background: linear-gradient(135deg, #b45309, #92400e); }

.ranking-info     { flex: 1; min-width: 0; }
.ranking-name     { font-weight: 600; color: var(--gray-800); margin-bottom: 0.2rem; }
.ranking-stats    { font-size: 0.8rem; color: var(--gray-500); }
.ranking-score    { font-weight: 700; color: var(--secondary); font-size: 1.2rem; white-space: nowrap; }

/* ============================================================
   CARTÕES DE QUESTÕES
   ============================================================ */
.question-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--gray-200);
    transition: box-shadow 0.3s ease;
}

.question-card:hover { box-shadow: var(--shadow-lg); }

.question-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gray-100);
}

.question-tag {
    padding: 0.3rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.tag-clinica     { background: #e0f2fe; color: #0369a1; }
.tag-cirurgia    { background: #fee2e2; color: #b91c1c; }
.tag-pediatria   { background: #dcfce7; color: #166534; }
.tag-ginecologia { background: #fae8ff; color: #a21caf; }

.question-text {
    font-size: 1.1rem;
    color: var(--gray-800);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* ============================================================
   OPÇÕES DE RESPOSTA
   ============================================================ */
.options-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.option-item:hover { background: var(--gray-100); }

.option-item.selected {
    border-color: var(--secondary);
    background: #eef2ff;
}

.option-prefix {
    width: 30px;
    height: 30px;
    background: white;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    flex-shrink: 0;
}

.option-item.selected .option-prefix {
    background: var(--secondary);
    color: white;
    border-color: var(--secondary);
}

/* ============================================================
   BARRA DE PROGRESSO
   ============================================================ */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--secondary-light));
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

/* ============================================================
   RESPONSIVIDADE
   ============================================================ */

/* Previne overflow em grid items */
.grid-2 > *,
.grid-3 > *,
.grid-4 > * { min-width: 0; }

/* Desktop grande (≤1400px) */
@media (max-width: 1400px) {
    .main-content { padding: 2rem 1.5rem; }
}

/* Desktop (≤1200px) */
@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

/* Notebook / Tablet landscape (≤1024px) */
@media (max-width: 1024px) {
    .main-content { padding: 1.5rem 1.25rem; }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ─────────────────────────────────────────────
   900px — sidebar vira drawer
   ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .hamburger     { display: flex; }
    .collapse-btn  { display: none !important; }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
        overflow: hidden;
        height: 100vh;
        height: 100svh; /* exclui barra do browser em iOS/Android */
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 8px 0 40px rgba(0,0,0,0.3);
    }

    .sidebar-nav {
        min-height: 0;
        flex: 1;
        overflow-y: auto;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 4.5rem 1.25rem 1.5rem;
    }

    .filters-bar   { flex-direction: column; align-items: stretch; }
    .filter-group  { width: 100%; }
    .filter-select { width: 100%; }
}

/* Tablet portrait / Telas médias (≤768px) */
@media (max-width: 768px) {
    .main-content { padding: 4.5rem 1rem 1.5rem; }
    .card { padding: 1.25rem; }
    .metric-value { font-size: 1.5rem; }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    /* grid-2 e grid-3 empilham em móbile */
    .grid-2,
    .grid-3 { grid-template-columns: 1fr; }

    /* Tabela: texto menor e padding compacto */
    th { padding: 0.7rem 0.6rem; font-size: 0.82rem; }
    td { padding: 0.7rem 0.6rem; font-size: 0.85rem; }
}

/* Mobile (≤640px) — grid-4 vira 2 colunas */
@media (max-width: 640px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .metric-value { font-size: 1.3rem; }
    .metric-label { font-size: 0.78rem; }
}

/* Mobile pequeno (≤480px) */
@media (max-width: 480px) {
    .hamburger { top: 0.75rem; right: 0.75rem; }
    .main-content { padding: 4rem 0.75rem 1.5rem; }
    .card { padding: 1rem; }
    .question-header { flex-direction: column; align-items: flex-start; }
    .option-item { padding: 0.75rem; }
    .btn { padding: 0.6rem 1rem; font-size: 0.85rem; }
}

/* Mobile extra pequeno (≤360px) */
@media (max-width: 360px) {
    .main-content { padding: 3.75rem 0.5rem 1rem; }
    .card { padding: 0.875rem; }
    .grid-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   MODO ESCURO — Dark Mode
   ============================================================ */

/* Botão de toggle no sidebar */
.dm-toggle {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.65rem 0.8rem;
    border-radius: 9px;
    color: rgba(255,255,255,0.42);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 500;
    white-space: nowrap;
    width: 100%;
    text-align: left;
    transition: background 0.16s, color 0.16s;
    font-family: inherit;
}
.dm-toggle:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.72); }
.dm-toggle i { width: 18px; font-size: 0.92rem; text-align: center; flex-shrink: 0; }
.sidebar.collapsed .dm-toggle span { display: none; }
.sidebar.collapsed .dm-toggle { justify-content: center; padding: 0.7rem; gap: 0; }

/* ── Body ── */
[data-theme="dark"] body {
    background-color: #0a1628;
    background-image:
        radial-gradient(at 0% 0%,   rgba(37,99,235,0.10) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59,130,246,0.07) 0px, transparent 50%);
    color: #e2e8f0;
}

/* ── Hamburger ── */
[data-theme="dark"] .hamburger {
    background: #1e293b;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
[data-theme="dark"] .hamburger span { background: #60a5fa; }

/* ── Cards ── */
[data-theme="dark"] .card {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
[data-theme="dark"] .card:hover { box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
[data-theme="dark"] .card-header { border-bottom-color: #334155; }
[data-theme="dark"] .card-header h3 { color: #f1f5f9; }

/* ── Métricas ── */
[data-theme="dark"] .metric-card {
    background: linear-gradient(135deg, #1e293b, #243451);
    border-color: #334155;
}
[data-theme="dark"] .metric-value { color: #f1f5f9; }
[data-theme="dark"] .metric-label { color: #94a3b8; }

/* ── Tabelas ── */
[data-theme="dark"] table { background: #1e293b; }
[data-theme="dark"] th { background: #253347; color: #cbd5e1; border-bottom: 1px solid #334155; }
[data-theme="dark"] td { border-bottom-color: #334155; color: #94a3b8; }
[data-theme="dark"] tr:hover td { background: #2a3a52; }

/* ── Chart container ── */
[data-theme="dark"] .chart-container { background: #1e293b; border-color: #334155; }

/* ── Premium header (dashboard) ── */
[data-theme="dark"] .premium-header {
    background: linear-gradient(135deg, #1e293b, #243451);
    border-color: #334155;
}
[data-theme="dark"] .goal-box {
    background: rgba(59,130,246,0.08);
    border-color: rgba(59,130,246,0.25);
}
[data-theme="dark"] .goal-progress-bar { background: #334155; }

/* ── Período buttons ── */
[data-theme="dark"] .periodo-btn { background: #253347; border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .periodo-btn:hover { background: #334155; color: #e2e8f0; }
[data-theme="dark"] .periodo-btn.active { background: rgba(59,130,246,0.15); border-color: #3b82f6; color: #60a5fa; }

/* ── Ranking cols ── */
[data-theme="dark"] .ranking-cols .card { background: #1e293b; }

/* ── Filter wizard (questões) ── */
[data-theme="dark"] .filter-wizard-container { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .wizard-category-bar { background: #19243a; border-bottom-color: #334155; }
[data-theme="dark"] .smart-filter-row,
[data-theme="dark"] .secondary-filters,
[data-theme="dark"] .generate-bar { border-bottom-color: #334155; }
[data-theme="dark"] .wizard-category-label { color: #64748b; }

/* ── Smart Selects ── */
[data-theme="dark"] .smart-select-trigger {
    background: #253347; border-color: #475569; color: #e2e8f0;
}
[data-theme="dark"] .smart-select-trigger:hover { border-color: #3b82f6; }
[data-theme="dark"] .smart-select.open .smart-select-trigger {
    border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
[data-theme="dark"] .smart-select-value { color: #e2e8f0; }
[data-theme="dark"] .smart-select-value.placeholder { color: #64748b; }
[data-theme="dark"] .smart-dropdown {
    background: #1e293b; border-color: #475569; box-shadow: 0 10px 35px rgba(0,0,0,0.45);
}
[data-theme="dark"] .smart-search { background: #253347; border-bottom-color: #334155; }
[data-theme="dark"] .smart-search input { color: #e2e8f0; }
[data-theme="dark"] .smart-option { color: #cbd5e1; }
[data-theme="dark"] .smart-option:hover { background: #334155; }
[data-theme="dark"] .smart-option.selected { background: rgba(59,130,246,0.14); color: #60a5fa; }
[data-theme="dark"] .smart-option.selected .option-count { background: rgba(59,130,246,0.2); color: #60a5fa; }
[data-theme="dark"] .option-count { background: #334155; color: #64748b; }

/* ── Selects e Inputs nativos ── */
[data-theme="dark"] .modern-select,
[data-theme="dark"] .modern-input {
    background-color: #253347; border-color: #475569; color: #e2e8f0;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' 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");
}
[data-theme="dark"] .modern-select:focus,
[data-theme="dark"] .modern-input:focus {
    background-color: #1e293b; border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* ── Filtros modernos container ── */
[data-theme="dark"] .modern-filters-container { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .filter-group {
    background: #253347; border-color: #475569; color: #e2e8f0;
}

/* ── Active filter tags ── */
[data-theme="dark"] .active-tag { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.3); color: #60a5fa; }
[data-theme="dark"] .btn-clear-filters { border-color: #475569; color: #64748b; }
[data-theme="dark"] .btn-clear-filters:hover { border-color: #ef4444; color: #ef4444; background: rgba(239,68,68,0.08); }

/* ── Questão card ── */
[data-theme="dark"] .question-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .question-card::before { background: linear-gradient(180deg, #3b82f6, #60a5fa); }
[data-theme="dark"] .question-text { color: #cbd5e1; }
[data-theme="dark"] .question-header { border-bottom-color: #334155; }

/* ── Opções de resposta ── */
[data-theme="dark"] .option-item { background: #253347; border-color: transparent; }
[data-theme="dark"] .option-item:hover { background: #2d3f5c; }
[data-theme="dark"] .option-item.selected { background: rgba(59,130,246,0.10); border-color: #3b82f6; }
[data-theme="dark"] .option-prefix { background: #334155; border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .option-item.selected .option-prefix { background: #3b82f6; border-color: #3b82f6; color: white; }
[data-theme="dark"] .option-text { color: #cbd5e1; }

/* ── Action row border ── */
[data-theme="dark"] .q-actions-row { border-top-color: #334155; }

/* ── Chips de subdisciplina ── */
[data-theme="dark"] .chip-item label {
    background: #253347; border-color: #475569; color: #94a3b8;
}
[data-theme="dark"] .chip-item input[type="checkbox"]:checked + label {
    background: rgba(59,130,246,0.12); border-color: #3b82f6; color: #60a5fa;
}

/* ── Botão de comentários ── */
[data-theme="dark"] #toggle-comments-btn {
    border-color: #475569 !important; color: #94a3b8 !important;
}

/* ── Comments ── */
[data-theme="dark"] .comment-item { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .comment-item:hover { border-color: #475569; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
[data-theme="dark"] .comment-reply { background: #253347; border-left-color: #475569; }
[data-theme="dark"] .comment-author { color: #e2e8f0; }
[data-theme="dark"] .comment-text { color: #94a3b8; }
[data-theme="dark"] .subdiscipline-item { border-bottom-color: #334155; }

/* ── Report modal ── */
[data-theme="dark"] .report-box { background: #1e293b; }
[data-theme="dark"] .report-header { border-bottom-color: #334155; }
[data-theme="dark"] .report-header h3 { color: #f1f5f9; }
[data-theme="dark"] .report-label { color: #cbd5e1; }
[data-theme="dark"] .report-footer { border-top-color: #334155; }
[data-theme="dark"] .report-close { background: #334155; color: #94a3b8; }
[data-theme="dark"] .report-close:hover { background: #475569; }
[data-theme="dark"] .report-type-chip { background: #253347; border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .report-type-chip.active { border-color: #ef4444; background: rgba(239,68,68,0.08); color: #ef4444; }
[data-theme="dark"] .report-textarea { background: #253347; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .report-btn-cancel { background: #253347; border-color: #475569; color: #94a3b8; }

/* ── Flashcards ── */
[data-theme="dark"] .flashcard-front,
[data-theme="dark"] .flashcard-back { background: #1e293b !important; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .folder-item { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .folder-item:hover { border-color: #3b82f6; box-shadow: 0 8px 24px rgba(59,130,246,0.12); }
[data-theme="dark"] .folder-name { color: #e2e8f0; }
[data-theme="dark"] .folder-count { background: rgba(59,130,246,0.12); color: #60a5fa; }
[data-theme="dark"] .fc-tabs { background: #253347; }
[data-theme="dark"] .fc-tab { color: #64748b; }
[data-theme="dark"] .fc-tab.active { background: #334155; color: #e2e8f0; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
[data-theme="dark"] .biblioteca-header { background: rgba(59,130,246,0.06); border-color: rgba(59,130,246,0.18); }

/* ── Search bar ── */
[data-theme="dark"] .search-bar-wrapper { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .search-bar-wrapper input { color: #e2e8f0; }
[data-theme="dark"] .search-bar-wrapper input::placeholder { color: #475569; }
[data-theme="dark"] .search-bar-wrapper i { color: #475569; }

/* ── Flashcard modal subject selector ── */
[data-theme="dark"] .subject-input-wrapper { background: #253347; border-color: #475569; }
[data-theme="dark"] .subject-input-wrapper input { color: #e2e8f0; }
[data-theme="dark"] .subject-dropdown { background: #1e293b; border-color: #475569; }
[data-theme="dark"] .subject-chip { background: rgba(59,130,246,0.08); border-color: rgba(59,130,246,0.25); color: #60a5fa; }
[data-theme="dark"] .subject-chip:hover,
[data-theme="dark"] .subject-chip.selected { background: #3b82f6; color: white; border-color: #3b82f6; }
[data-theme="dark"] .modal .card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .modal .card h3 { color: #f1f5f9; }

/* ── Botões ── */
[data-theme="dark"] .btn-secondary { background: #334155; color: #cbd5e1; }
[data-theme="dark"] .btn-secondary:hover { background: #475569; }
[data-theme="dark"] .btn-skip-question { border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .btn-skip-question:hover { background: #334155; color: #e2e8f0; border-color: #64748b; }
[data-theme="dark"] .btn-report-error { border-color: #7f1d1d; color: #f87171; }
[data-theme="dark"] .btn-report-error:hover { background: rgba(239,68,68,0.08); }

/* ── Filtros gerais bar ── */
[data-theme="dark"] .filters-bar { background: #1e293b; }
[data-theme="dark"] .filter-group { background: #253347; }
[data-theme="dark"] .filter-select { color: #e2e8f0; background: transparent; }

/* ── Scrollbar ── */
[data-theme="dark"] ::-webkit-scrollbar-track { background: #0a1628; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #334155; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ── Main content ── */
[data-theme="dark"] .main-content { background: transparent; }

/* ── Inputs, textareas e selects genéricos ── */
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
[data-theme="dark"] textarea {
    background-color: #1a2742;
    border-color: #2d4060;
    color: #e2e8f0;
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: #475569; }

/* ── Sidebar overlay (mobile) ── */
[data-theme="dark"] .sidebar-overlay { background: rgba(0,0,0,0.75); }

/* ── Toast ── */
[data-theme="dark"] .toast {
    background: #1a2742;
    border: 1px solid #2d4060;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    color: #e2e8f0;
}
[data-theme="dark"] .toast-content p { color: #cbd5e1; }

/* ── Explanation container (override inline style) ── */
[data-theme="dark"] #explanation-container > div {
    background: rgba(14,165,233,0.07) !important;
    border-left-color: #0ea5e9 !important;
    color: #bae6fd !important;
}
[data-theme="dark"] #explanation-container strong { color: #7dd3fc !important; }
[data-theme="dark"] #explanation-container p { color: #bae6fd !important; }

/* ── Feedback messages (override inline style) ── */
[data-theme="dark"] #feedback-message { border-radius: 10px; }

/* ── Simulado / X1 result cards ── */
[data-theme="dark"] .result-card,
[data-theme="dark"] .score-card { background: #1e293b; border-color: #334155; color: #e2e8f0; }

/* ── Página de início / dashboard ── */
[data-theme="dark"] h1,[data-theme="dark"] h2,[data-theme="dark"] h3,
[data-theme="dark"] h4,[data-theme="dark"] h5,[data-theme="dark"] h6 { color: #f1f5f9; }
[data-theme="dark"] p { color: #94a3b8; }
[data-theme="dark"] label { color: #cbd5e1; }

/* ── Perfil e user cards ── */
[data-theme="dark"] .user-card,
[data-theme="dark"] .profile-card { background: #1e293b; border-color: #334155; }

/* ── Modais genéricos ── */
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.75); }
[data-theme="dark"] .modal-box,
[data-theme="dark"] .modal-content { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .modal-header { border-bottom-color: #334155; }
[data-theme="dark"] .modal-footer { border-top-color: #334155; }

/* ══════════════════════════════════════════════
   DARK MODE — tag badges
   ══════════════════════════════════════════════ */
[data-theme="dark"] .tag-clinica     { background: #0c2a3d; color: #7dd3fc; }
[data-theme="dark"] .tag-cirurgia    { background: #3b0a0a; color: #fca5a5; }
[data-theme="dark"] .tag-pediatria   { background: #0a2614; color: #86efac; }
[data-theme="dark"] .tag-ginecologia { background: #2e0a36; color: #e879f9; }
