@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================================
   DESIGN SYSTEM — TOKEN LAYER
   Todos os valores de cor são definidos aqui como variáveis CSS.
   Light mode só precisa sobrescrever os tokens, não componentes.
   ============================================================ */
:root {
    --font-primary: 'Inter', system-ui, -apple-system, sans-serif;

    /* === Paleta Dark (padrão) === */
    --bg-base:          #0f172a;
    --bg-surface:       #1e293b;
    --bg-surface-hover: #334155;
    --bg-elevated:      #263249;
    --bg-sidebar:       #0b0f19;
    --bg-topbar:        rgba(15, 23, 42, 0.85);
    --border-color:     rgba(255, 255, 255, 0.1);

    /* Inputs */
    --input-bg:         #0f172a;
    --input-bg-focus:   #1a2540;
    --input-border:     rgba(255, 255, 255, 0.18);
    --input-text:       #f8fafc;
    --input-placeholder:#64748b;

    /* Texto */
    --text-primary:     #f8fafc;
    --text-secondary:   #94a3b8;
    --text-muted:       #64748b;
    --text-on-accent:   #ffffff;

    /* Cores de acento */
    --primary:          #6366f1;
    --primary-glow:     rgba(99, 102, 241, 0.35);
    --secondary:        #a855f7;
    --secondary-glow:   rgba(168, 85, 247, 0.35);
    --accent:           #06b6d4;

    /* Estados */
    --success:          #10b981;
    --success-bg:       rgba(16, 185, 129, 0.12);
    --success-text:     #6ee7b7;
    --warning:          #f59e0b;
    --warning-bg:       rgba(245, 158, 11, 0.12);
    --warning-text:     #fcd34d;
    --error:            #ef4444;
    --error-bg:         rgba(239, 68, 68, 0.12);
    --error-text:       #fca5a5;

    /* Badges */
    --badge-admin-bg:   rgba(168, 85, 247, 0.18);
    --badge-admin-text: #d8b4fe;
    --badge-user-bg:    rgba(99, 102, 241, 0.18);
    --badge-user-text:  #c7d2fe;

    /* Histórico */
    --history-old-text: #fca5a5;
    --history-new-text: #86efac;

    /* Superfícies alternadas */
    --row-hover-bg:     rgba(255, 255, 255, 0.03);
    --th-bg:            rgba(255, 255, 255, 0.04);

    /* Raios e sombras */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --transition-fast:   0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.15), 0 1px 2px -1px rgb(0 0 0 / 0.15);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.2),  0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.25), 0 8px 10px -6px rgb(0 0 0 / 0.2);
}

/* ============================================================
   LIGHT MODE — Sobrescreve apenas os tokens
   ============================================================ */
body.light-mode {
    --bg-base:          #f1f5f9;
    --bg-surface:       #ffffff;
    --bg-surface-hover: #f1f5f9;
    --bg-elevated:      #e8edf5;
    --bg-sidebar:       #1e293b;
    --bg-topbar:        rgba(255, 255, 255, 0.92);
    --border-color:     #cbd5e1;

    --input-bg:         #ffffff;
    --input-bg-focus:   #f8fafc;
    --input-border:     #94a3b8;
    --input-text:       #0f172a;
    --input-placeholder:#94a3b8;

    --text-primary:     #0f172a;
    --text-secondary:   #475569;
    --text-muted:       #94a3b8;
    --text-on-accent:   #ffffff;

    --primary:          #4f46e5;
    --primary-glow:     rgba(79, 70, 229, 0.2);
    --secondary:        #9333ea;
    --secondary-glow:   rgba(147, 51, 234, 0.2);
    --accent:           #0891b2;

    --success:          #059669;
    --success-bg:       rgba(5, 150, 105, 0.1);
    --success-text:     #065f46;
    --warning:          #d97706;
    --warning-bg:       rgba(217, 119, 6, 0.1);
    --warning-text:     #92400e;
    --error:            #dc2626;
    --error-bg:         rgba(220, 38, 38, 0.1);
    --error-text:       #991b1b;

    --badge-admin-bg:   rgba(147, 51, 234, 0.12);
    --badge-admin-text: #6b21a8;
    --badge-user-bg:    rgba(79, 70, 229, 0.12);
    --badge-user-text:  #3730a3;

    --history-old-text: #dc2626;
    --history-new-text: #059669;

    --row-hover-bg:     #f8fafc;
    --th-bg:            #f1f5f9;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.06);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.07), 0 4px 6px -4px rgb(0 0 0 / 0.07);
}

/* Sidebar mantém tema escuro no light mode */
body.light-mode .sidebar {
    --text-primary:     #f8fafc;
    --text-secondary:   #94a3b8;
    --text-muted:       #64748b;
    --border-color:     rgba(255,255,255,0.1);
    --bg-surface-hover: #334155;
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-primary);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
                radial-gradient(circle at 90% 80%, rgba(168, 85, 247, 0.15) 0%, transparent 40%);
}

.login-card {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    padding: 40px;
    width: 100%;
    max-width: 440px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.6s ease;
}

.login-logo { text-align: center; margin-bottom: 30px; }

.login-logo h1 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #818cf8, #c084fc, #22d3ee);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 5px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input {
    width: 100%;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: var(--font-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
    appearance: none;
    -webkit-appearance: none;
}

.form-input::placeholder {
    color: var(--input-placeholder);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background-color: var(--input-bg-focus);
}

select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--text-on-accent);
    border: none;
    padding: 14px;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-family: var(--font-primary);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
    filter: brightness(1.08);
}

.btn:active { transform: translateY(0); }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: none;
}

