/* Device lookup (devices.html) */
[hidden] { display: none !important; }
code { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 14px; }

.dash-hero { background: var(--navy); color: #c5cdd8; padding: 56px 0 96px; }
.dash-hero .eyebrow { color: #5fb0ff; }
.dash-hero h1 { color: #fff; font-size: clamp(28px, 3.4vw, 42px); margin: 10px 0 12px; }
.dash-hero p { max-width: 620px; font-size: 17px; }

.dash { padding: 0 0 96px; background: var(--bg-soft); min-height: 50vh; display: flow-root; }

/* Device details (devices.html) */
.detail-hero { padding: 36px 0 44px; }
.detail-hero h1 { margin-top: 14px; }
.back-link { display: inline-block; color: #9fb0c6; font-size: 14px; font-weight: 600; }
.back-link:hover { color: #fff; }
.notice {
  margin-top: 32px; background: #fff; border: 1px solid var(--line); border-left: 4px solid #f5a524;
  border-radius: var(--radius); padding: 20px 24px; font-size: 16px; color: var(--ink);
}
.form-error { background: #fdecec; color: #b42318; border-radius: 8px; padding: 12px 16px; font-size: 15px; margin-top: 16px; }

.loading { display: flex; justify-content: center; padding: 64px 0; }
.loading span { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.demo-box { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--line); }
.demo-box > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.demo-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--ink); transition: all .2s;
}
.chip-btn:hover { border-color: var(--blue); color: var(--blue); background: #fff; }
.demo-badge {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 4px; vertical-align: 1px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: #fff4e5; color: #b45309;
}

/* Result */
.result { margin-top: 32px; animation: rise .5s ease both; }
.result-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; margin-bottom: 20px;
}
.result-head h2 { font-size: 26px; margin: 2px 0 4px; }
.result-head code { color: var(--muted); letter-spacing: .04em; }

.status {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px;
  background: var(--bg-soft); color: var(--ink); font-size: 14px; font-weight: 600;
}
.status i { width: 9px; height: 9px; border-radius: 50%; background: #8792a2; }
.status[data-state="connected"] { background: #e8f8ee; color: #15803d; }
.status[data-state="connected"] i { background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .2); }
.status[data-state="offline"] { background: #fdecec; color: #b42318; }
.status[data-state="offline"] i { background: #ef4444; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 20px; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.metric > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.metric strong { display: flex; align-items: center; gap: 8px; font-size: 26px; color: var(--ink); line-height: 1.2; }
.metric small { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.metric-main { background: var(--navy); border-color: var(--navy); }
.metric-main > span { color: #9fb0c6; }
.metric-main strong { font-size: 44px; color: #fff; }
.metric-main { grid-column: span 2; }
.metric-main.is-location strong { font-size: 28px; }
.metric strong .unit { font-size: .55em; font-weight: 600; color: var(--muted); }
.metric-main strong .unit { color: #9fb0c6; }
.metric-main .raw-value { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 22px; word-break: break-all; }
.metric-error { grid-column: 1 / -1; background: #fdecec; border-color: #f3b5b0; }
.metric-error > span, .metric-error small { color: #b42318; }
.map-link { font-size: 14px; font-weight: 600; color: #5fb0ff; margin-left: 6px; white-space: nowrap; }
.metric:not(.metric-main) .map-link { color: var(--blue); }
.metric strong { flex-wrap: wrap; }

.signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 18px; }
.signal i { width: 5px; background: var(--line); border-radius: 1px; }
.signal i:nth-child(1) { height: 25%; } .signal i:nth-child(2) { height: 50%; }
.signal i:nth-child(3) { height: 75%; } .signal i:nth-child(4) { height: 100%; }
.signal[data-level="1"] i:nth-child(-n+1) { background: #ef4444; }
.signal[data-level="2"] i:nth-child(-n+2) { background: #f5a524; }
.signal[data-level="3"] i:nth-child(-n+3) { background: #22c55e; }
.signal[data-level="4"] i { background: #22c55e; }

.chart-card, .history { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; margin-bottom: 20px; }
.chart-card h3, .history h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 14px; }
.chart { width: 100%; height: auto; display: block; color: var(--blue); }
.chart .line { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: #fff; stroke: currentColor; stroke-width: 2.5; }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 4; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .grid.day { stroke: #c8d2df; stroke-dasharray: none; }
.chart .axis.day { fill: var(--ink); font-weight: 600; }
.chart .pt { fill: currentColor; }
.chart .hit { fill: transparent; cursor: crosshair; touch-action: pan-y; }
.chart .cursor { stroke: var(--ink); stroke-opacity: .35; stroke-dasharray: 3 3; }
.chart-box { position: relative; }
.chart-tip {
  position: absolute; z-index: 2; transform: translate(-50%, calc(-100% - 12px)); pointer-events: none; white-space: nowrap;
  background: var(--navy); color: #c5cdd8; font-size: 12px; padding: 6px 10px; border-radius: 6px; box-shadow: var(--shadow);
}
.chart-tip strong { display: block; color: #fff; font-size: 15px; }
.chart-empty { color: var(--muted); font-size: 15px; padding: 24px 0; text-align: center; }

/* Chart period and Excel download */
.range-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.range-tabs { display: inline-flex; gap: 2px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 999px; }
.range-tabs button {
  border: 0; background: none; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 7px 16px; border-radius: 999px; cursor: pointer; transition: background .2s, color .2s;
}
.range-tabs button:hover:not(.active) { color: var(--ink); }
.range-tabs button.active { background: var(--blue); color: #fff; }
.export-btn { background: #fff; }
.export-btn::before { content: "⤓"; font-size: 16px; line-height: 1; }
.export-btn[disabled] { opacity: .6; cursor: progress; }
.range-note { font-size: 13px; color: var(--muted); margin-bottom: 14px; min-height: 1.6em; }
.range-note.is-error { color: #b42318; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--ink); }
tbody tr:last-child td { border-bottom: 0; }
.btn-sm { padding: 8px 18px; font-size: 14px; }
.more-btn { display: flex; margin: 16px auto 0; background: #fff; }

.updated { font-size: 13px; color: var(--muted); text-align: right; }
.updated.is-error { color: #b42318; }

@media (max-width: 600px) {
  .result-head, .chart-card, .history { padding: 20px 16px; }
  .range-tabs { width: 100%; }
  .range-tabs button { flex: 1; padding: 7px 6px; }
  .export-btn { width: 100%; justify-content: center; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 12px; }
  .metric { padding: 16px; }
  .metric strong { font-size: 20px; }
  .metric-main { grid-column: 1 / -1; }
  .metric-main strong { font-size: 36px; }
}

/* ---------------------------------------------------------------- shared form bits */
.mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; letter-spacing: .04em; }
.field { display: block; margin-bottom: 18px; flex: 1; min-width: 0; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 15px; color: var(--ink); background: #fff; transition: border-color .2s, box-shadow .2s;
}
.field input.mono { text-transform: uppercase; }
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.field small { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.field-row { display: flex; gap: 16px; }
.btn-ghost-dark { background: transparent; border-color: rgba(255, 255, 255, .35); color: #fff; }
.btn-ghost-dark:hover { background: #fff; color: var(--ink); }
.btn:disabled { opacity: .6; cursor: wait; transform: none; }
.status[data-state="none"] { background: var(--bg-soft); color: var(--muted); }

/* ---------------------------------------------------------------- sign in (login.html) */
.auth-page { background: var(--bg-soft); padding: 72px 0 96px; }
.auth-grid { display: grid; grid-template-columns: 1fr 460px; gap: 64px; align-items: center; }
.auth-intro h1 { font-size: clamp(30px, 3.6vw, 44px); margin: 12px 0 24px; }
.auth-intro .check-list li { font-size: 17px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-soft); border-radius: 999px; padding: 4px; margin-bottom: 26px; }
.auth-tabs button {
  border: 0; background: none; font: inherit; font-weight: 600; font-size: 15px; color: var(--muted);
  padding: 10px; border-radius: 999px; cursor: pointer; transition: background .2s, color .2s;
}
.auth-tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(15, 27, 45, .1); }
#auth-form[data-mode="login"] .only-register,
#auth-form[data-mode="register"] .only-login { display: none; }
#auth-form .btn { width: 100%; justify-content: center; margin-top: 4px; }
#auth-form .form-error { margin: 0 0 16px; }

/* ---------------------------------------------------------------- my dashboard */
.board-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.board-head p { font-size: 15px; color: #9fb0c6; }
.board-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.summary { position: relative; z-index: 2; margin-top: -48px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.sum-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 24px; border-top: 3px solid var(--blue); }
.sum-card strong { display: block; font-size: 32px; color: var(--ink); line-height: 1.1; }
.sum-card span { font-size: 14px; color: var(--muted); font-weight: 500; }
.sum-ok { border-top-color: #22c55e; }
.sum-bad { border-top-color: #ef4444; }
.sum-muted { border-top-color: #b7bfca; }
#board-error { margin: 0 0 20px; }

.add-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; margin-bottom: 24px; animation: rise .3s ease both; }
.add-card h2 { font-size: 20px; margin-bottom: 18px; }
.add-card .form-error { margin: 0 0 16px; }

/* Sharing (dashboard.html) */
.share-card { position: relative; }
.share-text { font-size: 15px; color: var(--muted); max-width: 680px; margin: -8px 0 18px; }
.share-link { display: flex; gap: 8px; }
.share-link input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg-soft);
}
.share-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.share-stop { color: #b42318; border-color: #f3b5b0; }
.share-stop:hover { background: #fdecec; color: #b42318; }
.share-note { font-size: 13px; color: var(--muted); margin-top: 12px; }
.share-card .form-error { margin: 16px 0 0; }
.share-close { position: absolute; top: 20px; right: 20px; }
.shared-banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 24px; padding: 12px 18px; border-radius: var(--radius);
  background: var(--blue-soft); color: var(--blue-dark); font-size: 15px; font-weight: 600;
}
.shared-banner::before { content: "👁"; }
.add-buttons { display: flex; gap: 12px; }

.empty-state { text-align: center; background: #fff; border: 2px dashed var(--line); border-radius: var(--radius); padding: 64px 24px; }
.empty-state h2 { font-size: 22px; margin-bottom: 8px; }
.empty-state p { color: var(--muted); margin-bottom: 24px; }

.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }

/* Devices on the left, alarms on the right */
.board-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.board-layout:has(.alarm-panel[hidden]) { grid-template-columns: minmax(0, 1fr); }
.alarm-panel {
  position: sticky; top: 96px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 18px 8px; max-height: calc(100vh - 120px); overflow: auto;
}
.alarm-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.alarm-head h2 { font-size: 17px; }
.alarm-count { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; }
.alarm-empty { color: var(--muted); font-size: 14px; padding: 8px 0 14px; }
.alarm-empty::before { content: "✓ "; color: #22c55e; font-weight: 700; }
.alarm-list { display: grid; gap: 6px; }
.alarm-item > a, .alarm-item:not(:has(> a)) {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 10px; border-radius: 8px; color: inherit;
}
.alarm-item > a:hover { background: var(--bg-soft); }
.alarm-item.is-active > a, .alarm-item.is-active:not(:has(> a)) { background: #fdf2f2; }
.alarm-item.is-active[data-level="offline"] > a, .alarm-item.is-active[data-level="offline"]:not(:has(> a)),
.alarm-item.is-active[data-level="low"] > a, .alarm-item.is-active[data-level="low"]:not(:has(> a)) { background: var(--bg-soft); }
.alarm-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: #94a3b8; }
.alarm-item[data-level="critical"] .alarm-dot { background: #dc2626; }
.alarm-item[data-level="high"] .alarm-dot { background: #f97316; }
.alarm-item[data-level="medium"] .alarm-dot { background: #eab308; }
.alarm-item[data-level="offline"] .alarm-dot { background: #64748b; }
.alarm-item.is-active[data-level="critical"] .alarm-dot { box-shadow: 0 0 0 4px rgba(220, 38, 38, .2); animation: alarm-blink 1.2s ease-in-out infinite; }
@keyframes alarm-blink { 50% { box-shadow: 0 0 0 7px rgba(220, 38, 38, .08); } }
.alarm-item strong { display: block; font-size: 14px; color: var(--ink); line-height: 1.35; }
.alarm-device { display: block; font-size: 13px; color: var(--ink); opacity: .8; }
.alarm-when { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.alarm-when b { color: #b42318; }
.device-alarms .alarm-list { max-width: 720px; }
.dev-card.has-alarm { border-left-color: #dc2626; box-shadow: 0 0 0 2px rgba(220, 38, 38, .25); }
.dev-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px;
  display: flex; flex-direction: column; gap: 16px; transition: box-shadow .2s;
  border-left: 4px solid #22c55e;
}
.dev-card:hover { box-shadow: var(--shadow); }
.dev-card[data-state="offline"] { border-left-color: #ef4444; }
.dev-card[data-state="noData"] { border-left-color: #b7bfca; }
.dev-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dev-head h3 { font-size: 19px; margin: 2px 0; word-break: break-word; }
.dev-head code { color: var(--muted); font-size: 12px; }
.dev-head .status { flex-shrink: 0; font-size: 12px; padding: 5px 11px; }
.dev-head .demo-badge { margin-left: 4px; }
.dev-primary span { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.dev-primary strong { font-size: 34px; color: var(--ink); line-height: 1.15; word-break: break-word; }
.dev-primary.is-location strong { font-size: 20px; }
.dev-primary .unit { font-size: .5em; color: var(--muted); }
.dev-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dev-fields div { background: var(--bg-soft); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.dev-fields dt { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-fields dd { font-size: 14px; font-weight: 600; color: var(--ink); }
.dev-fields .unit { font-size: 11px; color: var(--muted); }
.dev-meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.dev-meta .signal { height: 13px; vertical-align: -1px; }
.dev-meta .signal i { width: 4px; }
.dev-waiting { font-size: 14px; color: var(--muted); background: var(--bg-soft); border-radius: 8px; padding: 14px; }
.dev-actions { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 14px; margin-top: auto; }
.text-btn { border: 0; background: none; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.text-btn:hover { color: var(--ink); background: var(--bg-soft); }
.text-btn.danger:hover { color: #b42318; background: #fdecec; }
#updated { margin-top: 16px; }

@media (max-width: 960px) {
  .auth-grid { grid-template-columns: 1fr; gap: 32px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .auth-page { padding: 40px 0 64px; }
  .auth-card, .add-card { padding: 22px 18px; }
  .share-link { flex-direction: column; }
  .share-close { top: 14px; right: 12px; }
  .field-row { flex-direction: column; gap: 0; }
  .summary { gap: 10px; }
  .sum-card { padding: 14px 16px; }
  .sum-card strong { font-size: 26px; }
  .dev-grid { grid-template-columns: 1fr; }
  .board-actions .btn { flex: 1; justify-content: center; }
}

/* Alarm panel: below 1100px it moves above the devices, so an active alarm is seen first */
@media (max-width: 1100px) {
  .board-layout { grid-template-columns: minmax(0, 1fr); }
  .alarm-panel { position: static; order: -1; max-height: 340px; }
}

/* Device control (devices.html, js/control.js) */
.control-card .cmd-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.control-card .cmd-row:last-child { border-bottom: 0; }
.cmd-text strong { font-size: 15px; color: var(--ink); }
.cmd-text small { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; max-width: 520px; }
.cmd-state { display: inline-block; margin-left: 8px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--bg-soft); color: var(--muted); }
.cmd-state.is-on { background: #e8f8ee; color: #15803d; }
.cmd-controls { display: flex; align-items: center; gap: 8px; flex: none; }
.cmd-controls select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 14px; background: #fff; color: var(--ink); }
.cmd-controls input[type="range"] { width: 120px; accent-color: var(--blue); }
.cmd-controls output { min-width: 22px; font-weight: 700; color: var(--ink); }
.cmd-danger { color: #b42318; border-color: #f3b5b0; }
.cmd-danger:hover { background: #fdecec; color: #b42318; }
.control-card.is-off .cmd-controls { opacity: .45; pointer-events: none; }
.cmd-note { margin: 0 0 12px; padding: 10px 14px; border-radius: 8px; font-size: 14px; background: var(--bg-soft); color: var(--ink); }
.cmd-note.is-ok { background: #e8f8ee; color: #15803d; }
.cmd-note.is-error { background: #fdecec; color: #b42318; }
.cmd-advanced { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.cmd-advanced summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.control-card h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.cmd-history { display: grid; gap: 4px; }
.cmd-history li { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.cmd-history li:last-child { border-bottom: 0; }
.cmd-history strong { color: var(--ink); font-weight: 600; }
.cmd-history small { grid-column: 2; color: var(--muted); font-size: 12px; }
.cmd-pill { grid-row: span 2; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #fff4e5; color: #b45309; }
.cmd-pill[data-status="ok"] { background: #e8f8ee; color: #15803d; }
.cmd-pill[data-status="error"], .cmd-pill[data-status="failed"] { background: #fdecec; color: #b42318; }
.cmd-pill[data-status="no_answer"] { background: var(--bg-soft); color: var(--muted); }
@media (max-width: 600px) {
  .control-card .cmd-row { flex-direction: column; align-items: stretch; }
  .cmd-controls { flex-wrap: wrap; }
}
