:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --primary: #155eef;
    --primary-dark: #0f49bd;
    --ink: #172033;
    --muted: #5c667a;
    --line: #dfe4ec;
    --surface: #ffffff;
    --background: #f3f6fb;
    --danger: #b42318;
    --warning: #8a4b08;
    --success: #067647;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(21, 94, 239, .12), transparent 34rem),
        var(--background);
}

body.portal-body {
    display: grid;
    place-items: center;
    padding: 20px;
}

a { color: var(--primary); }

.card {
    width: min(100%, 580px);
    background: var(--surface);
    border: 1px solid rgba(23, 32, 51, .08);
    border-radius: 24px;
    box-shadow: 0 24px 70px rgba(24, 39, 75, .13);
    overflow: hidden;
}

.card-head {
    padding: 30px 30px 22px;
    border-bottom: 1px solid var(--line);
}

.card-body { padding: 28px 30px 30px; }

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 15px;
    color: white;
    font-weight: 800;
    letter-spacing: -.04em;
    background: var(--primary);
}

h1, h2, h3 { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.55rem, 5vw, 2.1rem); }
h2 { margin-bottom: 12px; font-size: 1.1rem; }
p { line-height: 1.58; }
.muted { color: var(--muted); }
.compact { margin: 0; }

.notice,
.error-notice,
.warning-notice,
.success-notice {
    padding: 13px 15px;
    margin: 0 0 18px;
    border-radius: 12px;
    font-size: .94rem;
}

