:root {
    color-scheme: dark;
    --bg: #0d0f14;
    --bg-2: #12151d;
    --surface: #171b24;
    --surface-2: #1e2330;
    --border: #2a3040;
    --text: #e9ebf2;
    --muted: #98a0b3;
    --accent: #f5b301;
    --accent-2: #ffd75e;
    --accent-text: #1a1400;
    --green: #3ecf72;
    --red: #ff6b6b;
    --danger-bg: #391d22;
    --danger-border: #6e2a34;
    --danger-text: #ff9aa2;
    --success-bg: #16321f;
    --success-border: #2c6a41;
    --success-text: #7fe3a5;
    --radius: 10px;
    --sidebar-w: 232px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
a { color: var(--accent-2); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.gold { color: var(--accent); }
.green { color: var(--green); }
.red { color: var(--red); }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .85em; }

.brand-star { color: var(--accent); }

/* ---- Botoes ---- */
.btn {
    display: inline-block;
    border: 0;
    border-radius: var(--radius);
    padding: .6rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    color: var(--accent-text);
    box-shadow: 0 2px 10px rgba(245, 179, 1, .25);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-lg { width: 100%; padding: .8rem 1rem; font-size: 1.02rem; }
.btn-sm { padding: .3rem .7rem; font-size: .84rem; font-weight: 500; }
.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

/* ---- Badges / alerts / callouts ---- */
.badge {
    display: inline-block;
    border-radius: 99px;
    padding: .08rem .55rem;
    font-size: .74rem;
    font-weight: 600;
    vertical-align: middle;
}
.badge-gold { background: rgba(245, 179, 1, .15); color: var(--accent-2); border: 1px solid rgba(245, 179, 1, .4); }
.badge-green { background: rgba(62, 207, 114, .12); color: var(--green); border: 1px solid rgba(62, 207, 114, .35); }
.badge-red { background: rgba(255, 107, 107, .12); color: var(--red); border: 1px solid rgba(255, 107, 107, .35); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.alert {
    border-radius: var(--radius);
    padding: .7rem 1rem;
    margin-bottom: 1rem;
    font-size: .92rem;
}
.alert-error { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text); }
.alert-success { background: var(--success-bg); border: 1px solid var(--success-border); color: var(--success-text); }

.callout {
    background: rgba(245, 179, 1, .07);
    border: 1px solid rgba(245, 179, 1, .3);
    border-radius: var(--radius);
    padding: .7rem 1rem;
    margin: 0 0 1.2rem;
    font-size: .92rem;
}

/* ================= LOGIN ================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background:
        radial-gradient(ellipse 60% 45% at 50% -5%, rgba(245, 179, 1, .16), transparent 70%),
        radial-gradient(ellipse 40% 35% at 85% 100%, rgba(245, 179, 1, .06), transparent 70%),
        linear-gradient(180deg, #0e1016, #0a0c10);
    position: relative;
    overflow: hidden;
}

.login-bg { position: absolute; inset: 0; pointer-events: none; }
.login-bg .star {
    position: absolute;
    color: var(--accent);
    opacity: .18;
    animation: twinkle 4s ease-in-out infinite;
}
.login-bg .s1 { top: 12%; left: 14%; font-size: 14px; animation-delay: 0s; }
.login-bg .s2 { top: 26%; left: 78%; font-size: 20px; animation-delay: .7s; }
.login-bg .s3 { top: 64%; left: 8%;  font-size: 12px; animation-delay: 1.3s; }
.login-bg .s4 { top: 78%; left: 68%; font-size: 16px; animation-delay: 2s; }
.login-bg .s5 { top: 44%; left: 90%; font-size: 11px; animation-delay: 2.6s; }
.login-bg .s6 { top: 8%;  left: 52%; font-size: 12px; animation-delay: 3.1s; }
.login-bg .s7 { top: 88%; left: 30%; font-size: 18px; animation-delay: 1.8s; }
@keyframes twinkle {
    0%, 100% { opacity: .08; transform: scale(.9); }
    50% { opacity: .4; transform: scale(1.05); }
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: rgba(23, 27, 36, .88);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.4rem 2.2rem 2.2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5), 0 0 0 1px rgba(245, 179, 1, .05);
    backdrop-filter: blur(8px);
}

.login-logo { text-align: center; margin-bottom: 1.6rem; }
.logo-ring {
    width: 72px; height: 72px;
    margin: 0 auto .9rem;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 35% 30%, rgba(245, 179, 1, .22), rgba(245, 179, 1, .05));
    border: 1px solid rgba(245, 179, 1, .45);
    box-shadow: 0 0 24px rgba(245, 179, 1, .18), inset 0 0 14px rgba(245, 179, 1, .10);
}
.brand-star.big { font-size: 2.1rem; text-shadow: 0 0 14px rgba(245, 179, 1, .6); }
.login-logo h1 { font-size: 1.45rem; letter-spacing: .02em; margin: 0; }
.login-sub { margin: .15rem 0 0; color: var(--muted); font-size: .88rem; }

.login-card .field { margin-bottom: 1rem; }
.login-card label,
.field label {
    display: block;
    margin-bottom: .3rem;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 500;
}
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], select {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .62rem .8rem;
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 179, 1, .15);
}
input::placeholder { color: #5b6373; }
.login-card .btn-primary { margin-top: .6rem; }

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
    font-size: 1.05rem;
    padding: 1.1rem 1.2rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-star { font-size: 1.3em; text-shadow: 0 0 10px rgba(245, 179, 1, .5); }

.sidebar-nav { flex: 1; padding: .8rem .6rem; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .8rem;
    margin-bottom: .15rem;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    font-size: .93rem;
    transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
    background: linear-gradient(90deg, rgba(245, 179, 1, .14), rgba(245, 179, 1, .04));
    color: var(--accent-2);
    border-left: 2px solid var(--accent);
    padding-left: calc(.8rem - 2px);
}

.sidebar-user {
    border-top: 1px solid var(--border);
    padding: .9rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
}
.user-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.user-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user form { margin: 0; }

.main {
    flex: 1;
    min-width: 0;
    padding: 1.6rem 2rem 3rem;
}
.page-head { margin-bottom: 1.2rem; }
.page-head h1 { font-size: 1.45rem; }
.page-actions { margin-bottom: 1rem; display: flex; gap: .6rem; }

/* ---- Filter bar (dashboard) ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .8rem 1rem;
    margin-bottom: 1.3rem;
}
.filter-presets { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
    display: inline-block;
    padding: .3rem .8rem;
    border-radius: 99px;
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    font-size: .85rem;
    font-weight: 500;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.active { background: rgba(245, 179, 1, .13); color: var(--accent-2); border-color: rgba(245, 179, 1, .5); }
.filter-fields { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.filter-fields input[type="date"] { width: auto; }
.filter-fields select { width: auto; min-width: 180px; }

/* ---- Stat cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: .9rem;
    margin-bottom: 1.3rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.stat-card.highlight {
    background: linear-gradient(160deg, rgba(245, 179, 1, .10), var(--surface) 55%);
    border-color: rgba(245, 179, 1, .35);
}
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-foot { font-size: .78rem; }

/* ---- Panels / tables ---- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.3rem;
}
.panel h2 { font-size: 1.05rem; margin-bottom: .8rem; }
.panel-form { max-width: 760px; }
.panel-form.panel-wide { max-width: none; }
.section-title { font-size: 1rem; margin: 1.4rem 0 .7rem; }
.section-title:first-child { margin-top: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.center, td.center { text-align: center; }
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; align-items: center; }
.row-actions form { margin: 0; }

/* ---- Matriz de permissoes ---- */
.matrix .matrix-modulo td {
    background: var(--surface-2);
    color: var(--accent-2);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.matrix input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.matrix td .mono { display: block; }
.select-sm { padding: .3rem .5rem; font-size: .84rem; width: auto; }

/* ---- Forms ---- */
.field { margin-bottom: 1rem; min-width: 0; }
.field .hint, .hint { color: var(--muted); font-size: .8rem; margin: .3rem 0 0; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row .field { flex: 0 0 auto; }
.field-row .field.grow { flex: 1 1 200px; }
.field-row.bottom { align-items: flex-end; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
    margin-top: 1.2rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--border);
}
.checkbox-grid { display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; }
.checkbox-item { display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.checkbox-item input { accent-color: var(--accent); width: 16px; height: 16px; }
.override-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* ---- Empty / erro ---- */
.empty-state { text-align: center; padding: 4.5rem 1rem; }
.empty-icon { font-size: 2.6rem; margin-bottom: .8rem; }
.empty-state .btn { margin-top: 1rem; }

/* ---- Responsivo ---- */
@media (max-width: 860px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
    .sidebar-brand { border-bottom: 0; }
    .sidebar-nav { display: flex; padding: .4rem; overflow-x: auto; }
    .nav-item span { display: none; }
    .sidebar-user { border-top: 0; margin-left: auto; }
    .main { padding: 1.1rem 1rem 2.5rem; }
    .filter-bar { flex-direction: column; align-items: stretch; }
}

.user-head { margin-bottom: 1.2rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.user-head h2 { margin-bottom: .2rem; }
.user-head p { margin: 0; font-size: .88rem; }
