:root {
  --brand: #3b9fbd;
  --brand-dark: #176e87;
  --brand-soft: #e3f0f4;
  --ink: #11181d;
  --muted: #5f6970;
  --line: #cbd2d6;
  --surface: #ffffff;
  --canvas: #e9edef;
  --running: #188a5a;
  --standby: #87939c;
  --error: #c84040;
  --shadow: 0 8px 22px rgba(22, 32, 38, .08);
  --font-display: "Bahnschrift", "Arial Narrow", Arial, sans-serif;
  --font-body: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255,255,255,.65), transparent 38%),
    var(--canvas);
  font-family: var(--font-body);
  min-height: 100vh;
}

.topbar {
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: #12242d;
  border-bottom: 4px solid var(--brand);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: var(--brand);
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand strong,
.brand small { display: block; }
.brand strong { font-family: var(--font-display); font-size: 1.18rem; letter-spacing: .03em; }
.brand small { color: #aebbc1; font-size: .72rem; margin-top: 1px; }

.environment {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c8d1d5;
  font-size: .8rem;
}

.environment span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(59, 159, 189, .17);
}

.shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

.breadcrumb {
  display: flex;
  gap: 9px;
  color: var(--muted);
  font-size: .78rem;
  margin-bottom: 18px;
}

.machine-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  font-family: var(--font-display);
  line-height: 1;
}

h1 { font-size: clamp(2.1rem, 5vw, 3.2rem); }
h2 { font-size: 1.5rem; }

.status-pill {
  --status-color: var(--standby);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 126px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--status-color) 38%, white);
  background: color-mix(in srgb, var(--status-color) 9%, white);
  color: var(--status-color);
  font-weight: 700;
  font-size: .85rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-color);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.kpi-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.kpi-card {
  position: relative;
  min-height: 142px;
  padding: 22px;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--brand);
}

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin: 18px 0 5px;
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1;
}

.kpi-card small { color: var(--muted); }

.panel { padding: 24px; }

.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.period-label {
  padding: 7px 10px;
  color: var(--muted);
  background: #f1f4f5;
  border: 1px solid #d8dfe2;
  font-size: .75rem;
  font-weight: 700;
}

.trend-wrap {
  position: relative;
  min-height: 320px;
  background: #f8fafb;
  border: 1px solid #dce2e5;
  overflow: hidden;
}

#status-trend {
  display: block;
  width: 100%;
  min-height: 320px;
  font-family: var(--font-body);
  touch-action: none;
}

.trend-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 126px;
  padding: 9px 11px;
  color: white;
  background: rgba(17, 24, 29, .94);
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
  pointer-events: none;
  transform: translate(12px, -50%);
}

.trend-tooltip strong,
.trend-tooltip span { display: block; }
.trend-tooltip strong { font-size: .82rem; }
.trend-tooltip span { color: #bdc9ce; font-size: .72rem; margin-top: 2px; }

.trend-note {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: .76rem;
}

.period-controls { display:flex; flex-wrap:wrap; align-items:center; gap:8px; justify-content:flex-end; font-size:.85rem; }
.period-controls select,.period-controls input,.period-controls button { font:inherit; border:1px solid #a6b4bc; border-radius:3px; padding:8px; background:white; color:var(--ink); }
.period-controls button { background:var(--brand-dark); color:white; cursor:pointer; }
.custom-period { display:flex; flex-wrap:wrap; gap:10px; align-items:end; }
.custom-period label { display:grid; gap:4px; }
[hidden] { display:none !important; }
#history-summary { margin:0 0 12px; line-height:1.6; }
.trend-tooltip { max-width:290px; }
.trend-tooltip span { white-space:normal; }

.error-message {
  padding: 20px;
  color: var(--error);
  background: #fff0f0;
  border: 1px solid #eccaca;
}

.account-nav { display:flex; align-items:center; gap:22px; font-size:.88rem; }
.account-nav small { display:block; color:#aebbc1; font-size:.72rem; margin-top:3px; }
.logout-button { background:transparent; border:1px solid #657780; color:white; padding:9px 12px; cursor:pointer; font:inherit; }
.logout-button:hover { background:#29414d; }
.login-shell { width:min(460px, calc(100% - 32px)); margin:clamp(32px,8vh,90px) auto; }
.login-panel { padding:36px; border-top:4px solid var(--brand); }
.login-panel h1 { font-size:2rem; line-height:1.2; }
.login-intro,.intro { color:var(--muted); line-height:1.6; }
.login-panel label { display:block; font-size:.85rem; font-weight:600; margin:20px 0 8px; }
.login-panel input:not([type=hidden]) { width:100%; border:1px solid #a6b4bc; padding:12px; font:inherit; border-radius:3px; }
.login-panel small { display:block; color:var(--muted); margin-top:7px; }
.primary-button { display:flex; justify-content:space-between; width:100%; margin-top:26px; padding:14px 16px; background:var(--brand-dark); color:white; border:0; border-radius:3px; font:inherit; font-weight:600; cursor:pointer; }
.primary-button:hover { background:#12576b; }
a:focus-visible,button:focus-visible,input:focus-visible { outline:3px solid var(--brand); outline-offset:3px; }
.login-footer { text-align:center; color:var(--muted); font-size:.78rem; }
.machine-list { display:grid; grid-template-columns:repeat(auto-fit,minmax(270px,370px)); gap:20px; }
.machine-tile { display:block; border:1px solid var(--line); border-top:4px solid var(--brand); background:white; color:var(--ink); text-decoration:none; padding:24px; box-shadow:var(--shadow); }
.machine-tile:hover { border-color:var(--brand-dark); box-shadow:0 8px 24px #176e871f; }
.tile-heading { display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:28px; }
.connection-badge { color:var(--muted); background:#eef1f3; padding:6px 10px; font-size:.78rem; }
.connection-badge.online { color:#116943; background:#e3f4eb; }
.tile-status { color:var(--muted); font-size:.88rem; }
.tile-received { font-size:.8rem; color:var(--muted); margin-top:28px; line-height:1.8; }
.tile-received strong { color:var(--ink); font-weight:500; }
.tile-footer { display:flex; justify-content:space-between; margin-top:24px; padding-top:18px; border-top:1px solid var(--line); color:var(--brand-dark); font-weight:600; font-size:.87rem; }
.back-link { display:inline-block; margin-bottom:20px; color:var(--brand-dark); text-decoration:none; font-size:.9rem; }

@media (max-width: 720px) {
  .login-panel { padding:24px; }
  .account-nav { gap:12px; }
  .topbar { padding: 0 18px; }
  .environment { display: none; }
  .shell { width: min(100% - 28px, 1180px); padding-top: 22px; }
  .machine-heading { align-items: flex-start; flex-direction: column; gap: 14px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card { min-height: 122px; }
  .panel { padding: 16px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .trend-wrap, #status-trend { min-height: 300px; }
}
