:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #04101a;
  color: #e8f3f8;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #04101a; }
button, input { font: inherit; letter-spacing: 0; }

.topbar {
  min-height: 76px;
  padding: 14px max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #244052;
  background: #071725;
}
.eyebrow { margin: 0; color: #22c7d6; font-size: 12px; font-weight: 800; }
h1 { margin: 0; font-size: 25px; }
h2 { margin: 0; font-size: 18px; }
.link-state { display: flex; gap: 8px; align-items: center; color: #a9bdc9; font-weight: 700; font-size: 13px; }
.link-state span { width: 10px; height: 10px; border-radius: 50%; background: #64748b; }
.link-state.online span { background: #22c55e; }
.link-state.stale span { background: #f59e0b; }
.link-state.offline span { background: #ef4444; }

main { width: min(1180px, 100%); margin: 0 auto; padding: 18px; }
.login-panel { width: min(420px, 100%); margin: 12vh auto 0; }
.login-panel h2 { margin-bottom: 18px; }
label { display: block; margin: 14px 0; color: #a9bdc9; font-size: 13px; font-weight: 700; }
input { width: 100%; min-height: 48px; margin-top: 6px; padding: 10px 12px; color: #eef8fb; background: #0b2030; border: 1px solid #365268; border-radius: 6px; }
button { min-height: 46px; padding: 10px 18px; border: 1px solid #22c7d6; border-radius: 6px; color: #031118; background: #22b8c7; font-weight: 800; }
.quiet { color: #dcebf2; background: #132b3b; border-color: #365268; }
.error { min-height: 22px; color: #fca5a5; }
.hidden { display: none !important; }

.dashboard { display: grid; gap: 18px; }
.status-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid #244052; }
.status-strip div { display: grid; gap: 3px; }
.status-strip span, article span { color: #8fa8b6; font-size: 12px; font-weight: 700; }
.section { padding: 4px 0 16px; border-bottom: 1px solid #244052; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.metric-grid, .instrument-grid, .alarm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
article, .alarm-item, .log-entry { border: 1px solid #29475a; border-radius: 6px; background: #091c2b; }
article { min-height: 92px; padding: 14px; display: grid; align-content: space-between; gap: 8px; }
article strong { overflow-wrap: anywhere; font-size: 19px; }
.position-card { cursor: pointer; border-color: #23758a; }
.position-card:active { background: #0d2a3b; }
.position-card small { color: #22c7d6; font-size: 11px; font-weight: 700; }
.count { min-width: 38px; padding: 5px 9px; text-align: center; border-radius: 5px; background: #173145; }
.alarm-item { min-height: 82px; padding: 13px; border-left: 4px solid #22c55e; }
.alarm-item.active { border-left-color: #ef4444; background: #29151a; }
.alarm-item strong, .alarm-item span { display: block; }
.alarm-item span { margin-top: 6px; color: #a9bdc9; font-size: 12px; }
.instrument-grid article { min-height: 110px; }
.instrument-grid small { color: #8fa8b6; }
.muted { color: #8fa8b6; }
.logbook { display: grid; gap: 8px; margin-top: 12px; }
.logbook-head, .log-entry { display: grid; grid-template-columns: minmax(120px, .9fr) 1.2fr 1.2fr 1fr 1.2fr .8fr; gap: 10px; align-items: center; }
.logbook-head { margin-top: 12px; padding: 0 13px; color: #8fa8b6; font-size: 11px; font-weight: 800; }
.log-entry { padding: 11px 13px; }
.log-entry span { color: #a9bdc9; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  main { padding: 14px; }
  .metric-grid, .instrument-grid, .alarm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-strip { grid-template-columns: 1fr 1fr; }
  .logbook-head { display: none; }
  .log-entry { grid-template-columns: 1fr 1.2fr; gap: 4px 10px; }
  .log-entry > *::before { display: block; color: #6f8b9b; font-size: 10px; font-weight: 700; }
  .log-entry > :nth-child(1)::before { content: 'Hora'; }
  .log-entry > :nth-child(2)::before { content: 'Evento'; }
  .log-entry > :nth-child(3)::before { content: 'Valor'; }
  .log-entry > :nth-child(4)::before { content: 'Umbral'; }
  .log-entry > :nth-child(5)::before { content: 'Posición'; }
  .log-entry > :nth-child(6)::before { content: 'Rol'; }
}

@media (max-width: 390px) {
  .metric-grid, .instrument-grid, .alarm-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .link-state { max-width: 145px; justify-content: flex-end; text-align: right; }
}