.notice { background: #eef4ff; color: #294b8d; }
.error-notice { background: #fff1f0; color: var(--danger); }
.warning-notice { background: #fff7e8; color: var(--warning); }
.success-notice { background: #ecfdf3; color: var(--success); }

.terms-box {
    max-height: 270px;
    overflow: auto;
    padding: 18px;
    margin: 18px 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfcfe;
}

.terms-text {
    margin: 0;
    white-space: pre-line;
    color: #354057;
    font-size: .93rem;
}

.privacy-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 18px 0;
}

.privacy-item {
    padding: 13px;
    border-radius: 12px;
    background: #f6f8fb;
    font-size: .88rem;
    line-height: 1.45;
}

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 50px;
    padding: 12px 18px;
    border: 0;
    border-radius: 13px;
    color: #fff;
    background: var(--primary);
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    text-decoration: none;
}

.button:hover { background: var(--primary-dark); }
.button.secondary { background: #334155; }
.button.inline { width: auto; min-height: 42px; }
.button.small { width: auto; min-height: 38px; padding: 8px 12px; font-size: .82rem; }

.fine-print {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: .78rem;
    text-align: center;
}

.spinner {
    width: 52px;
    height: 52px;
    margin: 4px auto 22px;
    border: 5px solid #dbe5f7;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.panel-body { background: #eef2f8; }

.panel-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 50px;
}

.panel-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 22px;
    background: #111827;
    color: #fff;
    border-radius: 18px;
}

.panel-topbar h1 { margin: 0; font-size: 1.25rem; }
.panel-topbar p { margin: 3px 0 0; color: #b8c1d1; font-size: .85rem; }

.panel-actions,
.button-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-actions form { margin: 0; }
.panel-notice { margin-top: 18px; }
.panel-section { margin-top: 20px; }
.narrow-panel { width: min(900px, calc(100% - 32px)); }

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 22px 0;
}

.metric {
    padding: 22px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .06);
}

.metric strong { display: block; font-size: 2rem; }
.metric span { color: var(--muted); font-size: .86rem; }

.panel-card {
    padding: 22px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .06);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
td { vertical-align: top; }

.tenant-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.tenant-card {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfcfe;
}

.tenant-card h3 { margin-bottom: 3px; }

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-badge.active,
.status-badge.reviewed { background: #dcfae6; color: #067647; }
.status-badge.pending { background: #fff1cc; color: #8a4b08; }
.status-badge.draft { background: #eaf0ff; color: #294b8d; }
.status-badge.archived { background: #eef0f3; color: #475467; }

.action-stack { display: grid; gap: 10px; min-width: 250px; }

.inline-admin-form {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fafbfc;
}

.inline-admin-form label { font-size: .78rem; font-weight: 700; }
.inline-admin-form input[type="text"],
.inline-admin-form input:not([type]) {
    width: 100%;
    min-height: 38px;
    margin-top: 5px;
    padding: 8px 10px;
    border: 1px solid #cbd3df;
    border-radius: 8px;
    font: inherit;
}

.check-line {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.4;
}

.check-line input { margin-top: 3px; }

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: min(100%, 430px);
    padding: 30px;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(15, 23, 42, .13);
}

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 7px; font-size: .88rem; font-weight: 700; }
.field input,
.field select {
    width: 100%;
    min-height: 47px;
    padding: 10px 12px;
    border: 1px solid #cbd3df;
    border-radius: 10px;
    font: inherit;
    background: #fff;
}
.field textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #cbd3df;
    border-radius: 10px;
    resize: vertical;
    font: inherit;
    line-height: 1.5;
}
.field small { display: block; margin-top: 6px; color: var(--muted); }
.field input:focus,
.field select:focus,
.field textarea:focus { outline: 3px solid rgba(21, 94, 239, .15); border-color: var(--primary); }

.form-grid { display: grid; gap: 16px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.button-row .button { flex: 1; }
.full-column,
.form-section-title { grid-column: 1 / -1; }
.form-section-title { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.form-section-title:first-of-type { border-top: 0; padding-top: 0; }

.workspace-body { background: #f3f6fb; }
.workspace { min-height: 100vh; display: grid; grid-template-columns: 255px minmax(0, 1fr); }
.workspace-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    color: #dbe5f5;
    background: #101828;
    border-right: 1px solid rgba(255,255,255,.06);
}
.workspace-brand { display: flex; align-items: center; gap: 12px; padding: 3px 7px 22px; color: #fff; text-decoration: none; }
.workspace-brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--primary); color: #fff; font-size: 1.35rem; font-weight: 900; }
.workspace-brand strong { display: block; font-size: 1.15rem; }
.workspace-brand small { display: block; margin-top: 2px; color: #98a2b3; }
.workspace-tenant { padding: 14px; margin-bottom: 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 13px; background: rgba(255,255,255,.04); }
.workspace-tenant small { display: block; margin-bottom: 5px; color: #98a2b3; text-transform: uppercase; letter-spacing: .08em; font-size: .65rem; }
.workspace-tenant strong { display: block; font-size: .9rem; line-height: 1.35; }
.workspace-nav { display: grid; gap: 5px; }
.workspace-nav a { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 10px; color: #c7d0df; text-decoration: none; font-size: .9rem; }
.workspace-nav a span { width: 20px; text-align: center; font-size: 1rem; }
.workspace-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.workspace-nav a.active { color: #fff; background: var(--primary); font-weight: 750; }
.workspace-privacy { margin-top: auto; padding: 14px; border-radius: 12px; background: rgba(21,94,239,.15); font-size: .78rem; line-height: 1.45; }
.workspace-privacy strong, .workspace-privacy span { display: block; }
.workspace-privacy span { margin-top: 4px; color: #b8c5d8; }
.workspace-main { min-width: 0; }
.workspace-topbar { display: flex; align-items: center; justify-content: space-between; min-height: 88px; padding: 18px 30px; background: #fff; border-bottom: 1px solid var(--line); }
.workspace-topbar h1 { margin: 0; font-size: 1.5rem; }
.workspace-eyebrow { margin: 0 0 4px; color: var(--muted); font-size: .75rem; }
.workspace-user { display: flex; align-items: center; gap: 13px; font-size: .85rem; }
.workspace-user form { margin: 0; }
.link-button { padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; font: inherit; cursor: pointer; }
.workspace-content { padding: 26px 30px 42px; }
.workspace-footer { padding: 14px 30px 28px; color: var(--muted); text-align: center; font-size: .75rem; }
.workspace-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 18px; }
.workspace-metrics article { min-height: 128px; padding: 19px; border: 1px solid #e5eaf1; border-radius: 15px; background: #fff; box-shadow: 0 6px 22px rgba(15,23,42,.04); }
.workspace-metrics span, .workspace-metrics small { display: block; color: var(--muted); }
.workspace-metrics span { font-size: .78rem; font-weight: 750; text-transform: uppercase; letter-spacing: .03em; }
.workspace-metrics strong { display: block; margin: 10px 0 5px; font-size: 1.75rem; }
.workspace-metrics small { font-size: .75rem; }
.workspace-card { padding: 21px; margin-bottom: 18px; border: 1px solid #e5eaf1; border-radius: 15px; background: #fff; box-shadow: 0 6px 22px rgba(15,23,42,.04); }
.workspace-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.workspace-card-grid .workspace-card { margin: 0; }
.workspace-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.workspace-card-head h2 { margin: 0 0 4px; font-size: 1.05rem; }
.workspace-card-head p { margin: 0; color: var(--muted); font-size: .82rem; }
.privacy-pill { padding: 6px 9px; border-radius: 999px; background: #ecfdf3; color: var(--success); font-size: .7rem; font-weight: 800; }
.privacy-banner { padding: 15px 18px; margin-bottom: 18px; border: 1px solid #c7d7fe; border-radius: 13px; background: #eef4ff; color: #294b8d; font-size: .88rem; }
.bar-chart { display: flex; align-items: end; gap: 10px; min-height: 250px; padding-top: 12px; overflow-x: auto; }
.bar-column { flex: 1 0 42px; display: grid; grid-template-rows: 22px 170px 24px; align-items: end; text-align: center; }
.bar-value { color: var(--muted); font-size: .68rem; }
.bar-track { position: relative; height: 170px; border-bottom: 1px solid var(--line); }
.bar-track i { position: absolute; bottom: 0; left: 15%; width: 70%; min-height: 4px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #3b82f6, var(--primary)); }
.bar-label { padding-top: 7px; color: var(--muted); font-size: .68rem; }
.detail-list { display: grid; gap: 0; margin: 0; }
.detail-list div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: .8rem; }
.detail-list dd { margin: 0; text-align: right; font-size: .84rem; font-weight: 700; }
.filter-row { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.filter-row label { display: grid; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.filter-row input { min-height: 40px; padding: 8px 10px; border: 1px solid #cbd3df; border-radius: 9px; font: inherit; }
.pagination { display: flex; justify-content: flex-end; gap: 18px; padding-top: 16px; color: var(--muted); font-size: .82rem; }
code { padding: 3px 6px; border-radius: 6px; background: #f2f4f7; color: #344054; font-size: .78rem; }
.readiness-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.readiness-grid > div { display: grid; grid-template-columns: 10px 1fr; column-gap: 9px; row-gap: 2px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; }
.readiness-grid strong, .readiness-grid small { grid-column: 2; }
.readiness-grid small { color: var(--muted); }
.readiness-dot { grid-row: 1 / span 2; align-self: center; width: 9px; height: 9px; border-radius: 50%; background: #f79009; }
.readiness-dot.ready { background: #12b76a; }

.terms-preview h2 { margin-top: 10px; font-size: 1.45rem; }
.terms-preview h3 { margin: 24px 0 8px; }
.detail-metadata {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}
.detail-metadata > div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfcfe;
    line-height: 1.5;
}
.preview-text {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfe;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.58;
}

@media (max-width: 760px) {
    .privacy-summary,
    .metric-grid,
    .tenant-grid,
    .detail-metadata,
    .form-grid.two-columns { grid-template-columns: 1fr; }
    .card-head, .card-body { padding-left: 21px; padding-right: 21px; }
    .panel-topbar { align-items: flex-start; flex-direction: column; }
    .panel-actions,
    .button-row { width: 100%; align-items: stretch; flex-direction: column; }
    .panel-actions .button,
    .panel-actions form,
    .panel-actions form .button { width: 100%; }
    .workspace { display: block; }
    .workspace-sidebar { position: static; width: 100%; height: auto; }
    .workspace-nav { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .workspace-privacy { margin-top: 15px; }
    .workspace-topbar { padding: 16px 18px; }
    .workspace-content { padding: 18px; }
    .workspace-metrics,
    .workspace-card-grid,
    .readiness-grid { grid-template-columns: 1fr; }
    .workspace-user > span { display: none; }
    .full-column,
    .form-section-title { grid-column: auto; }
}
