:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #e4e8ef;
    --primary: #2855d9;
    --primary-dark: #1f43ad;
    --success: #137a55;
    --danger: #b42318;
    --warning: #9a6700;
    --sidebar: #111827;
    --radius: 12px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
code { font-family: "Cascadia Code", Consolas, monospace; font-size: .9em; overflow-wrap: anywhere; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.75rem, 3vw, 2.25rem); line-height: 1.15; letter-spacing: -.025em; }
h2 { margin-bottom: 4px; font-size: 1.05rem; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; display: flex; width: 238px; flex-direction: column; padding: 24px 16px; color: #e5e7eb; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand span:last-child { display: flex; flex-direction: column; }
.brand small { color: #98a2b3; }
.brand-mark { display: inline-grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 10px; color: #fff; background: var(--primary); font-weight: 800; }
.brand-mark-large { width: 50px; height: 50px; flex-basis: 50px; }
.main-nav { display: grid; gap: 5px; }
.main-nav a { padding: 10px 12px; border-radius: 8px; color: #b8c0cf; font-weight: 600; }
.main-nav a:hover, .main-nav a.active { color: #fff; background: #253047; text-decoration: none; }
.sidebar-footer { display: grid; gap: 14px; margin-top: auto; padding-top: 20px; border-top: 1px solid #293348; }
.signed-in-user { display: flex; min-width: 0; flex-direction: column; }
.signed-in-user span, .signed-in-user small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-in-user small { color: #98a2b3; }
.main-content { min-height: 100vh; margin-left: 238px; padding: 38px clamp(24px, 4vw, 56px) 64px; }
.mobile-header { display: none; }

.page-header { display: flex; justify-content: space-between; gap: 24px; margin: 0 auto 26px; max-width: 1440px; }
.page-header p { margin-bottom: 0; color: var(--muted); }
.page-header-actions { align-items: end; }
.eyebrow { margin-bottom: 7px !important; color: var(--primary) !important; font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 13px; font-weight: 650; }
.title-row, .button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.panel { max-width: 1440px; margin: 0 auto 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: 0 1px 2px rgb(16 24 40 / 4%); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.panel-header p { margin-bottom: 0; color: var(--muted); }
.form-panel { padding: 24px; }
.compact-panel { padding-bottom: 20px; }

.metric-grid { display: grid; max-width: 1440px; margin: 0 auto 22px; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card { display: flex; flex-direction: column; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.metric-card span { color: var(--muted); font-weight: 650; }
.metric-card strong { margin-top: 12px; font-size: 2rem; line-height: 1; }

.button { display: inline-flex; min-height: 39px; align-items: center; justify-content: center; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; font-weight: 700; white-space: nowrap; }
.button:hover { text-decoration: none; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { border-color: #cfd6e2; color: #344054; background: #fff; }
.button-secondary:hover, .button-ghost:hover { border-color: #aeb8c8; background: #f8fafc; }
.button-ghost { border-color: transparent; color: #475467; background: transparent; }
.sidebar .button-ghost { border-color: #3a465e; color: #e5e7eb; }
.button-block { width: 100%; }
.link-danger { padding: 0; border: 0; color: var(--danger); background: transparent; font-weight: 700; }

.alert { max-width: 1440px; margin: 0 auto 18px; padding: 12px 15px; border: 1px solid; border-radius: 9px; }
.alert ul { margin: 7px 0 0; padding-left: 20px; }
.alert-success { border-color: #a9dfca; color: #075e41; background: #ecfdf5; }
.alert-danger { border-color: #f1b5ae; color: #8d1a12; background: #fff1f0; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }
.field > span { color: #344054; font-weight: 700; }
.field em { color: var(--muted); font-size: .85em; font-style: normal; font-weight: 500; }
.field small { color: var(--muted); }
.field-span-2 { grid-column: span 2; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="search"], textarea, select {
    width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #cfd6e2; border-radius: 7px; color: var(--ink); background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); outline: 3px solid rgb(40 85 217 / 13%); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); }
.check-row, .switch-row { display: flex; align-items: center; gap: 9px; min-height: 40px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; max-width: 1440px; margin: 24px auto 0; }
.sticky-actions { position: sticky; bottom: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgb(255 255 255 / 95%); box-shadow: 0 8px 25px rgb(16 24 40 / 12%); }
.filter-bar { display: flex; align-items: end; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.filter-grow { flex: 1; }
.filter-select { width: 180px; }
.resource-bulk-actions { display: flex; min-height: 64px; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.resource-bulk-actions > span { color: var(--muted); font-weight: 650; }
.table-check { width: 46px; padding-right: 4px; text-align: center; }
.inline-create-form { display: grid; align-items: end; padding: 18px 22px; grid-template-columns: 1fr 1fr auto; gap: 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.audit-filters { display: grid; padding: 18px 20px; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 12px; border-bottom: 1px solid var(--line); }
.filter-actions { display: flex; align-items: end; gap: 8px; grid-column: 1 / -1; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; color: #667085; background: #f9fafb; font-size: .75rem; letter-spacing: .025em; text-align: left; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fbfcfe; }
.table-title { display: block; color: var(--ink); font-weight: 750; }
.table-subtitle { display: block; margin-top: 3px; color: var(--muted); }
.table-actions { text-align: right; }
.table-actions form { display: inline; }
.table-input { min-width: 130px !important; }
.row-muted { opacity: .56; }
.nowrap { white-space: nowrap; }
.empty-state { padding: 28px !important; color: var(--muted); text-align: center; }

.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; font-size: .74rem; font-weight: 800; white-space: nowrap; }
.badge-success { color: #086044; background: #dff7ed; }
.badge-danger { color: #9b2118; background: #fee4e2; }
.badge-muted { color: #475467; background: #eaecf0; }
.badge-warning { color: #825500; background: #fef0c7; }
.badge-info { margin-left: 5px; color: #1849a9; background: #dbe8ff; }

.detail-grid { display: grid; max-width: 1440px; margin: 0 auto; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.detail-grid > .panel { width: 100%; }
.token-reveal { display: grid; max-width: 1440px; margin: 0 auto 20px; padding: 18px 20px; border: 1px solid #7bd5b4; border-radius: var(--radius); background: #ecfdf5; gap: 12px; }
.token-reveal h2, .token-reveal p { margin-bottom: 0; }
.token-reveal code { display: block; padding: 12px; border-radius: 7px; color: #fff; background: #133f34; word-break: break-all; user-select: all; }
.key-values { margin: 0; padding: 14px 22px; }
.key-values div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.key-values dt { color: var(--muted); }
.key-values dd { margin: 0; font-weight: 700; }
.permission-summary { margin: 0 20px 18px; padding: 0; list-style: none; }
.permission-summary li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }

.permission-bulk-actions { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 18px 20px; }
.permission-search { display: flex; width: min(100%, 390px); flex: 0 1 390px; flex-direction: column; gap: 6px; }
.permission-search > span { color: #344054; font-weight: 700; }
.permission-bulk-controls { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.permission-select-all { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.permission-select-all > span { display: flex; flex-direction: column; }
.permission-select-all small { color: var(--muted); font-weight: 500; }
.permission-search-empty[hidden], .permission-card[hidden] { display: none; }
.permission-grid { display: grid; max-width: 1440px; margin: 0 auto; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.permission-card { width: 100%; margin: 0; overflow: hidden; }
.permission-resource { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); background: #f9fafb; }
.permission-resource-main { display: flex; min-width: 0; flex: 1; align-items: center; gap: 10px; cursor: pointer; }
.permission-resource-main > span { display: flex; min-width: 0; flex: 1; justify-content: space-between; gap: 10px; }
.permission-columns-all { display: flex; align-items: center; gap: 7px; color: var(--primary); cursor: pointer; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.column-checks { display: grid; max-height: 330px; padding: 10px 18px; overflow-y: auto; }
.column-checks label { display: grid; align-items: center; padding: 7px 0; grid-template-columns: auto minmax(110px, 1fr) minmax(100px, auto) auto; gap: 8px; border-bottom: 1px solid #f0f2f5; }

.pagination-wrap { padding: 15px 20px; border-top: 1px solid var(--line); }
.pagination-wrap nav > div:first-child { display: none; }
.pagination-wrap nav > div:last-child { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.pagination-wrap nav p { margin: 0; color: var(--muted); }
.pagination-wrap nav span[aria-current="page"] span, .pagination-wrap nav a { display: inline-flex; min-width: 34px; height: 34px; align-items: center; justify-content: center; padding: 0 9px; border: 1px solid var(--line); color: #344054; background: #fff; }
.pagination-wrap nav span[aria-current="page"] span { color: #fff; background: var(--primary); }
.pagination-wrap svg { width: 18px; height: 18px; }
details pre { max-width: 420px; max-height: 240px; padding: 10px; overflow: auto; border-radius: 6px; color: #e5e7eb; background: #1f2937; font-size: .75rem; }

.guest-body { display: grid; min-height: 100vh; padding: 24px; place-items: center; background: radial-gradient(circle at top, #e8eeff 0, var(--bg) 45%); }
.guest-card { width: min(100%, 430px); padding: 32px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 18px 55px rgb(16 24 40 / 11%); }
.login-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.login-heading h1 { margin-bottom: 3px; font-size: 1.45rem; }
.login-heading p { margin-bottom: 0; color: var(--muted); }
.stack-form { display: grid; gap: 18px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .audit-filters { grid-template-columns: repeat(3, 1fr); }
    .detail-grid, .permission-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .sidebar { position: static; width: 100%; padding: 12px 16px; }
    .brand, .sidebar-footer { display: none; }
    .main-nav { display: flex; overflow-x: auto; }
    .main-nav a { white-space: nowrap; }
    .main-content { margin-left: 0; padding: 24px 16px 48px; }
    .mobile-header { display: flex; justify-content: space-between; margin-bottom: 22px; }
    .page-header, .page-header-actions { align-items: stretch; flex-direction: column; }
    .metric-grid, .form-grid, .audit-filters { grid-template-columns: 1fr; }
    .field-span-2 { grid-column: auto; }
    .inline-create-form { grid-template-columns: 1fr; }
    .filter-bar { align-items: stretch; flex-wrap: wrap; }
    .filter-grow { flex-basis: 100%; }
    .filter-select { width: auto; flex: 1; }
    .resource-bulk-actions { align-items: stretch; flex-direction: column; }
    .guest-card { padding: 24px; }
    .permission-bulk-actions, .permission-bulk-controls, .permission-resource { align-items: stretch; flex-direction: column; }
    .permission-search { width: 100%; flex-basis: auto; }
}
