/* Machine Status · Zervician Pvt Ltd */

:root {
  --page: #f2f2f2;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --text: #191919;
  --text-2: #666666;
  --border: #e3e3e3;
  --grid: #e6e6e6;
  --reference: #666666;
  --crosshair: #9c9c9c;
  --brand: #000000;
  --brand-ink: #ffffff;
  --focus: #257de0;
  /* Categorical series (validated for colour-blind separation): vibration, temperature, humidity. */
  --s1: #257de0;
  --s2: #f47230;
  --s3: #00b894;
  /* Status: always shown with a symbol and a label. */
  --good: #0aac23;
  --warning: #fbb315;
  --critical: #dc3c3d;
  --neutral: #8a8a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 16px;
  --sidebar: 248px;
  --topbar: 56px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #0e0e0e;
  --surface: #191919;
  --surface-2: #222222;
  --text: #efefef;
  --text-2: #9c9c9c;
  --border: #2c2c2c;
  --grid: #2c2c2c;
  --reference: #9c9c9c;
  --crosshair: #666666;
  --brand: #ffffff;
  --brand-ink: #000000;
  --focus: #338ced;
  --s1: #338ced;
  --s2: #e76624;
  --s3: #00a888;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand); opacity: .88; }
.btn-danger { color: var(--critical); }
.btn-block { width: 100%; height: 44px; }
.btn-small { height: 32px; padding: 0 12px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.field { display: grid; gap: 6px; margin: 14px 0; }
.field > span { font-weight: 600; font-size: 14px; }
.field input, .field select, .input {
  height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
}
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0 14px; font-size: 14px; }
.form-error { color: var(--critical); font-size: 14px; margin: 0 0 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-size: 14px; font-weight: 500;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- sign-in */
.login {
  min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 24px; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--surface-2), var(--page));
}
.login-card {
  width: min(400px, 100%); padding: 32px; border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border);
}
.login-logo { display: block; width: 240px; max-width: 100%; height: auto; margin-bottom: 28px; }
.login-card h1 { font-size: 26px; }
.login-card > .muted { margin: 4px 0 8px; }
.login-footer { text-align: center; }

/* ---------- shell */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-top .logo-img { width: 62px; height: auto; }
.brand-name { font-weight: 700; }
.device-picker select { height: 36px; max-width: 46vw; text-overflow: ellipsis; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; }
.brand-name { white-space: nowrap; }
.conn .label-short { display: none; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.conn.ok::before { background: var(--good); }
.conn.err::before { background: var(--critical); }

.sidebar {
  position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: var(--sidebar);
  display: flex; flex-direction: column; gap: 8px; padding: 20px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .2s ease;
}
.sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
.brand-side { padding: 4px 10px 18px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.brand-side .logo-img { width: 72px; height: auto; }
.brand-text { display: grid; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--text-2); letter-spacing: .02em; }
.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: 10px; border: 0; background: none;
  text-decoration: none; font-weight: 500; color: var(--text-2); cursor: pointer; text-align: left;
}
.nav a:hover, .nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.nav-bottom { margin-top: auto; display: grid; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .35); }

.main { padding: 20px 16px 0; max-width: 1240px; margin: 0 auto; outline: none; }
#page { display: grid; gap: 16px; min-height: calc(100vh - var(--topbar) - 120px); }
.site-footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px;
  padding: 28px 0 32px; font-size: 13px;
}
.site-footer .logo-img { width: 44px; height: auto; }

@media (min-width: 960px) {
  .sidebar { transform: none; }
  .scrim { display: none !important; }
  .topbar, .main-wrap { margin-left: var(--sidebar); }
  .topbar { padding-left: 24px; }
  .menu-toggle, .brand-top { display: none; }
  .main { margin-left: calc(var(--sidebar) + max(0px, (100vw - var(--sidebar) - 1240px) / 2)); padding: 28px 32px 0; }
}

/* ---------- page layout */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 4px 0 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 10px; }
.card-head h2, .card h2 { font-size: 17px; }
.card-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.card-link { text-decoration: none; display: block; transition: border-color .15s; }
.card-link:hover { border-color: var(--text-2); }
.card-link h2::after { content: " ›"; color: var(--text-2); }
.note { font-size: 13px; color: var(--text-2); margin: 10px 0 0; }
.empty { padding: 28px; text-align: center; color: var(--text-2); }
.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--critical) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
}
.banner.info { background: var(--surface); border-color: var(--border); align-items: center; }
.banner > span:not(.spinner) { flex: 1; }
.banner .btn { flex: none; }

/* status hero */
.status-hero { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 28px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 10px; font-size: 28px; font-weight: 800; letter-spacing: .01em;
}
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--neutral); flex: none; }
.status-meta { display: grid; gap: 2px; }
.kpis { display: flex; flex-wrap: wrap; gap: 12px 32px; margin-left: auto; }
.kpi { display: grid; gap: 2px; min-width: 110px; }
.kpi-label { font-size: 13px; color: var(--text-2); }
.kpi-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-2); }
.tile .kpi-value { font-size: 28px; }

/* health badge */
.health-badge { display: flex; align-items: center; gap: 14px; }
.health-symbol {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  font-size: 24px; font-weight: 800; color: #fff; flex: none;
}
.health-symbol.watch { color: #191919; }
.health-title { font-size: 24px; font-weight: 800; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.pill b { font-weight: 800; }
.checks { display: grid; }
.check-row { padding: 12px 0; border-top: 1px solid var(--border); display: grid; gap: 2px; }
.check-row:first-child { border-top: 0; }
.check-row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }

/* live */
.axes-values { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 6px 0 10px; }
.axis-value { display: grid; }
.axis-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 600; }
.axis-num { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

/* charts */
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart canvas { display: block; width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; margin: 2px 0 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-line { width: 18px; height: 0; border-top: 2.5px solid; }
.legend-line.dashed { border-top-style: dashed; }
.legend-band { width: 18px; height: 10px; border-radius: 2px; opacity: .28; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
  font-variant-numeric: tabular-nums;
}
.tooltip-time { font-weight: 600; margin-bottom: 4px; }
.tooltip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tooltip-hint { color: var(--text-2); font-size: 12px; margin-top: 4px; }

/* history */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.filters .field { margin: 0; }
.filters .field > span { font-size: 13px; color: var(--text-2); font-weight: 600; }
.filters input[type="datetime-local"] { min-width: 210px; }
.table-wrap { overflow: auto; max-height: 480px; border: 1px solid var(--border); border-radius: 12px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inspect-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }

/* info list */
.info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.info dt { color: var(--text-2); }
.info dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }

/* dialog */
.dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 24px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog h2 { font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog small { font-size: 12px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--border); border-top-color: var(--text); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } .spinner { animation-duration: 2s; } }

@media (max-width: 600px) {
  .main { padding: 16px 12px 0; }
  .card { padding: 16px; }
  .page-head h1 { font-size: 22px; }
  .status-pill { font-size: 24px; }
  .kpis { margin-left: 0; }
  /* Phones: the page itself shows the data is loading, so hide "Server connected";
     show only a short warning when the server cannot be reached. */
  .conn.ok, .conn:not(.err) { display: none; }
  .conn .label { display: none; }
  .conn .label-short { display: inline; }
  /* Make room for the monitor picker when there is more than one monitor. */
  .topbar:has(.device-picker:not([hidden])) .brand-name { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .device-picker select { max-width: 38vw; }
}

@media print {
  .sidebar, .topbar, .scrim, .no-print { display: none !important; }
  .main { margin: 0 !important; max-width: none; }
  .card { break-inside: avoid; box-shadow: none; }
}