.btn-secondary:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
    transform: none;
    box-shadow: none;
    filter: none;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 20px;
    border-left: 4px solid transparent;
    animation: shake 0.4s ease;
}

.alert-danger  { background-color: var(--error-bg);   color: var(--error-text);   border-left-color: var(--error);   }
.alert-success { background-color: var(--success-bg); color: var(--success-text); border-left-color: var(--success); }
.alert-warning { background-color: var(--warning-bg); color: var(--warning-text); border-left-color: var(--warning); }

.card-footer {
    margin-top: 25px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.card-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--transition-fast);
}

.card-footer a:hover {
    color: var(--secondary);
    text-decoration: underline;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition-normal);
}

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

.sidebar-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.04em;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 12px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.sidebar-item a:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.sidebar-item.active a {
    background: linear-gradient(135deg, var(--primary-glow), var(--secondary-glow));
    border-left: 3px solid var(--primary);
    color: var(--text-primary);
    font-weight: 600;
}

.sidebar-user {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: var(--bg-surface-hover);
    padding: 2px 8px;
    border-radius: 99px;
    align-self: flex-start;
    text-transform: uppercase;
    font-weight: 700;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.logout-btn:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--error);
}

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

.top-bar {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    background-color: var(--bg-topbar);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 99;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--transition-fast);
}

.theme-toggle:hover { background-color: var(--bg-surface-hover); }

.content-body {
    padding: 30px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
   METRIC CARDS
   ============================================================ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.metric-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.3);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0.8;
}

.metric-card.accent::before { background: linear-gradient(90deg, var(--secondary), var(--accent)); }

.metric-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 8px;
}

.metric-icon {
    font-size: 2.2rem;
    color: var(--primary);
    opacity: 0.8;
}

.metric-card.accent .metric-icon { color: var(--accent); }

/* ============================================================
   GENERIC CARDS
   ============================================================ */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 30px;
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--th-bg);
}

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

.card-body { padding: 24px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-responsive { width: 100%; overflow-x: auto; }

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

.table th {
    padding: 14px 20px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    background-color: var(--th-bg);
}

.table td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

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

/* ============================================================
   LAYOUT HELPERS
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 25px;
}

.search-box {
    display: flex;
    align-items: center;
    position: relative;
    max-width: 360px;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border-radius: var(--radius-md);
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    font-size: 0.9rem;
    font-family: var(--font-primary);
    transition: all var(--transition-fast);
}

.search-input::placeholder { color: var(--input-placeholder); }

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.search-icon { position: absolute; left: 14px; color: var(--text-muted); }
.action-buttons { display: flex; gap: 10px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-backdrop.show { display: flex; }

.modal {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 520px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: zoomIn 0.3s ease;
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color var(--transition-fast);
}

.modal-close:hover { color: var(--error); }
.modal-body { padding: 24px; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: inline-block;
}

.badge-admin { background-color: var(--badge-admin-bg); color: var(--badge-admin-text); }
.badge-user  { background-color: var(--badge-user-bg);  color: var(--badge-user-text);  }

/* ============================================================
   HISTÓRICO
   ============================================================ */
.history-list { display: flex; flex-direction: column; gap: 12px; }

.history-item {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.history-item-details { display: flex; flex-direction: column; gap: 4px; }
.history-change { font-weight: 500; color: var(--text-primary); }
.history-val-old { color: var(--history-old-text); text-decoration: line-through; }
.history-val-new { color: var(--history-new-text); }
.history-meta { font-size: 0.8rem; color: var(--text-muted); }

/* ============================================================
   TABS
   ============================================================ */
.tabs { display: flex; border-bottom: 1px solid var(--border-color); margin-bottom: 25px; gap: 20px; }

.tab-link {
    padding: 12px 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.tab-link:hover { color: var(--text-primary); }
.tab-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0);    }
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1);    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0);    }
    25%       { transform: translateX(-4px); }
    75%       { transform: translateX(4px);  }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .app-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-menu {
        flex-direction: row;
        overflow-x: auto;
        padding: 10px 15px;
    }

    .sidebar-item a { padding: 8px 12px; white-space: nowrap; }
    .sidebar-user { display: none; }
    .top-bar { padding: 0 20px; }
    .content-body { padding: 20px; }
}

/* ============================================================
   VIEWER DE NORMAS — Sobrescreve cores hardcoded do HTML do MCTIC
   ============================================================ */
.norm-html-viewer {
    color: var(--text-primary) !important;
    background-color: var(--bg-surface) !important;
}

.norm-html-viewer * {
    color: inherit !important;
    background-color: transparent !important;
    border-color: var(--border-color) !important;
    font-family: var(--font-primary) !important;
}

.norm-html-viewer a { color: var(--accent) !important; text-decoration: underline; }
.norm-html-viewer a:hover { color: var(--primary) !important; }

.norm-html-viewer table { border-collapse: collapse; width: 100%; margin: 16px 0; }

.norm-html-viewer table td,
.norm-html-viewer table th {
    border: 1px solid var(--border-color) !important;
    padding: 8px 12px;
    color: var(--text-primary) !important;
}

.norm-html-viewer table th { background: var(--th-bg) !important; font-weight: 700; }
.norm-html-viewer img { max-width: 100%; border-radius: var(--radius-sm); }

/* Correção de Contraste para options de Select */
select option, select optgroup {
    background-color: var(--bg-surface) !important;
    color: var(--text-primary) !important;
}
select:focus option, select:focus optgroup {
    background-color: var(--bg-surface-hover) !important;
    color: var(--text-primary) !important;
}
