:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --ink: #1a1d21;
    --muted: #656d76;
    --line: #dfe2e8;
    --primary: #0969da;
    --primary-dark: #0550ae;
    --danger: #cf222e;
    --ok: #1a7f37;
    --warning: #9a6700;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(27,31,36,.05);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: #24292f;
    color: #fff;
    padding: 20px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 24px;
    padding: 0 8px;
}

.nav-block { margin-bottom: 20px; }
.nav-block strong { display: block; color: #8b949e; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; padding: 0 8px; }
.nav-block ul { list-style: none; margin: 0; padding: 0; }
.nav-block li { margin: 2px 0; }
.nav-block a { display: block; color: #c9d1d9; padding: 8px 10px; border-radius: 6px; font-size: 14px; font-weight: 500; }
.nav-block a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-block a.active { background: rgba(255,255,255,.12); color: #fff; }

.main { flex: 1; padding: 24px 28px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 600; color: var(--ink); }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.user-pill { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }

/* Page header - unificado */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.page-header-text h2, .page-header-text p { margin: 0; }
.page-header-text p { color: var(--muted); margin-top: 8px; font-size: 14px; }
.page-header-text h2 { font-size: 24px; line-height: 1.2; font-weight: 700; color: var(--ink); }

/* Grid layouts */
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* Cards - unificado */
.section-card {
    display: block;
    background: var(--surface) !important;
    border: 1px solid var(--line) !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow) !important;
    padding: 24px !important;
    margin-bottom: 20px !important;
}
.section-card > *:first-child { margin-top: 0; }
.section-card > *:last-child { margin-bottom: 0; }
.section-card.flush { padding: 0 !important; overflow: hidden; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; padding: 28px; }
.card h1, .card h2, .card h3, .card p { margin-top: 0; }
.card h2 { margin-bottom: 18px; font-size: 22px; line-height: 1.25; }
.card p:last-child { margin-bottom: 0; }
.card-content { display: grid; gap: 16px; }
.dashboard-grid { align-items: stretch; }
.metric-card { min-height: 150px; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; }
.metric-card p { font-size: 15px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #f6f8fa; }
.card-header h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); }
.card-body { padding: 16px; }
.card-body h2, .card-body h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--ink); }
.card-body h2:first-child, .card-body h3:first-child { margin-top: 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); }

/* Form elements - unificado */
.form-grid { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink); }
label span { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    font: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--ink);
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,105,218,.12); }
textarea { min-height: 72px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='%23656d76' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
input[type="search"] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='%23656d76' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m21 21-5.197-5.197m0 0A8 8 0 1 0 5.196 5.196a8 8 0 0 0 10.607 10.607Z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 10px center; padding-left: 34px; }

