:root {
    --primary: #3B41A6;
    --primary-light: #6970ff;
    --primary-dark: #262b75;
    --bg: #080a14;
    --surface: #111421;
    --surface-2: #171b2c;
    --surface-3: #20253a;
    --text: #f6f7fb;
    --muted: #9ca3b8;
    --border: rgba(255,255,255,.09);
    --success: #51d28a;
    --warning: #ffcf5a;
    --danger: #ff6b6b;
    --shadow: 0 20px 60px rgba(0,0,0,.35);
    --radius: 22px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(59,65,166,.32), transparent 32rem),
        radial-gradient(circle at bottom right, rgba(105,112,255,.18), transparent 28rem),
        var(--bg);
    min-height: 100vh;
}

button, input, select, textarea { font-family: inherit; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 310px;
    padding: 24px;
    background: rgba(12, 15, 27, .88);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(20px);
    z-index: 20;
    display: flex;
    flex-direction: column;
    transition: transform .28s ease;
}

.brand {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(59,65,166,.35), rgba(255,255,255,.04));
    box-shadow: var(--shadow);
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    font-weight: 800;
    letter-spacing: -1px;
}

.brand-logo img {
    width: 100%;
    height: 100%;
    border-radius: 20%;
    object-fit: cover;
    display: block;
}

.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

.sidebar-nav { margin-top: 24px; overflow-y: auto; padding-right: 4px; }
.category-list { display: grid; gap: 12px; }

.nav-item, .category-button, .sub-button {
    width: 100%;
    border: 0;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: .22s ease;
}

.nav-item, .category-button {
    padding: 14px 15px;
    border-radius: 16px;
    background: rgba(255,255,255,.04);
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.nav-item:hover, .category-button:hover, .sub-button:hover {
    transform: translateX(3px);
    background: rgba(59,65,166,.22);
    border-color: rgba(105,112,255,.32);
}

.nav-item.active, .category-button.active, .sub-button.active {
    background: linear-gradient(135deg, rgba(59,65,166,.9), rgba(59,65,166,.42));
    border-color: rgba(255,255,255,.16);
}

.category-group { display: grid; gap: 8px; }
.sub-list { display: grid; gap: 6px; padding: 0 0 0 12px; margin: 4px 0 4px 0; border-left: 1px solid var(--border); }
.sub-button {
    background: transparent;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--muted);
    border: 1px solid transparent;
}

.sidebar-footer { margin-top: auto; padding-top: 20px; display: grid; gap: 8px; }
.sidebar-footer a {
    color: var(--text);
    text-decoration: none;
    background: var(--primary);
    padding: 13px 14px;
    border-radius: 14px;
    text-align: center;
    font-weight: 700;
    transition: .22s ease;
}
.sidebar-footer a:hover { filter: brightness(1.15); transform: translateY(-2px); }
.sidebar-footer small { color: var(--muted); text-align: center; }

.content { margin-left: 310px; width: calc(100% - 310px); padding: 28px; }

.hero {
    min-height: 240px;
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 30px;
    background:
        linear-gradient(135deg, rgba(59,65,166,.36), rgba(17,20,33,.86)),
        url('data:image/svg+xml;utf8,<svg width="800" height="400" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="rgba(255,255,255,.12)"><path d="M0 80 C160 20 260 160 420 90 S690 10 800 90"/><path d="M0 210 C150 150 300 280 470 210 S660 150 800 220"/><path d="M0 330 C160 270 280 380 430 330 S650 270 800 340"/></g></svg>');
    background-size: cover;
    box-shadow: var(--shadow);
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    position: relative;
    overflow: hidden;
}

.hero:before {
    content: '';
    position: absolute;
    width: 220px;
    height: 220px;
    right: -60px;
    top: -70px;
    background: rgba(105,112,255,.26);
    filter: blur(25px);
    border-radius: 999px;
}

.hero > * { position: relative; z-index: 1; }
.eyebrow { color: #cbd0ff; text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.hero h1 { font-size: clamp(32px, 5vw, 64px); margin: 10px 0 12px; letter-spacing: -2px; line-height: .96; }
.hero p { color: #d7daf5; max-width: 720px; margin: 0; line-height: 1.65; }
.hero-card {
    min-width: 180px;
    padding: 20px;
    border-radius: 24px;
    background: rgba(8,10,20,.58);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
}
.hero-card strong { font-size: 42px; display: block; }
.hero-card span { color: var(--muted); }

.menu-toggle, .mobile-close { display: none; }

.toolbar {
    margin: 24px 0 16px;
    display: grid;
    grid-template-columns: 1fr 240px 240px;
    gap: 14px;
}

.search-box, .toolbar select {
    border: 1px solid var(--border);
    background: rgba(17,20,33,.86);
    color: var(--text);
    border-radius: 18px;
    min-height: 54px;
    box-shadow: 0 12px 35px rgba(0,0,0,.18);
}

.search-box { display: flex; align-items: center; gap: 10px; padding: 0 16px; }
.search-box input { width: 100%; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 15px; }
.search-box input::placeholder { color: var(--muted); }
.toolbar select { padding: 0 14px; outline: 0; }

.active-filter { color: var(--muted); margin-bottom: 18px; }

.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 18px; }
.rules-grid.rule-list { grid-template-columns: 1fr; }
.rule-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(23,27,44,.94), rgba(17,20,33,.94));
    padding: 22px;
    position: relative;
    overflow: hidden;
    animation: cardIn .42s ease both;
    transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}
