:root {
    --navy: #102a43;
    --navy-2: #173f5f;
    --blue: #1877d2;
    --blue-dark: #0f5ca8;
    --cyan: #42b9e8;
    --ink: #1d2939;
    --muted: #667085;
    --line: #e5eaf0;
    --surface: #ffffff;
    --canvas: #f4f7fa;
    --green: #16875d;
    --amber: #b66a05;
    --red: #c9364d;
    --shadow: 0 10px 35px rgba(16, 42, 67, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(66, 185, 232, .4);
    outline-offset: 2px;
}
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 999; background: #fff; padding: .7rem 1rem; }
.skip-link:focus { top: 1rem; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar {
    position: sticky; top: 0; height: 100vh; padding: 1.35rem 1rem;
    color: #dce9f3; background: linear-gradient(175deg, #0b263e 0%, #123f63 100%);
    display: flex; flex-direction: column; z-index: 20;
}
.brand { display: flex; align-items: center; min-height: 56px; padding: 0 .5rem 1.25rem; }
.brand img { display: block; width: 152px; height: 64px; object-fit: contain; object-position: left center; }
.nav-label { color: #7fb1d2; font-size: .69rem; letter-spacing: .12em; font-weight: 800; text-transform: uppercase; padding: .8rem .75rem .45rem; }
.nav { display: grid; gap: .25rem; }
.nav a {
    display: flex; align-items: center; gap: .75rem; min-height: 44px; padding: .68rem .8rem;
    border-radius: 9px; color: #dce9f3; font-weight: 650;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: #fff; color: var(--navy); box-shadow: 0 8px 22px rgba(0,0,0,.13); }
.nav-icon { width: 22px; text-align: center; font-size: 1rem; }
.sidebar-spacer { flex: 1; }
.sidebar-user { border-top: 1px solid rgba(255,255,255,.12); padding: 1rem .65rem .2rem; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { color: #a9c8dc; font-size: .82rem; }
.logout-form { margin: .65rem 0 0; }
.logout-button { border: 0; background: none; color: #dce9f3; padding: 0; font-weight: 650; cursor: pointer; }
.main { min-width: 0; }
.topbar {
    height: 76px; padding: 0 clamp(1rem, 3vw, 2.5rem); background: rgba(255,255,255,.93);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 1.08rem; color: var(--navy); }
.topbar-meta { color: var(--muted); font-size: .85rem; }
.menu-button { display: none; border: 0; background: none; font-size: 1.4rem; color: var(--navy); }
.content { width: min(1500px, 100%); margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.5rem); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { color: var(--blue-dark); font-weight: 800; letter-spacing: .1em; text-transform: uppercase; font-size: .72rem; margin-bottom: .35rem; }
.page-head h2 { color: var(--navy); font-size: clamp(1.65rem, 3vw, 2.25rem); line-height: 1.15; margin: 0 0 .45rem; letter-spacing: -.03em; }
.page-head p { margin: 0; color: var(--muted); max-width: 680px; }
.btn {
    border: 1px solid transparent; border-radius: 9px; min-height: 42px; padding: .62rem .95rem;
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font-weight: 750; cursor: pointer;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(24,119,210,.18); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { border-color: var(--line); background: #fff; color: var(--navy); }
.btn-danger { background: #fff; border-color: #f4cbd2; color: var(--red); }
.btn-small { min-height: 34px; padding: .4rem .65rem; font-size: .82rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.card-header h3 { margin: 0; color: var(--navy); font-size: 1.02rem; }
.card-body { padding: 1.25rem; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { padding: 1.2rem; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; right: -24px; top: -24px; width: 82px; height: 82px; border-radius: 50%; background: var(--accent, var(--blue)); opacity: .08; }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.stat-value { color: var(--navy); font-size: 2rem; font-weight: 850; letter-spacing: -.04em; margin: .18rem 0; }
.stat-note { color: var(--muted); font-size: .76rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .7fr); gap: 1.25rem; }
.dashboard-grid-full { grid-template-columns: minmax(0, 1fr); }
.filters { display: flex; flex-wrap: wrap; gap: .65rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.field { display: grid; gap: .4rem; margin-bottom: 1rem; }
.field label { color: #344054; font-weight: 750; font-size: .84rem; }
.field input, .field select, .field textarea, .filters input, .filters select {
    width: 100%; border: 1px solid #ccd5df; border-radius: 9px; background: #fff; color: var(--ink); padding: .68rem .78rem;
}
.filters input { flex: 1; min-width: 200px; }
.filters select { width: auto; min-width: 150px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(66,185,232,.14); }
.field small { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-actions { display: flex; gap: .65rem; justify-content: flex-end; margin-top: .5rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .82rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: #667085; background: #fbfcfd; font-size: .72rem; letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; }
tbody tr:hover { background: #fbfdff; }
.client-cell strong, .device-cell strong { display: block; color: var(--navy); }
.client-cell span, .device-cell span { display: block; color: var(--muted); font-size: .8rem; }
.device-summary-row.details-open { background: #f7fbfe; }
.device-toggle { white-space: nowrap; }
.device-toggle-icon { display: inline-block; font-size: 1rem; line-height: 1; transition: transform .18s ease; }
.device-toggle[aria-expanded="true"] .device-toggle-icon { transform: rotate(180deg); }
.device-detail-row[hidden] { display: none; }
.device-detail-row:hover { background: transparent; }
.device-detail-row > td { padding: 0; background: #f7fbfe; border-bottom: 1px solid #cfe0ec; }
.device-detail-panel { padding: 1rem 1.15rem 1.2rem; border-left: 3px solid var(--cyan); }
.device-detail-heading {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    margin-bottom: .8rem;
}
.device-detail-heading strong { display: block; color: var(--navy); }
.device-detail-heading span { display: block; color: var(--muted); font-size: .8rem; }
.inline-account-table { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.inline-account-table th, .inline-account-table td { padding: .68rem .8rem; }
.inline-account-table tbody tr:last-child td { border-bottom: 0; }
.inline-empty { padding: 1rem; border: 1px dashed #b9cfde; border-radius: 9px; color: var(--muted); background: #fff; }
.badge { display: inline-flex; align-items: center; gap: .36rem; border-radius: 999px; padding: .27rem .57rem; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.healthy, .badge.active { color: var(--green); background: #e8f7f1; }
.badge.warning { color: var(--amber); background: #fff3dd; }
.badge.stale, .badge.inactive { color: var(--red); background: #fdecef; }
.badge.unknown { color: #667085; background: #eef1f5; }
.stack { display: grid; gap: .75rem; }
.alert { border-radius: 10px; padding: .85rem 1rem; margin: 0 0 1rem; border: 1px solid; }
.alert-success { color: #0f6849; border-color: #b7e2d2; background: #edf9f4; }
.alert-error { color: #a5293e; border-color: #f3c5cd; background: #fff0f2; }
.alert-info { color: #155991; border-color: #bfddf5; background: #eef7ff; }
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto 1rem; border-radius: 50%; background: #eef7ff; color: var(--blue); font-size: 1.35rem; }
.empty h3 { color: var(--navy); margin: 0 0 .4rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.muted { color: var(--muted); }
.actions { display: flex; gap: .45rem; flex-wrap: wrap; }
.secret-box { border: 1px solid #b9ddf5; background: #f2f9ff; border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.secret-row { display: flex; gap: .5rem; margin-top: .4rem; }
.secret-row input { flex: 1; min-width: 0; border: 1px solid #a5cce7; border-radius: 8px; padding: .65rem; }
.detail-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 1.25rem; align-items: start; }
.detail-list { display: grid; gap: .8rem; }
.detail-row { display: grid; grid-template-columns: 140px 1fr; gap: .75rem; }
.detail-row dt { color: var(--muted); }
.detail-row dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.login-page { background: #ecf3f8; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(340px, 520px) 1fr; }
.login-panel { background: #fff; display: flex; align-items: center; padding: clamp(2rem, 6vw, 5rem); position: relative; z-index: 2; }
.login-card { width: 100%; max-width: 390px; margin: auto; }
.login-logo { width: 190px; height: 92px; object-fit: contain; object-position: left center; margin-bottom: 2rem; }
.login-card h1 { color: var(--navy); margin: 0 0 .5rem; font-size: 2rem; letter-spacing: -.04em; }
.login-card > p { color: var(--muted); margin: 0 0 2rem; }
.login-card .btn { width: 100%; margin-top: .4rem; }
.login-aside {
    position: relative; overflow: hidden; padding: clamp(2rem, 6vw, 5rem); color: #fff;
    display: flex; align-items: flex-end; background: linear-gradient(140deg, rgba(10,39,64,.97), rgba(17,79,119,.9));
}
.login-aside::before, .login-aside::after { content: ""; position: absolute; border: 1px solid rgba(255,255,255,.12); border-radius: 50%; }
.login-aside::before { width: 520px; height: 520px; right: -130px; top: -140px; }
.login-aside::after { width: 340px; height: 340px; right: 10%; top: 10%; }
.login-message { position: relative; z-index: 2; max-width: 670px; }
.login-message .eyebrow { color: #77d2f4; }
.login-message h2 { font-size: clamp(2.1rem, 5vw, 4.4rem); line-height: 1.04; letter-spacing: -.05em; margin: .5rem 0 1.25rem; }
.login-message p { color: #c9deeb; font-size: 1.08rem; max-width: 570px; }
.footer-note { color: var(--muted); font-size: .78rem; margin-top: 1.5rem; }
.mfa-code-input {
    font-size: 1.55rem !important;
    font-weight: 800;
    letter-spacing: .34em;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.mfa-setup-card { width: min(760px, 100%); }
.setup-steps { list-style: none; counter-reset: setup; margin: 0; padding: 0; display: grid; gap: 1.4rem; }
.setup-steps > li { counter-increment: setup; position: relative; padding-left: 3.1rem; }
.setup-steps > li::before {
    content: counter(setup); position: absolute; left: 0; top: -.15rem; width: 2.2rem; height: 2.2rem;
    display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--blue); font-weight: 850;
}
.setup-steps strong, .setup-steps span { display: block; }
.setup-steps span { color: var(--muted); margin-top: .15rem; }
.mfa-qr {
    width: min(260px, 100%); aspect-ratio: 1; margin: 1rem 0; padding: .55rem;
    border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.mfa-qr svg { display: block; width: 100%; height: 100%; }
.mfa-confirm-form { max-width: 340px; margin: 1.5rem 0 0 3.1rem; }
.recovery-code-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem;
    padding: 1rem; border: 1px dashed #9bbcd4; border-radius: 10px; background: #f7fbfe;
}
.recovery-code-grid code { color: var(--navy); font-size: 1rem; font-weight: 750; letter-spacing: .04em; }

@media print {
    .sidebar, .topbar, .page-head, .alert, .form-actions, .mfa-setup-card form { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    .mfa-setup-card { border: 0; box-shadow: none; }
    .recovery-code-grid { border: 1px solid #000; }
}

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; width: 260px; left: -280px; transition: left .2s ease; box-shadow: 20px 0 45px rgba(0,0,0,.2); }
    body.nav-open .sidebar { left: 0; }
    .menu-button { display: inline-grid; place-items: center; }
    .topbar { height: 66px; }
    .topbar-meta { display: none; }
    .login-shell { grid-template-columns: 1fr; }
    .login-aside { display: none; }
    .login-panel { min-height: 100vh; }
}
@media (max-width: 600px) {
    .content { padding: 1rem; }
    .page-head { display: grid; }
    .page-head .btn { width: 100%; }
    .stat-grid, .form-grid { grid-template-columns: 1fr; }
    .filters input, .filters select { width: 100%; }
    .detail-row { grid-template-columns: 1fr; gap: .1rem; }
    .secret-row { display: grid; }
    .recovery-code-grid { grid-template-columns: 1fr; }
    .mfa-confirm-form { margin-left: 0; }
    .device-detail-heading { align-items: flex-start; flex-direction: column; }
    .device-detail-heading .btn { width: 100%; }
}