/* Buttons - unificado, sin small */
.btn, button {
    border: 0;
    border-radius: 6px;
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}
.btn:hover, button:hover { background: var(--primary-dark); color: #fff; }
.btn.secondary, button.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover, button.secondary:hover { background: var(--bg); border-color: #b0b7c3; color: var(--ink); }
.btn.danger, button.danger { background: var(--danger); color: #fff; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables - unificado */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: #f6f8fa; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f6f8fa; }
tbody tr.selected { background: #eaf2ff; }
tbody tr.selected td:first-child { border-left: 3px solid var(--primary); }

/* Badges - unificado */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; background: #ddf4ff; color: #0550ae; font-size: 11px; font-weight: 600; white-space: nowrap; }
.card .badge { margin: 4px 4px 0 0; }
.badge.deny { background: #ffebe9; color: var(--danger); }
.badge.allow { background: #dafbe1; color: var(--ok); }
.badge.neutral { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.warning { background: #fff8c5; color: var(--warning); }

/* Utility */
.muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.empty-row { padding: 20px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: #dafbe1; color: var(--ok); font-size: 13px; font-weight: 500; border: 1px solid #1a7f37; }
.flash.error { background: #ffebe9; color: var(--danger); border-color: var(--danger); }
.flash.warning { background: #fff8c5; color: var(--warning); border-color: var(--warning); }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* Filters - unificado */
.filters-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.filters-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters-row .filter-field { flex: 1 1 180px; display: grid; gap: 4px; }
.filters-row .filter-field label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filters-row .filter-field input, .filters-row .filter-field select { padding: 6px 10px; font-size: 13px; }
.filters-row .filter-actions { display: flex; gap: 6px; align-items: flex-end; padding-bottom: 0; }

/* List panel - unificado */
.list-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.list-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.list-card-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.list-card-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 22px 0; }
.list-card-toolbar strong { font-size: 13px; font-weight: 600; color: var(--ink); }
.list-card-toolbar span { font-size: 12px; color: var(--muted); }
.list-card-body { overflow-x: auto; padding: 18px 22px; }
.list-card-body table { border: 1px solid var(--line); border-collapse: separate; border-spacing: 0; border-radius: 8px; overflow: hidden; background: var(--surface); }
.list-card-body th, .list-card-body td { padding: 12px 14px; }
.list-card-footer { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-top: 1px solid var(--line); background: #f6f8fa; }
.list-card-footer .muted { font-size: 12px; }

/* Editor panel - unificado */
.editor-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.editor-card-header { padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.editor-card-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.editor-card-body { padding: 22px; }
.editor-card-footer { padding: 18px 22px; border-top: 1px solid var(--line); background: #f6f8fa; display: flex; justify-content: flex-end; gap: 8px; }

/* Toggle - unificado */
.toggle-row { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--line); border-radius: 20px; cursor: pointer; transition: background .2s; border: 1px solid transparent; }
.toggle-slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + .toggle-slider { background: var(--ok); border-color: var(--ok); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle input:focus + .toggle-slider { box-shadow: 0 0 0 3px rgba(9,105,218,.12); }
.toggle-row span:last-child { font-size: 13px; font-weight: 600; color: var(--ink); }

/* Role/permission assignment grid */
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.role-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--bg); cursor: pointer; min-height: 52px; }
.role-item input { width: 15px; height: 15px; flex-shrink: 0; }
.role-item span { font-size: 13px; font-weight: 500; color: var(--ink); }

/* User avatar */
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.user-avatar.sm { width: 24px; height: 24px; font-size: 10px; }

/* Admin section layout */
.admin-section { display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, .55fr); gap: 18px; align-items: start; }
.reports-admin-section { display: grid; gap: 22px; }
.reports-page .report-card {
    display: block !important;
    background: #fff !important;
    border: 1px solid var(--line) !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow) !important;
    padding: 28px !important;
    margin: 0 !important;
    overflow: hidden !important;
}
.reports-top-grid { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(520px, 1.1fr); gap: 22px; align-items: stretch; }
.reports-top-grid .report-card { min-height: 720px; display: flex !important; flex-direction: column; }
.reports-top-grid .report-card .report-card-body { flex: 1; }
.reports-flow { display: grid; gap: 22px; }
.reports-flow .report-card { width: 100%; }
.report-card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.report-card-header h3 { margin: 0; font-size: 22px; font-weight: 700; color: var(--ink); }
.report-card-body { min-width: 0; }
.report-list-scroll { flex: 1; overflow: auto; min-height: 0; }
.reports-page .report-table { width: 100%; border: 1px solid var(--line); border-collapse: separate; border-spacing: 0; border-radius: 10px; overflow: hidden; background: #fff; }
.reports-page .report-table th, .reports-page .report-table td { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.reports-page .report-table tr:last-child td { border-bottom: none; }
.reports-page .report-table th { background: #f6f8fa; }
.reports-page .report-form { display: grid; gap: 18px; }
.reports-page .report-form-actions { margin-top: auto; padding-top: 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.section-stack { display: grid; gap: 18px; }
.section-stack > .list-card { margin-bottom: 0; }
.spaced-card { margin-top: 16px; }
.spaced-section { margin-top: 16px; }
.embedded-filters { margin: 18px 22px 0; }
.inline-user { display: flex; align-items: center; gap: 10px; }
.inline-user.compact { gap: 8px; }
.item-title { display: block; font-size: 13px; font-weight: 600; color: var(--ink); }
.item-title.sm { font-size: 12px; }
.notice-card { padding: 10px 16px; background: #fff8c5; border-bottom: 1px solid var(--line); }
.notice-card p { margin: 0; color: var(--warning); }
.split-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Permission matrix */
.permission-matrix { overflow-x: auto; }
.matrix-table { width: 100%; min-width: 720px; border-collapse: separate; border-spacing: 0; font-size: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.matrix-table th, .matrix-table td { padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.matrix-table th:last-child, .matrix-table td:last-child { border-right: none; }
.matrix-table tbody tr:last-child td { border-bottom: none; }
.matrix-table th { background: #f6f8fa; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 10px; letter-spacing: .04em; }
.matrix-table td:first-child { text-align: left; font-size: 13px; color: var(--ink); }
.matrix-table input[type="checkbox"] { width: 15px; height: 15px; border-radius: 3px; }

/* Empty state */
.empty-state { border: 1px dashed var(--line); border-radius: 8px; padding: 24px; text-align: center; background: var(--bg); }
.empty-state h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; color: var(--ink); }
.empty-state p { margin: 0; font-size: 12px; color: var(--muted); }

/* Responsive */
@media (max-width: 960px) {
    .app-shell { display: block; }
    .sidebar { width: 100%; height: auto; position: relative; }
    .main { padding: 16px; }
    .grid.two, .grid.three { grid-template-columns: 1fr; }
    .admin-section, .reports-top-grid { grid-template-columns: 1fr; }
    .filters-row .filter-field { flex: 1 1 160px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .page-header { flex-direction: column; }
}
@media (max-width: 640px) {
    .grid.three { grid-template-columns: 1fr; }
    .role-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
