:root {
  color-scheme: light;
  --ink: #15251f;
  --muted: #687871;
  --border: #dce6e1;
  --surface: #ffffff;
  --canvas: #f4f8f6;
  --green: #087c68;
  --green-bright: #19a985;
  --green-soft: #e8f7f2;
  --red: #d34a4a;
  --red-soft: #fff0ef;
  --shadow: 0 8px 28px rgba(30, 61, 50, 0.07);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 0%, rgba(49, 177, 145, 0.08), transparent 24rem),
    var(--canvas);
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.auth-pending { overflow: hidden; }

button, input { font: inherit; }
button { cursor: pointer; }

.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid rgba(216, 228, 222, 0.9);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.topbar-inner { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 12px; background: #075b51; color: white; box-shadow: 0 7px 18px rgba(7, 91, 81, 0.2); }
.brand-mark svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: -0.01em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; }

.topbar-meta { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: 12px; font-weight: 600; }
.readonly-pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid #cfe4dc; border-radius: 999px; background: var(--green-soft); color: #176b5c; }
.readonly-pill svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; }
.live-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--green-bright); box-shadow: 0 0 0 4px rgba(25, 169, 133, 0.12); }
.logout-button { padding: 0; border: 0; background: transparent; color: #687871; font-size: 12px; font-weight: 600; }
.logout-button:hover { color: var(--green); }

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(63, 193, 157, 0.2), transparent 25rem),
    radial-gradient(circle at 85% 90%, rgba(16, 111, 95, 0.2), transparent 26rem),
    rgba(10, 34, 29, 0.92);
  backdrop-filter: blur(9px);
  transition: opacity 180ms ease, visibility 180ms ease;
}
.auth-overlay.is-hidden { visibility: hidden; opacity: 0; pointer-events: none; }
.login-card { width: min(100%, 410px); padding: 34px; border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 22px; background: rgba(255, 255, 255, 0.97); box-shadow: 0 28px 80px rgba(0, 20, 16, 0.3); }
.login-mark { display: grid; width: 48px; height: 48px; margin-bottom: 25px; place-items: center; border-radius: 14px; background: #075b51; color: white; box-shadow: 0 9px 22px rgba(7, 91, 81, 0.22); }
.login-mark svg { width: 27px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.login-eyebrow { margin: 0 0 8px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: 0.16em; }
.login-card h2 { margin: 0; font-size: 28px; letter-spacing: -0.035em; }
.login-copy { margin: 8px 0 25px; color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 15px; }
.login-form label > span { display: block; margin-bottom: 7px; color: #41534c; font-size: 11px; font-weight: 700; }
.login-form input { width: 100%; height: 46px; padding: 0 13px; border: 1px solid #d5e1dc; border-radius: 10px; outline: none; background: #fbfdfc; color: var(--ink); font-size: 14px; transition: border-color 150ms ease, box-shadow 150ms ease; }
.login-form input:focus { border-color: #6eb3a2; box-shadow: 0 0 0 3px rgba(8, 124, 104, 0.1); }
.login-error { margin: -3px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--red-soft); color: #ae3f3f; font-size: 11px; }
.login-submit { display: flex; height: 46px; align-items: center; justify-content: center; gap: 9px; margin-top: 3px; border: 0; border-radius: 10px; background: #075b51; color: white; font-size: 13px; font-weight: 700; box-shadow: 0 8px 20px rgba(7, 91, 81, 0.2); }
.login-submit:hover { background: #064f46; }
.login-submit:disabled { cursor: wait; opacity: 0.72; }
.login-submit svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.login-submit.is-loading svg { animation: spin 0.8s linear infinite; }
.login-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 22px 0 0; color: #809088; font-size: 10px; }
.login-note span { width: 6px; height: 6px; border-radius: 50%; background: var(--green-bright); }

.main-content { min-height: calc(100vh - 140px); padding-block: 48px 70px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 11px; font-weight: 700; letter-spacing: 0.16em; }
h1 { margin: 0; font-size: clamp(30px, 5vw, 42px); line-height: 1.1; letter-spacing: -0.045em; }
.subtitle { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.hero-actions { display: flex; align-items: center; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 8px; width: 230px; height: 42px; padding-inline: 12px; border: 1px solid var(--border); border-radius: 10px; background: white; color: #86948e; box-shadow: 0 3px 14px rgba(36, 70, 58, 0.03); }
.search-box:focus-within { border-color: #78b8a8; box-shadow: 0 0 0 3px rgba(8, 124, 104, 0.1); }
.search-box svg, .refresh-button svg { width: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; }
.refresh-button { display: inline-flex; height: 42px; align-items: center; gap: 7px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px; background: white; color: #42564e; font-size: 13px; font-weight: 600; box-shadow: 0 3px 14px rgba(36, 70, 58, 0.03); }
.refresh-button:hover { border-color: #adcbc2; background: #fbfdfc; }
.refresh-button:disabled { cursor: wait; opacity: 0.65; }
.refresh-button.is-loading svg { animation: spin 0.8s linear infinite; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 38px; }
.stat-card { display: flex; align-items: center; gap: 13px; min-height: 92px; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: rgba(255, 255, 255, 0.9); box-shadow: var(--shadow); }
.stat-icon { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 11px; }
.stat-icon svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stat-card.connected .stat-icon { color: var(--green); background: var(--green-soft); }
.stat-card.offline .stat-icon { color: var(--red); background: var(--red-soft); }
.stat-card.total .stat-icon, .stat-card.updated .stat-icon { color: #596c64; background: #eef3f0; }
.stat-card strong, .stat-card span { display: block; }
.stat-card strong { font-size: 24px; line-height: 1; letter-spacing: -0.035em; }
.stat-card.updated strong { font-size: 15px; letter-spacing: -0.01em; }
.stat-card div > span { margin-top: 6px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.055em; }

.device-groups { display: grid; gap: 34px; }
.group-header { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.group-header h2 { margin: 0; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }
.group-count { display: inline-flex; min-width: 23px; height: 20px; align-items: center; justify-content: center; padding: 0 7px; border-radius: 999px; background: #e8efeb; color: #617069; font-size: 11px; font-weight: 700; }
.device-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.device-card { position: relative; overflow: hidden; min-height: 176px; padding: 17px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 4px 18px rgba(30, 61, 50, 0.045); transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease; }
.device-card:hover { transform: translateY(-2px); border-color: #c5d9d2; box-shadow: 0 10px 26px rgba(30, 61, 50, 0.08); }
.device-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--green-bright); opacity: 0; }
.device-card.is-offline::before { background: var(--red); opacity: 0.75; }
.device-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.device-title { display: flex; min-width: 0; align-items: center; gap: 8px; }
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; border: 2px solid #8bd8c4; border-radius: 50%; background: var(--green-bright); box-shadow: 0 0 0 3px rgba(25, 169, 133, 0.1); }
.is-offline .status-dot { border-color: #f5aaaa; background: var(--red); box-shadow: 0 0 0 3px rgba(211, 74, 74, 0.08); }
.device-title h3 { overflow: hidden; margin: 0; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.os-badge { flex: 0 0 auto; padding: 4px 7px; border-radius: 6px; background: #f0f4f2; color: #687871; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.status-label { margin: 7px 0 18px 17px; color: var(--green); font-size: 11px; font-weight: 700; }
.is-offline .status-label { color: var(--red); }
.device-data { display: grid; gap: 10px; margin: 0; }
.data-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.data-row dt { color: #89958f; font-size: 11px; }
.data-row dd { overflow: hidden; margin: 0; color: #374a42; font-size: 11px; font-weight: 600; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.data-row dd.mono { font-family: "IBM Plex Mono", monospace; font-size: 10px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 15px; padding-top: 12px; border-top: 1px solid #edf2ef; }
.tag { padding: 4px 7px; border-radius: 5px; background: #edf7f3; color: #347767; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }

.state-panel { display: flex; min-height: 190px; align-items: center; justify-content: center; gap: 12px; border: 1px dashed #ccdcd5; border-radius: 14px; color: var(--muted); background: rgba(255, 255, 255, 0.5); font-size: 13px; }
.spinner { width: 20px; height: 20px; border: 2px solid #cfe1da; border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; }
.error-panel { justify-content: flex-start; min-height: auto; padding: 18px; border-style: solid; border-color: #f1cfcc; color: #9e3434; background: #fff5f4; }
.error-panel svg { width: 24px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.error-panel strong { font-size: 13px; }
.error-panel p { margin: 3px 0 0; color: #a75f5f; font-size: 12px; }

footer { border-top: 1px solid var(--border); background: rgba(255, 255, 255, 0.6); }
.footer-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #819089; font-size: 11px; }
.sr-only { position: absolute; 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; }

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

@media (max-width: 980px) {
  .stats, .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .shell { width: min(100% - 28px, 1180px); }
  .topbar-inner { height: 66px; }
  .live-indicator { display: none; }
  .login-card { padding: 27px 23px; }
  .main-content { padding-block: 34px 50px; }
  .hero { align-items: stretch; flex-direction: column; }
  .hero-actions { width: 100%; }
  .search-box { flex: 1; width: auto; }
  .stats { gap: 10px; }
  .stat-card { min-height: 80px; padding: 13px; }
  .stat-icon { width: 36px; height: 36px; }
  .device-grid { grid-template-columns: 1fr; }
  .footer-inner { align-items: flex-start; flex-direction: column; justify-content: center; gap: 5px; }
}

@media (max-width: 430px) {
  .stats { grid-template-columns: 1fr; }
  .stat-card { min-height: 72px; }
  .refresh-button { width: 42px; justify-content: center; padding: 0; }
  .refresh-button span { display: none; }
}

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