:root {
    color-scheme: dark;
    --bg: #090b12;
    --panel: #111622;
    --panel-2: #171e2d;
    --line: #283247;
    --text: #f5f7fb;
    --muted: #9ba8bd;
    --primary: #6c7cff;
    --primary-hover: #8390ff;
    --danger: #ef5c6c;
    --success: #42d392;
    --warning: #f3bd57;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: inherit; }
button, input, textarea { font: inherit; }
button, .button, a { -webkit-tap-highlight-color: transparent; }

.auth-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 10%, rgba(108, 124, 255, .20), transparent 35%),
        radial-gradient(circle at 90% 90%, rgba(66, 211, 146, .10), transparent 32%),
        var(--bg);
}

.center-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.login-card, .card, .table-card, .empty-state {
    background: rgba(17, 22, 34, .96);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, .28);
}
.login-card { width: min(100%, 470px); padding: 32px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.8rem, 4vw, 2.4rem); }
h2 { margin-bottom: 6px; }
.muted, .help, .section-heading p { color: var(--muted); }
.eyebrow { color: #aab3ff; font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 8px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar {
    position: sticky; top: 0; height: 100vh; padding: 24px 18px;
    border-right: 1px solid var(--line); background: #0d111b;
    display: flex; flex-direction: column; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 800; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, #6c7cff, #8d5cff); font-size: .75rem; }
nav { display: grid; gap: 6px; }
.nav-link { padding: 11px 13px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 650; }
.nav-link:hover, .nav-link.active { background: var(--panel-2); color: var(--text); }
.logout-form { margin-top: auto; }
.content { min-width: 0; padding: 36px clamp(20px, 4vw, 54px); }
.page-header, .section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.page-header { margin-bottom: 24px; }
.section-heading { margin-bottom: 20px; }
.section-heading p { margin-bottom: 0; }

.button {
    appearance: none; border: 1px solid var(--line); border-radius: 9px; padding: 10px 14px;
    background: var(--panel-2); color: var(--text); cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center; font-weight: 720; line-height: 1.1;
}
.button:hover { border-color: #4b5873; }
.button.primary { background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.danger { color: #ffb2bb; border-color: rgba(239, 92, 108, .45); }
.button.ghost { background: transparent; }
.button.small { padding: 7px 10px; font-size: .8rem; }
.button.full { width: 100%; }
.text-link { color: #b9c0ff; }

.field { display: grid; gap: 7px; margin-bottom: 17px; font-weight: 650; }
.field small { color: var(--muted); font-weight: 400; }
input, textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px;
    background: #0c111b; color: var(--text); outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 124, 255, .16); }
textarea { resize: vertical; }
.checkbox-field input { width: auto; margin-right: 7px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.form-card, .card { padding: 24px; margin-bottom: 24px; }
.warning { padding: 12px 14px; border: 1px solid rgba(243, 189, 87, .35); background: rgba(243, 189, 87, .08); color: #f7d48f; border-radius: 9px; margin: 0 0 18px; }
.notice { padding: 12px 14px; border-radius: 9px; margin-bottom: 18px; }
.notice.success { border: 1px solid rgba(66, 211, 146, .4); background: rgba(66, 211, 146, .1); }
.notice.error { border: 1px solid rgba(239, 92, 108, .4); background: rgba(239, 92, 108, .1); }

.table-card { overflow: hidden; margin-bottom: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #121827; color: var(--muted); font-size: .76rem; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.notes-cell { max-width: 250px; color: var(--muted); white-space: pre-wrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.row-actions form { margin: 0; }
.status { display: inline-flex; margin-left: 8px; padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.status.ok { color: #8be9ba; background: rgba(66, 211, 146, .12); }
.status.off { color: #ff9eaa; background: rgba(239, 92, 108, .12); }
.status.neutral { color: #ccd3df; background: rgba(155, 168, 189, .13); }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 14px; }
.device-card { padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: #0d121d; }
.device-card p { color: var(--muted); margin: 12px 0; font-size: .86rem; line-height: 1.6; }
.empty-state { text-align: center; padding: 52px 24px; color: var(--muted); }
code { color: #cad0ff; white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 820px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .logout-form { margin-top: 0; }
    .content { padding: 24px 16px; }
    .page-header, .section-heading { align-items: stretch; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
}
