:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dce5ef;
    --border-strong: #c7d3e0;
    --text: #14243a;
    --muted: #64778e;
    --primary: #175cd3;
    --primary-hover: #124ba9;
    --accent: #f58a1f;
    --success: #16794d;
    --success-bg: #e9f8f0;
    --danger: #b42318;
    --danger-bg: #fff0ee;
    --warning: #9a5b00;
    --warning-bg: #fff7e5;
    --shadow: 0 18px 44px rgba(25, 55, 92, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 100% 0, rgba(23, 92, 211, .08), transparent 32rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}
button, input, select { font: inherit; }
a { color: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(220px, auto) 1fr auto;
    align-items: center;
    gap: 28px;
    min-height: 72px;
    padding: 10px clamp(18px, 4vw, 56px);
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(18px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--primary), #0b3c92);
    color: #fff;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(23,92,211,.25);
}
.brand-mark-large { width: 54px; height: 54px; border-radius: 16px; font-size: 22px; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a { padding: 9px 12px; border-radius: 9px; color: #43566d; font-weight: 650; text-decoration: none; }
.nav a:hover { background: #eef4fb; color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.user-menu form { margin: 0; }

.main { width: min(1440px, calc(100% - 36px)); margin: 0 auto; padding: 34px 0 60px; }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(450px, 100%); padding: 34px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 15px; margin-bottom: 30px; }
.auth-brand h1 { margin: 0 0 2px; font-size: 24px; }
.auth-brand p, .auth-note { margin: 0; color: var(--muted); }
.auth-note { margin-top: 22px; text-align: center; font-size: 13px; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 2px 0 4px; font-size: clamp(27px, 3vw, 38px); line-height: 1.15; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--primary) !important; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.device-title-row, .title-with-badge { display: flex; align-items: center; gap: 14px; }
.title-with-badge { flex-wrap: wrap; gap: 10px; }
.device-heading { align-items: center; }
.device-avatar { display: grid; place-items: center; width: 46px; height: 46px; background: #edf4ff; border: 1px solid #d7e6fb; border-radius: 14px; font-size: 22px; }
.device-avatar-large { width: 60px; height: 60px; border-radius: 18px; font-size: 28px; }

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 750;
    text-decoration: none;
    transition: .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 20px rgba(23,92,211,.18); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: #fff; border-color: var(--border-strong); color: #33475e; }
.button-secondary:hover, .button-ghost:hover { background: #f0f5fa; }
.button-ghost { min-height: 34px; padding: 6px 10px; background: transparent; border-color: var(--border); color: #475b72; }
.button-danger { background: var(--danger); color: #fff; }
.button-danger:hover { background: #8e1c13; }
.button-small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button-full { width: 100%; }

.alert { margin: 0 0 20px; padding: 14px 16px; border: 1px solid; border-radius: 12px; font-weight: 600; }
.alert-success { color: var(--success); background: var(--success-bg); border-color: #b9e5ce; }
.alert-error { color: var(--danger); background: var(--danger-bg); border-color: #f2c5c0; }
.alert-warning { color: var(--warning); background: var(--warning-bg); border-color: #ecd99f; }
.alert-info { color: #1556a8; background: #eaf3ff; border-color: #c8ddfa; }
.one-time-code-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.one-time-code { display: inline-block; padding: 9px 12px; background: #fff; border: 1px dashed currentColor; border-radius: 8px; font-size: 18px; letter-spacing: .08em; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { display: flex; align-items: center; gap: 15px; min-height: 110px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(25,55,92,.04); }
.stat-card strong { display: block; font-size: 30px; line-height: 1; letter-spacing: -.03em; }
.stat-card span:last-child { display: block; margin-top: 7px; color: var(--muted); font-size: 13px; }
.stat-icon { display: grid !important; place-items: center; width: 42px; height: 42px; margin: 0 !important; border-radius: 13px; background: #edf4ff; color: var(--primary) !important; font-size: 20px !important; }
.status-dot { display: inline-block; flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(128,145,166,.1); }
.status-dot.online { background: #25a56a; box-shadow: 0 0 0 4px rgba(37,165,106,.12); }
.status-dot.offline { background: #95a2b3; }
.stat-card > .status-dot { width: 15px; height: 15px; margin: 13px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(25,55,92,.045); overflow: hidden; }
.compact-panel { padding: 24px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.panel-header h2, .spec-panel h2, .compact-panel h2, .command-panel h2 { margin: 0 0 3px; font-size: 18px; letter-spacing: -.015em; }
.panel-header p, .command-panel p, .danger-panel p { margin: 0; color: var(--muted); font-size: 13px; }
.search-box { width: min(360px, 100%); }
.search-box input, .panel-header > input { width: 100%; min-width: 260px; }

.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 20px; }
.device-card { display: block; min-width: 0; padding: 18px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 14px; text-decoration: none; transition: .16s ease; }
.device-card:hover { transform: translateY(-2px); border-color: #b6cae2; box-shadow: 0 14px 30px rgba(25,55,92,.09); }
.device-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.device-card h3 { margin: 0 0 3px; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-card > p { margin: 0 0 16px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-card-footer { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.mini-specs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.mini-specs div { min-width: 0; padding: 9px; background: #fff; border: 1px solid #e4ebf3; border-radius: 9px; }
.mini-specs dt { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.mini-specs dd { margin: 3px 0 0; font-size: 13px; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 7px; width: max-content; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge-online { color: var(--success); background: var(--success-bg); }
.badge-offline { color: #5f6f82; background: #edf1f5; }
.badge-neutral { color: #4f6075; background: #edf1f5; }

.field { margin-bottom: 17px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 750; }
input, select { width: 100%; min-height: 43px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 9px; background: #fff; color: var(--text); outline: 0; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23,92,211,.12); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.steps-list { margin: 18px 0 0; padding-left: 22px; color: #42556c; }
.steps-list li + li { margin-top: 12px; }

.summary-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.summary-strip > div { min-width: 0; padding: 17px 20px; border-right: 1px solid var(--border); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.summary-strip strong { display: block; margin-top: 5px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { min-width: 0; }
.tab-list { display: flex; gap: 5px; margin-bottom: 16px; padding: 6px; overflow-x: auto; background: #eaf0f7; border-radius: 12px; }
.tab-button { flex: 0 0 auto; padding: 9px 13px; border: 0; border-radius: 8px; background: transparent; color: #52657b; cursor: pointer; font-weight: 700; }
.tab-button span { padding: 2px 6px; margin-left: 4px; border-radius: 999px; background: #dce5ef; font-size: 10px; }
.tab-button.active { background: #fff; color: var(--primary); box-shadow: 0 4px 12px rgba(25,55,92,.08); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.spec-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.spec-panel { padding: 22px; }
.spec-panel h2 { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.detail-list { margin: 0; }
.detail-list div { display: grid; grid-template-columns: minmax(130px, .9fr) minmax(0, 1.3fr); gap: 16px; padding: 11px 0; border-bottom: 1px solid #edf1f5; }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 13px; }
.detail-list dd { min-width: 0; margin: 0; text-align: right; font-size: 13px; font-weight: 700; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px !important; }
.break-word { word-break: break-all; white-space: normal; }
.command-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px; margin-bottom: 18px; }
.command-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.command-actions form { margin: 0; }
.danger-panel { border-color: #f1c3be; background: #fffafa; }
.danger-panel p { margin: 8px 0 18px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 16px; border-bottom: 1px solid #e9eef4; text-align: left; vertical-align: middle; }
th { background: #f8fafc; color: #5c6e83; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
tbody tr:hover { background: #fbfdff; }
tbody tr:last-child td { border-bottom: 0; }
.muted-cell { color: var(--muted); text-align: center; padding: 30px; }

.timeline { padding: 16px 22px 24px; }
.timeline-item { position: relative; display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding: 10px 0; }
.timeline-item:not(:last-child)::after { content: ""; position: absolute; left: 5px; top: 25px; bottom: -10px; width: 1px; background: var(--border); }
.timeline-dot { width: 11px; height: 11px; margin-top: 5px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px #e8f1ff; }
.timeline-item strong { font-size: 13px; }
.timeline-item p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.history-columns { align-items: start; margin-bottom: 0; }

.empty-state { padding: 54px 24px; text-align: center; }
.empty-state > span { display: block; font-size: 42px; }
.empty-state h1, .empty-state h3 { margin: 12px 0 4px; }
.empty-state p { margin: 0 auto 18px; color: var(--muted); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .device-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar { grid-template-columns: 1fr auto; }
    .nav { grid-row: 2; grid-column: 1 / -1; }
    .summary-strip { grid-template-columns: repeat(2, 1fr); }
    .summary-strip > div:nth-child(2) { border-right: 0; }
    .summary-strip > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
}

@media (max-width: 760px) {
    .main { width: min(100% - 24px, 1440px); padding-top: 22px; }
    .topbar { position: static; gap: 12px; padding: 12px 16px; }
    .user-menu > span { display: none; }
    .nav { overflow-x: auto; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .page-heading > .button { width: 100%; }
    .stats-grid, .device-grid, .spec-grid, .two-column { grid-template-columns: 1fr; }
    .device-grid { padding: 13px; }
    .panel-header { align-items: stretch; flex-direction: column; padding: 18px; }
    .search-box, .search-box input, .panel-header > input { width: 100%; min-width: 0; }
    .summary-strip { grid-template-columns: 1fr; }
    .summary-strip > div { border-right: 0; border-bottom: 1px solid var(--border); }
    .summary-strip > div:last-child { border-bottom: 0; }
    .command-panel { align-items: stretch; flex-direction: column; }
    .command-actions, .command-actions form, .command-actions .button { width: 100%; }
    .detail-list div { grid-template-columns: 1fr; gap: 3px; }
    .detail-list dd { text-align: left; }
    .form-grid { grid-template-columns: 1fr; gap: 0; }
    .one-time-code-row { align-items: stretch; flex-direction: column; }
    .one-time-code { font-size: 15px; text-align: center; }
    .auth-card { padding: 25px; }
}

@media (max-width: 430px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { min-height: 88px; }
    .mini-specs { grid-template-columns: 1fr; }
    .device-title-row { align-items: flex-start; }
}

.nowrap { white-space: nowrap; }
.audit-details { max-width: 360px; word-break: break-word; color: var(--muted); font-size: 12px; }