.rule-card[style*="--rule-accent"] {
    border-color: rgba(var(--rule-accent-rgb), .32);
    box-shadow: inset 0 1px 0 rgba(var(--rule-accent-rgb), .16);
}
.rule-card:hover {
    transform: translateY(-5px);
    border-color: rgba(var(--rule-accent-rgb, 105,112,255), .55);
    box-shadow: 0 18px 50px rgba(0,0,0,.24), 0 0 0 1px rgba(var(--rule-accent-rgb, 105,112,255), .1);
}
.rule-card.fixed { border-color: rgba(255,207,90,.38); }
.rule-card.fixed:before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: linear-gradient(90deg, var(--warning), var(--rule-accent, var(--primary-light)));
}
.rule-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.rule-title-wrap { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.rule-icon {
    width: 48px;
    height: 48px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background: rgba(var(--rule-accent-rgb, 105,112,255), .18);
    color: var(--rule-accent, var(--primary-light));
    border: 1px solid rgba(var(--rule-accent-rgb, 105,112,255), .28);
    font-size: 24px;
}
.rule-card h2 { margin: 0; font-size: 20px; color: var(--rule-accent, var(--text)); letter-spacing: 0; }
.rule-kicker {
    display: block;
    margin-top: 6px;
    color: var(--rule-accent, #cbd0ff);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; font-weight: 800; padding: 6px 9px; border-radius: 999px; background: rgba(255,255,255,.08); color: var(--text); white-space: nowrap; }
.badge.order { background: rgba(105,112,255,.16); color: #cbd0ff; }
.badge.new { background: rgba(81,210,138,.16); color: var(--success); }
.badge.fixed { background: rgba(255,207,90,.16); color: var(--warning); }
.rule-meta { color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin: 13px 0 16px; font-size: 13px; }
.rule-body { color: #dde1f3; line-height: 1.68; }
.rule-body p:first-child { margin-top: 0; }
.rule-body p:last-child { margin-bottom: 0; }
.rule-body strong { color: var(--rule-accent, #cbd0ff); }
.rule-body blockquote {
    margin: 18px 0 0;
    padding: 16px 18px;
    border: 1px solid rgba(var(--rule-accent-rgb, 105,112,255), .3);
    border-radius: 14px;
    background: rgba(var(--rule-accent-rgb, 105,112,255), .12);
}
.rule-body blockquote p { margin: 0 0 10px; }
.rule-body blockquote p:last-child { margin-bottom: 0; }
.rule-body code { background: rgba(255,255,255,.08); padding: 2px 6px; border-radius: 6px; }
.rule-body ul { padding-left: 20px; }
.rule-dates { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--muted); display: grid; gap: 5px; font-size: 12px; }
.category-card { cursor: pointer; display: grid; gap: 14px; }
.category-card-description { color: #dde1f3; line-height: 1.6; margin: 0; }
.category-card-action {
    justify-self: flex-start;
    border: 1px solid rgba(105,112,255,.36);
    background: rgba(105,112,255,.14);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 800;
}
.category-card:hover .category-card-action { background: rgba(105,112,255,.24); }
.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state div { font-size: 54px; }
.empty-state h2 { color: var(--text); }

@keyframes cardIn {
    from { opacity: 0; transform: translateY(16px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 980px) {
    .sidebar { transform: translateX(-105%); }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; width: 100%; padding: 18px; }
    .menu-toggle, .mobile-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: rgba(255,255,255,.08);
        color: var(--text);
        cursor: pointer;
        padding: 11px 14px;
        font-weight: 800;
    }
    .mobile-close { margin-top: 14px; width: 100%; }
    .hero { align-items: start; flex-direction: column; min-height: auto; }
    .toolbar { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .sidebar { width: min(92vw, 330px); }
    .hero { padding: 22px; border-radius: 24px; }
    .rules-grid { grid-template-columns: 1fr; }
    .rule-head { flex-direction: column; }
    .badges { justify-content: flex-start; }
}

/* Subcategorias recolhidas: aparecem apenas ao clicar na categoria */
.category-info {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.category-arrow {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: rgba(255,255,255,.06);
    font-size: 14px;
    line-height: 1;
    transition: transform .22s ease, background .22s ease;
}

.category-group .sub-list {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    transform: translateY(-4px);
    transition: max-height .28s ease, opacity .22s ease, transform .22s ease, padding .22s ease, margin .22s ease;
}

.category-group.expanded .sub-list {
    max-height: 420px;
    opacity: 1;
    padding-top: 0;
    padding-bottom: 0;
    margin: 4px 0 4px 0;
    transform: translateY(0);
}

.category-group.expanded .category-arrow {
    transform: rotate(180deg);
    background: rgba(105,112,255,.22);
}

.sub-empty {
    display: block;
    color: var(--muted);
    font-size: 12px;
    padding: 8px 12px;
}
