:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #18212f;
    --muted: #667085;
    --line: #e3e8ef;
    --brand: #1f5f99;
    --brand-dark: #164b7b;
    --success: #147a4b;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --warning-bg: #fff8e6;
    --info-bg: #eef6ff;
    --shadow: 0 10px 30px rgba(24, 33, 47, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); color: var(--ink); }
body { margin: 0; min-height: 100vh; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
button, input { font: inherit; }
code, .mono-small { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar { height: 72px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 30; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); font-weight: 750; letter-spacing: -.01em; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 13px; font-weight: 850; }
.brand-mark-large { width: 58px; height: 58px; border-radius: 15px; font-size: 18px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar, .member-avatar, .group-avatar { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: #e7eef6; color: var(--brand-dark); font-weight: 800; }
.user-label { display: grid; line-height: 1.2; }
.user-label small { color: var(--muted); margin-top: 3px; }
.impersonation-pill, .context-badge { border: 1px solid #e6b800; background: #fff8c5; color: #684f00; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 700; }
.logout-form { margin: 0 0 0 6px; }

.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { border-right: 1px solid var(--line); background: #fbfcfd; padding: 24px 18px; }
.nav { display: grid; gap: 6px; }
.nav a { display: flex; align-items: center; gap: 12px; color: #344054; padding: 11px 12px; border-radius: 9px; font-weight: 650; }
.nav a:hover { background: #eef4fa; color: var(--brand-dark); }
.nav-icon { width: 22px; text-align: center; color: var(--brand); }
.sidebar-card { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 20px; }
.sidebar-card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }
.main { padding: 38px clamp(24px, 4vw, 64px) 64px; max-width: 1500px; width: 100%; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-header h1, .hero h1 { margin: 2px 0 0; font-size: clamp(30px, 4vw, 44px); letter-spacing: -.035em; line-height: 1.05; }
.detail-header { border-bottom: 1px solid var(--line); padding-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--brand); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; font-weight: 800; }
.lead-meta, .muted { color: var(--muted); }
.lead-meta { margin: 8px 0 0; }
.resource-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: 11px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 9px; }
.breadcrumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.breadcrumbs a { color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.hero { padding: 34px 0 26px; }
.hero p:last-child { color: var(--muted); font-size: 18px; max-width: 680px; }
.resource-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.resource-card { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; gap: 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px; color: var(--ink); box-shadow: var(--shadow); }
.resource-card:hover { border-color: #b8cadb; transform: translateY(-1px); }
.resource-card-icon, .resource-row-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: #eef4fa; color: var(--brand); font-size: 20px; }
.resource-card div, .resource-row-main { display: grid; gap: 4px; }
.resource-card small, .resource-row-main small { color: var(--muted); }
.chevron { font-size: 28px; color: #98a2b3; }
.resource-list { overflow: hidden; }
.resource-row { display: grid; grid-template-columns: 50px minmax(0,1fr) auto; gap: 14px; align-items: center; padding: 16px 18px; color: var(--ink); border-bottom: 1px solid var(--line); }
.resource-row:last-child { border-bottom: 0; }
.resource-row:hover { background: #f8fafc; }
.empty-state { padding: 48px; text-align: center; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--muted); }
.empty-icon { font-size: 40px; color: #98a2b3; }

.info-panel, .security-card, .audit-panel { padding: 22px; }
.section-heading { margin-bottom: 16px; }
.section-heading h2, .section-heading h3 { margin: 0; letter-spacing: -.02em; }
.section-heading-actions { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.definition-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin: 0 0 20px; }
.definition-grid > div { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
dt { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
dd { margin: 6px 0 0; overflow-wrap: anywhere; }
.quota-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.quota-progress { width: 100%; height: 14px; margin-top: 8px; accent-color: var(--brand); }
.two-column { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .75fr); gap: 20px; margin-top: 20px; }
.two-column > .panel:first-child { padding: 22px; }
.security-section { margin-top: 28px; }
.security-card { margin-bottom: 16px; }
.member-list { border-top: 1px solid var(--line); }
.member-row { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
.member-avatar, .group-avatar { width: 36px; height: 36px; }
.group-avatar { background: #efeafa; color: #6b3fa0; }
.initials-avatar { font-size: 11px; }
.member-main { display: grid; min-width: 0; flex: 1; }
.member-main small { color: var(--muted); margin-top: 2px; }
.member-inactive { opacity: .58; }
.empty-inline { color: var(--muted); padding: 14px 0; }
.audit-list { display: grid; }
.audit-row { display: grid; grid-template-columns: 56px minmax(0,1fr); gap: 10px 12px; border-top: 1px solid var(--line); padding: 12px 0; }
.audit-row:first-child { border-top: 0; }
.audit-row p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.audit-row time { grid-column: 2; color: #98a2b3; font-size: 11px; }
.audit-action { align-self: start; border-radius: 999px; background: #eef4fa; color: var(--brand); font-size: 10px; font-weight: 800; text-transform: uppercase; padding: 5px 7px; text-align: center; }

.input { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid #cfd7e3; border-radius: 8px; background: #fff; color: var(--ink); outline: none; }
.input:focus { border-color: #6c9bc3; box-shadow: 0 0 0 3px rgba(31,95,153,.12); }
.field { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 650; font-size: 13px; }
.field-label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.button { appearance: none; border: 0; border-radius: 8px; min-height: 38px; padding: 8px 13px; font-weight: 750; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-dark); color: #fff; }
.button-success { background: var(--success); color: #fff; }
.button-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f7c7c3; }
.button-secondary { background: #eef2f6; color: #344054; border: 1px solid #d8e0e8; }
.button-quiet { background: transparent; color: var(--muted); }
.button-small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.button-block { width: 100%; }
.inline-add { display: flex; gap: 8px; align-items: flex-start; width: min(420px, 50%); }
.lookup-wrap { position: relative; width: 100%; }
.compact-lookup { min-width: 180px; }
.lookup-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 12px 30px rgba(24,33,47,.15); overflow: hidden; z-index: 50; max-height: 280px; overflow-y: auto; }
.lookup-option { display: block; width: 100%; border: 0; background: #fff; text-align: left; padding: 10px 11px; cursor: pointer; }
.lookup-option:hover { background: #f2f6fa; }
.lookup-form { position: relative; }

.notice { border-radius: 10px; padding: 12px 14px; font-size: 13px; }
.notice-warning { background: var(--warning-bg); color: #684f00; }
.notice-info { background: var(--info-bg); color: #174f7d; }
.form-error { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 10px; font-size: 13px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; background: #143b2a; color: #fff; padding: 12px 15px; border-radius: 9px; box-shadow: var(--shadow); z-index: 100; }
.toast[data-kind="error"] { background: #762019; }

.bare-main { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: radial-gradient(circle at top left, #e9f2fb, transparent 42%), var(--bg); }
.login-shell { width: min(900px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; gap: 42px; align-items: center; }
.login-brand h1 { font-size: clamp(38px, 6vw, 62px); line-height: 1; letter-spacing: -.05em; margin: 20px 0 12px; }
.login-brand p { color: var(--muted); font-size: 18px; }
.login-panel { padding: 28px; }
.panel-heading h2 { margin: 0 0 22px; font-size: 28px; }
.error-panel { max-width: 700px; padding: 32px; }
.error-panel h1 { margin: 0; }
.error-panel p { color: var(--muted); margin-bottom: 22px; }

.member-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    margin-left: 0.5rem;
    padding: 0.2rem 0.55rem;

    min-width: 1.6rem;

    border-radius: 999px;

    background: #e8edf4;
    color: #4b5563;

    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
}

@media (max-width: 980px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .nav { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .sidebar-card { display: none; }
    .two-column, .resource-grid { grid-template-columns: 1fr; }
    .topbar-user .user-label { display: none; }
}
@media (max-width: 680px) {
    .topbar { padding: 0 14px; }
    .brand > span:last-child, .impersonation-pill { display: none; }
    .main { padding: 24px 14px 50px; }
    .nav { grid-template-columns: 1fr; }
    .page-header, .section-heading-actions { display: block; }
    .resource-id { display: inline-block; margin-top: 14px; }
    .definition-grid { grid-template-columns: 1fr; }
    .inline-add { width: 100%; margin-top: 14px; }
    .login-shell { grid-template-columns: 1fr; gap: 20px; }
    .login-brand { text-align: center; }
    .login-brand .brand-mark { margin: 0 auto; }
    .resource-grid { grid-template-columns: 1fr; }
}
