:root {
    --ink-950: #071525;
    --ink-900: #102238;
    --ink-700: #40566f;
    --ink-500: #71849a;
    --line: #dfe8f1;
    --surface: #ffffff;
    --surface-soft: #f4f8fb;
    --brand: #087f8c;
    --brand-dark: #05616b;
    --brand-soft: #dff5f4;
    --blue: #2876e5;
    --danger: #d9485f;
    --danger-soft: #fff0f2;
    --warning: #dc8a16;
    --success: #15936f;
    --shadow: 0 18px 45px rgba(19, 47, 76, .08);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html { scroll-behavior: smooth; }

body.app-shell {
    margin: 0;
    color: var(--ink-950);
    background:
        radial-gradient(circle at 8% 0%, rgba(8, 127, 140, .10), transparent 26rem),
        linear-gradient(180deg, #f8fbfd 0%, #eef4f8 100%);
    font-family: "Segoe UI", Arial, system-ui, sans-serif;
    min-height: 100vh;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    color: #fff;
    background: rgba(7, 21, 37, .94);
    border-bottom: 1px solid rgba(255, 255, 255, .09);
    backdrop-filter: blur(18px);
}

.nav-inner {
    width: min(1180px, calc(100% - 32px));
    min-height: 76px;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 13px;
    color: #fff;
    background: linear-gradient(145deg, #0eb3b0, #207ce5);
    box-shadow: 0 8px 24px rgba(14, 179, 176, .24);
}
.brand-mark svg { width: 23px; height: 23px; }
.brand-copy strong { display: block; font-size: 16px; line-height: 1.3; letter-spacing: .01em; }
.brand-copy span { display: block; margin-top: 2px; color: #92a8be; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }

.nav-actions { display: flex; align-items: center; gap: 10px; }
.nav-clock { color: #afc1d3; font-size: 12px; font-variant-numeric: tabular-nums; }
.connection { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #c6d5e3; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #e2586c; box-shadow: 0 0 0 4px rgba(226, 88, 108, .13); }
.status-dot.online { background: #31c99a; box-shadow: 0 0 0 4px rgba(49, 201, 154, .13); }

.btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-weight: 650;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: transform .18s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible { outline: 3px solid rgba(40, 118, 229, .25); outline-offset: 2px; }
.btn-primary { color: #fff; background: var(--brand); box-shadow: 0 8px 18px rgba(8, 127, 140, .18); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { color: #d7e4ef; border-color: rgba(255, 255, 255, .15); background: rgba(255, 255, 255, .06); }
.btn-ghost:hover { background: rgba(255, 255, 255, .11); }
.btn-light { color: var(--ink-900); border-color: var(--line); background: #fff; }
.btn-light:hover { border-color: #bfcedd; background: #f9fbfc; }
.btn svg { width: 16px; height: 16px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.active { color: #a7f3e5; border-color: rgba(49, 201, 154, .5); background: rgba(49, 201, 154, .13); }

.page-wrap { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 38px 0 56px; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 8px; color: var(--brand); font-size: 11px; font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
.hero h1 { margin: 0; color: var(--ink-950); font-size: clamp(27px, 4vw, 38px); line-height: 1.14; letter-spacing: -.035em; }
.hero p { margin: 9px 0 0; color: var(--ink-500); font-size: 14px; }
.last-update { color: var(--ink-500); font-size: 12px; white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 30px; }
.metric-card {
    min-height: 118px;
    padding: 19px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: rgba(255, 255, 255, .90);
    border: 1px solid rgba(208, 221, 233, .84);
    border-radius: 16px;
    box-shadow: 0 10px 28px rgba(20, 47, 75, .045);
}
.metric-label { display: flex; align-items: center; gap: 8px; color: var(--ink-500); font-size: 13px; font-weight: 650; }
.metric-icon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: var(--brand); background: var(--brand-soft); }
.metric-icon svg { width: 15px; height: 15px; }
.metric-value { color: var(--ink-950); font-size: 27px; font-weight: 750; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metric-value small { margin-left: 4px; color: var(--ink-500); font-size: 12px; font-weight: 500; letter-spacing: 0; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; color: var(--ink-950); font-size: 17px; letter-spacing: -.015em; }
.section-head span { color: var(--ink-500); font-size: 12px; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }

.device-card {
    position: relative;
    overflow: hidden;
    padding: 21px;
    color: inherit;
    background: rgba(255, 255, 255, .94);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 10px 32px rgba(14, 42, 69, .055);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.device-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand); opacity: 0; transition: opacity .2s ease; }
.device-card:hover { transform: translateY(-3px); border-color: #b9cbdc; box-shadow: var(--shadow); }
.device-card:hover::before { opacity: 1; }
.device-card.alarm { border-color: #f2bcc5; background: linear-gradient(145deg, #fff, #fff7f8); }
.device-card.alarm::before { opacity: 1; background: var(--danger); }
.device-card.warning { border-color: #ead09f; background: linear-gradient(145deg, #fff, #fffbf3); }
.device-card.warning::before { opacity: 1; background: var(--warning); }
.device-card.offline { border-color: #cbd7e2; background: #f8fafc; }
.device-card.offline::before { opacity: 1; background: #8798aa; }
.device-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.device-name { margin: 0; font-size: 16px; font-weight: 720; letter-spacing: -.01em; }
.device-location { min-height: 18px; margin: 5px 0 0; color: var(--ink-500); font-size: 12px; }
.state-badge { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; padding: 6px 8px; border-radius: 8px; color: #087052; background: #e7f8f2; font-size: 10px; font-weight: 700; }
.state-badge.offline { color: #a23a4b; background: #fff0f2; }
.state-badge.alarm { color: #a1263d; background: #ffe6eb; }
.state-badge.warning { color: #9a5d08; background: #fff2d8; }
.state-badge.normal { color: #087052; background: #e7f8f2; }
.state-badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.temp-block { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin: 25px 0 20px; }
.temp-caption { margin: 0 0 5px; color: var(--ink-500); font-size: 11px; font-weight: 700; letter-spacing: .10em; text-transform: uppercase; }
.temperature {
    display: flex;
    align-items: baseline;
    gap: 5px;
    font-size: 42px;
    font-weight: 760;
    line-height: 1;
    letter-spacing: -.055em;
    font-variant-numeric: tabular-nums;
}
.temperature sup {
    display: block;
    margin: 0;
    font-size: 15px;
    font-weight: 650;
    line-height: 1;
    letter-spacing: 0;
    vertical-align: baseline;
}
.range { text-align: right; color: var(--ink-500); font-size: 11px; line-height: 1.7; }
.range strong { color: var(--ink-700); font-weight: 650; }
.alert-note { margin: -8px 0 17px; padding: 8px 10px; border-radius: 8px; color: #a33145; background: var(--danger-soft); font-size: 11px; font-weight: 650; }
.device-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid #edf2f6; color: var(--ink-500); font-size: 11px; }
.device-link { display: flex; align-items: center; gap: 5px; color: var(--brand-dark); font-size: 12px; font-weight: 700; }

.device-tools { display: flex; align-items: center; gap: 8px; }
.device-tools input, .device-tools select {
    height: 38px;
    min-height: 38px !important;
    padding: 0 11px;
    color: var(--ink-900);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-size: 12px;
}
.device-tools input { width: 210px; }
.view-switch { height: 38px; display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.view-switch button { width: 32px; border: 0; border-radius: 6px; color: var(--ink-500); background: transparent; font-size: 17px; line-height: 1; cursor: pointer; }
.view-switch button.active { color: var(--brand-dark); background: var(--brand-soft); }

.device-grid.list-view { display: grid; grid-template-columns: 1fr; gap: 8px; }
.device-row {
    min-height: 72px;
    display: grid;
    grid-template-columns: minmax(180px, 1.5fr) 110px minmax(145px, 1fr) 145px 120px 22px;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    color: inherit;
    background: #fff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--brand);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.device-row:hover { transform: translateY(-1px); border-color: #b9cbdc; box-shadow: 0 9px 24px rgba(14,42,69,.07); }
.device-row.alarm { border-left-color: var(--danger); background: #fffafb; }
.device-row.warning { border-left-color: var(--warning); background: #fffdf8; }
.device-row.offline { border-left-color: #8798aa; background: #f8fafc; }
.device-row-name strong { display: block; font-size: 14px; }
.device-row-name span, .device-row-meta { display: block; margin-top: 3px; color: var(--ink-500); font-size: 11px; }
.device-row-temp { color: var(--brand-dark); font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }
.device-row-temp.alarm { color: var(--danger); }
.device-row-temp.warning { color: var(--warning); }
.device-row-threshold { color: var(--ink-700); font-size: 11px; }
.device-row-arrow { color: var(--brand); font-size: 18px; font-weight: 700; }

.alarm-center {
    margin-bottom: 28px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #efbdc6;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(136, 35, 54, .08);
}
.alarm-center-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; color: #8f2c3e; background: var(--danger-soft); }
.alarm-center-head h2 { margin: 0; font-size: 14px; }
.alarm-list { display: grid; }
.alarm-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 18px; border-top: 1px solid #f4e1e5; }
.alarm-row:first-child { border-top: 0; }
.alarm-row strong { display: block; font-size: 13px; }
.alarm-row span { display: block; margin-top: 3px; color: var(--ink-500); font-size: 11px; }
.alarm-ack { padding: 7px 10px; flex: 0 0 auto; color: #8f2c3e; background: #fff; border: 1px solid #e8aeba; border-radius: 8px; font-size: 11px; font-weight: 700; cursor: pointer; }

.alarm-banner { color: #fff; background: #b83950; }
.alarm-inner { width: min(1180px, calc(100% - 32px)); min-height: 48px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 13px; }
.alarm-inner strong { display: flex; align-items: center; gap: 10px; }
.alarm-inner button { color: inherit; background: none; border: 0; cursor: pointer; }

.empty-panel { padding: 64px 24px; text-align: center; background: rgba(255,255,255,.75); border: 1px dashed #bfd0df; border-radius: 18px; }
.empty-icon { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 14px; color: var(--brand); background: var(--brand-soft); border-radius: 15px; }
.empty-icon svg { width: 26px; }
.empty-panel h3 { margin: 0 0 5px; font-size: 16px; }
.empty-panel p { margin: 0; color: var(--ink-500); font-size: 13px; }

.skeleton { min-height: 260px; background: linear-gradient(100deg, #f4f7f9 20%, #fff 40%, #f4f7f9 60%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fade-up .34s ease both; }

/* Existing secondary pages */
.app-shell .page-card,
.app-shell main > .bg-white,
.app-shell main .bg-white.rounded-xl { border-color: var(--line) !important; border-radius: 16px !important; box-shadow: 0 12px 34px rgba(20,47,75,.06) !important; }
.app-shell input:not([type="checkbox"]), .app-shell select {
    min-height: 42px;
    border-color: #ccd9e5 !important;
    border-radius: 9px !important;
    background-color: #fff;
}
.app-shell input:focus, .app-shell select:focus { outline: none; border-color: var(--brand) !important; box-shadow: 0 0 0 3px rgba(8,127,140,.12) !important; }
.app-shell .tab-active { color: var(--brand) !important; border-color: var(--brand) !important; }

@media (max-width: 900px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .nav-clock { display: none; }
    .device-row { grid-template-columns: minmax(150px, 1.4fr) 90px 120px 110px 22px; }
    .device-row-threshold { display: none; }
}

@media (max-width: 640px) {
    .nav-inner, .page-wrap, .alarm-inner { width: min(1180px, calc(100% - 24px)); }
    .nav-inner { min-height: 68px; }
    .brand-copy span, .connection span { display: none; }
    .connection { padding: 8px 2px; }
    .nav-actions { gap: 7px; }
    .btn { min-height: 38px; padding: 0 12px; }
    .btn .btn-label-mobile { display: none; }
    .btn-icon { display: none; }
    .page-wrap { padding-top: 28px; }
    .hero { align-items: flex-start; flex-direction: column; gap: 12px; }
    .summary-grid { gap: 10px; }
    .metric-card { min-height: 104px; padding: 15px; }
    .metric-value { font-size: 23px; }
    .device-grid { grid-template-columns: 1fr; }
    .device-card { padding: 19px; }
    .section-head { align-items: flex-start; flex-direction: column; }
    .device-tools { width: 100%; flex-wrap: wrap; }
    .device-tools input { min-width: 0; width: 100%; }
    .device-tools select { width: 100%; max-width: none; }
    .view-switch { display: none; }
    .device-grid.list-view { display: grid; }
    .device-row { grid-template-columns: 1fr auto; gap: 8px 12px; }
    .device-row-temp { grid-row: 2; }
    .device-row .state-badge { grid-column: 2; grid-row: 1; }
    .device-row-meta { grid-column: 2; grid-row: 2; text-align: right; }
    .device-row-arrow { display: none; }
    .alarm-row { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
