/* HMI Remote — the phone shell around the shared HMI runtime.
   Landscape, no zoom: the plant screen is stretched to fill everything
   below the app bar. */

:root {
  --ma-bar: 56px;
  --ma-navy: #0b1f4b;
  --ma-navy-2: #10285e;
  --ma-navy-line: rgba(255,255,255,.08);
  --ma-ink: #0f172a;
  --ma-ink-2: #475569;
  --ma-ink-3: #64748b;
  --ma-line: #e2e8f0;
  --ma-bg: #f3f5f9;
  --ma-card: #ffffff;
  --ma-blue: #1d4ed8;
  --ma-blue-soft: rgba(29,78,216,.08);
  --ma-ok: #15803d;
  --ma-bad: #b91c1c;
  --ma-warn: #b45309;
  --ma-radius: 12px;
  --ma-shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --ma-safe-top: env(safe-area-inset-top, 0px);
  --ma-safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ma-ink: #e2e8f0;
    --ma-ink-2: #a3b1c6;
    --ma-ink-3: #8193ad;
    --ma-line: #22314a;
    --ma-bg: #0a1220;
    --ma-card: #111b2e;
    --ma-blue: #60a5fa;
    --ma-blue-soft: rgba(96,165,250,.12);
    --ma-ok: #4ade80;
    --ma-bad: #f87171;
    --ma-warn: #fbbf24;
    --ma-shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

/* no pinch, no double-tap zoom, no rubber band, no long-press callouts */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body.ma { height: 100%; overscroll-behavior: none; }
body.ma {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--ma-bg);
  color: var(--ma-ink);
  font: 15px/1.45 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
body.ma input { -webkit-user-select: text; user-select: text; }
body.ma main { flex: 1 1 auto; min-height: 0; position: relative; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ---------- app bar ---------- */
.ma-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ma-bar);
  padding: var(--ma-safe-top) 4px 0 16px;
  background: var(--ma-navy);
  color: #fff;
  border-bottom: 1px solid var(--ma-navy-line);
  position: relative;
  z-index: 20;
}
.ma-bar:has(#ma-back:not([hidden])) { padding-left: 4px; }
.ma-mark { width: 32px; height: 32px; border-radius: 8px; background: #fff; flex: 0 0 auto; }
.ma-brand { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ma-title { font-weight: 600; font-size: 16.5px; letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-sub { font-size: 11.5px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: #9fb0d4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-icon {
  appearance: none; border: 0; background: transparent; color: #fff;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  flex: 0 0 auto;
}
.ma-icon:active { background: rgba(255,255,255,.14); }
.ma-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ma-icon circle { fill: currentColor; stroke: none; }

.ma-live {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0;
  height: 26px; padding: 0 10px; border-radius: 13px;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: #dbe4f5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ma-live span { overflow: hidden; text-overflow: ellipsis; }
.ma-live i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; flex: 0 0 auto; }
.ma-live[data-kind="on"] { color: #bbf7d0; border-color: rgba(74,222,128,.35); background: rgba(22,163,74,.16); }
.ma-live[data-kind="on"] i { background: #4ade80; animation: ma-pulse 2s infinite; }
.ma-live[data-kind="bad"] { color: #fecaca; border-color: rgba(248,113,113,.4); background: rgba(220,38,38,.2); }
.ma-live[data-kind="bad"] i { background: #f87171; }
.ma-live[data-kind="wait"] { color: #fde68a; border-color: rgba(251,191,36,.35); background: rgba(217,119,6,.16); }
.ma-live[data-kind="wait"] i { background: #fbbf24; }
@keyframes ma-pulse { 0% { box-shadow: 0 0 0 0 rgba(74,222,128,.55); } 70% { box-shadow: 0 0 0 6px rgba(74,222,128,0); } 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); } }
@media (prefers-reduced-motion: reduce) { .ma-live[data-kind="on"] i { animation: none; } }

/* ---------- overflow menu ---------- */
.ma-menu {
  position: absolute; right: 8px; top: calc(var(--ma-bar) + var(--ma-safe-top) - 2px); z-index: 30;
  min-width: 240px; padding: 6px 0; border-radius: 10px;
  background: var(--ma-card); color: var(--ma-ink); border: 1px solid var(--ma-line);
  box-shadow: 0 10px 30px rgba(2,8,23,.22), 0 2px 6px rgba(2,8,23,.08);
  animation: ma-drop .14s ease-out;
}
@keyframes ma-drop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.ma-menu button {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; appearance: none; border: 0; background: transparent;
  color: inherit; font: inherit; font-size: 15px; padding: 0 18px; min-height: 48px; cursor: pointer;
}
.ma-menu button svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: var(--ma-ink-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ma-menu button:active { background: var(--ma-blue-soft); }
.ma-menu hr { border: 0; border-top: 1px solid var(--ma-line); margin: 6px 0; }
.ma-menu .is-danger { color: var(--ma-bad); }
.ma-menu .is-danger svg { stroke: var(--ma-bad); }

/* ---------- pages ---------- */
.ma-page { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px calc(24px + var(--ma-safe-bottom)); }
.ma-page > * { max-width: 480px; margin-left: auto; margin-right: auto; }

.ma-hero {
  margin: 0 -16px 0; max-width: none; padding: 28px 24px 52px; text-align: center; color: #fff;
  background: var(--ma-navy);
  background-image: radial-gradient(120% 90% at 50% 0%, #17377d 0%, rgba(11,31,75,0) 70%);
}
.ma-hero .ma-logo { display: block; margin: 0 auto 14px; width: 56px; height: 56px; border-radius: 14px; background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.ma-hero h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -.005em; }
.ma-hero p { margin: 0; font-size: 14px; color: #b7c4e2; }
.ma-hero + .ma-card { margin-top: -32px; position: relative; }

.ma-card {
  padding: 22px 20px 20px; border-radius: var(--ma-radius);
  background: var(--ma-card); border: 1px solid var(--ma-line); box-shadow: var(--ma-shadow);
}
.ma-card h1 { margin: 0 0 8px; font-size: 20px; font-weight: 600; line-height: 1.3; }
.ma-card p { color: var(--ma-ink-2); margin: 0 0 18px; }
.ma-card-title { margin: 0 0 14px; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ma-ink-3); }

.ma-steps { list-style: none; counter-reset: ma-step; margin: 0 0 22px; padding: 0; color: var(--ma-ink-2); font-size: 14.5px; }
.ma-steps li { counter-increment: ma-step; position: relative; padding: 2px 0 2px 38px; margin: 0 0 12px; }
.ma-steps li::before {
  content: counter(ma-step); position: absolute; left: 0; top: 0;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--ma-blue); background: var(--ma-blue-soft);
}
.ma-steps b { color: var(--ma-ink); font-weight: 600; }

.ma-field { display: block; margin: 0 0 16px; }
.ma-field span { display: block; font-size: 13px; font-weight: 600; color: var(--ma-ink-2); margin-bottom: 6px; }
.ma-field input {
  width: 100%; box-sizing: border-box; height: 50px; padding: 0 14px; border-radius: 8px; font: inherit; font-size: 16px;
  background: var(--ma-card); color: inherit; border: 1px solid #cbd5e1; transition: border-color .15s, box-shadow .15s;
}
@media (prefers-color-scheme: dark) { .ma-field input { border-color: #334155; background: #0d1626; } }
.ma-field input::placeholder { color: #94a3b8; }
#ma-code {
  height: 58px; font-family: "Roboto Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 24px; font-weight: 500; letter-spacing: .2em; text-align: center; text-transform: uppercase;
}
.ma-field input:focus { outline: none; border-color: var(--ma-blue); box-shadow: 0 0 0 3px var(--ma-blue-soft); }

.ma-btn {
  appearance: none; display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; padding: 0 16px; margin-top: 4px;
  border-radius: 8px; border: 1px solid var(--ma-line); background: var(--ma-card); color: var(--ma-ink);
  font: inherit; font-size: 15px; font-weight: 600; letter-spacing: .01em; cursor: pointer;
  transition: filter .12s, background .12s;
}
.ma-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.ma-btn:active { filter: brightness(.94); }
.ma-btn-primary { background: var(--ma-blue); border-color: var(--ma-blue); color: #fff; box-shadow: 0 1px 2px rgba(29,78,216,.3); }
@media (prefers-color-scheme: dark) { .ma-btn-primary { background: #2563eb; border-color: #2563eb; } }
.ma-btn-outline { background: transparent; border-color: var(--ma-line); color: var(--ma-blue); }
.ma-btn-ghost { background: transparent; border-color: transparent; color: var(--ma-blue); margin-top: 8px; }
.ma-btn:disabled { opacity: .55; }
.ma-msg { min-height: 1.4em; margin: 10px 0 0; font-size: 14px; color: var(--ma-ink-2); text-align: center; }
.ma-msg.is-error { color: var(--ma-bad); }

.ma-assure {
  display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; padding: 0 4px;
  font-size: 12.5px; line-height: 1.45; color: var(--ma-ink-3);
}
.ma-assure svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; fill: none; stroke: var(--ma-ok); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- station list ---------- */
.ma-section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 22px 4px 10px; }
.ma-h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ma-ink-3); }
.ma-count { font-size: 13px; color: var(--ma-ink-3); }
.ma-stations {
  margin-bottom: 14px; border-radius: var(--ma-radius); overflow: hidden;
  background: var(--ma-card); border: 1px solid var(--ma-line); box-shadow: var(--ma-shadow);
}
.ma-station {
  appearance: none; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; gap: 2px 14px; align-items: center;
  padding: 14px 12px 14px 16px; background: transparent; border: 0; border-top: 1px solid var(--ma-line);
}
.ma-station:first-child { border-top: 0; }
.ma-station:active { background: var(--ma-blue-soft); }
.ma-st-dot { grid-row: 1 / span 2; width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 4px rgba(148,163,184,.18); }
.ma-station[data-state="on"] .ma-st-dot { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.18); }
.ma-station[data-state="off"] .ma-st-dot { background: #ef4444; box-shadow: 0 0 0 4px rgba(239,68,68,.16); }
.ma-st-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-st-plant { grid-column: 2; color: var(--ma-ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-st-plant b { font-weight: 600; color: var(--ma-ink-2); }
.ma-station[data-state="on"] .ma-st-plant b { color: var(--ma-ok); }
.ma-station[data-state="off"] .ma-st-plant b { color: var(--ma-bad); }
.ma-st-go { grid-column: 3; grid-row: 1 / span 2; width: 20px; height: 20px; fill: none; stroke: var(--ma-ink-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- notice ---------- */
.ma-notice { margin-top: 12vh; text-align: center; padding: 30px 22px 22px; }
.ma-notice-icon {
  display: grid; place-items: center; width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--ma-blue-soft); color: var(--ma-blue);
}
.ma-notice-icon svg { display: none; width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ma-notice-icon circle[r="1"] { fill: currentColor; }
.ma-notice[data-kind="offline"] .ma-notice-icon { background: rgba(217,119,6,.12); color: var(--ma-warn); }
.ma-notice[data-kind="ended"] .ma-notice-icon { background: rgba(220,38,38,.1); color: var(--ma-bad); }
.ma-notice[data-kind="offline"] [data-icon="offline"],
.ma-notice[data-kind="ended"] [data-icon="ended"],
.ma-notice[data-kind="info"] [data-icon="info"] { display: block; }

/* ---------- the plant screens ---------- */
body.ma #hmi-root.hmi-root { flex: 1 1 auto; height: auto; min-height: 0; padding-bottom: var(--ma-safe-bottom); }
body.ma .hmi-stage { touch-action: none; }
/* the plant's own command bar becomes a slim tab strip under the app bar */
body.ma .hmi-header {
  padding: 0 4px 0 8px; gap: 8px; flex-wrap: nowrap; min-height: 44px;
  background: var(--ma-navy-2); border-bottom: 0; box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
body.ma .hmi-title,                                /* the app bar already names the station */
body.ma .hmi-pill,                                 /* and shows the link state */
body.ma .hmi-clock { display: none; }
body.ma .hmi-tabs { gap: 0; padding: 0; align-self: stretch; scrollbar-width: none; }
body.ma .hmi-tabs::-webkit-scrollbar { display: none; }
body.ma .hmi-tab {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; box-shadow: none;
  color: #a9b8d8; font-size: 12.5px; font-weight: 600; letter-spacing: .06em; padding: 0 12px; min-height: 44px;
  transform: none;
}
body.ma .hmi-tab:hover { background: transparent; box-shadow: none; transform: none; color: #fff; }
body.ma .hmi-tab.is-active { background: transparent; color: #fff; border-bottom-color: #60a5fa; box-shadow: none; }
body.ma .hmi-headright { gap: 6px; }
body.ma .hmi-alarmcount { font-size: 11px; padding: 5px 10px; letter-spacing: .05em; }

/* the device popup and alarm panel as bottom sheets */
body.ma .hmi-dialog { align-items: flex-end; }
body.ma .hmi-dialog-card { width: 100%; max-width: none; max-height: 88vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding-bottom: var(--ma-safe-bottom); }

.ma-toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(20px + var(--ma-safe-bottom)); z-index: 50;
  max-width: 480px; margin: 0 auto; padding: 14px 16px; border-radius: 8px;
  background: #1e293b; color: #f1f5f9; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: ma-rise .18s ease-out;
}
@keyframes ma-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#ma-back:not([hidden]) + .ma-mark { display: none; }

/* the alarm & event panel as a bottom sheet, clear of the app bar */
body.ma .hmi-ap { align-items: flex-end; padding: calc(var(--ma-bar) + var(--ma-safe-top) + 12px) 0 0; }
body.ma .hmi-ap-card {
  width: 100%; max-height: 100%; border-radius: 16px 16px 0 0; padding-bottom: var(--ma-safe-bottom);
  animation: ma-sheet .2s ease-out;
}
body.ma .hmi-ap-head { padding: 6px 8px 0 8px; }
body.ma .hmi-ap-tabs { overflow-x: auto; scrollbar-width: none; }
body.ma .hmi-ap-body { min-height: 30vh; }
@keyframes ma-sheet { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- QR scan (inside the app) ---------- */
.ma-btn-scan { min-height: 54px; margin: 0; background: var(--ma-blue-soft); border-color: transparent; color: var(--ma-blue); font-size: 16px; }
.ma-btn-scan svg { width: 24px; height: 24px; stroke-width: 2; }
.ma-btn-scan rect { fill: currentColor; stroke: none; }
.ma-or { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; font-size: 12.5px; color: var(--ma-ink-3); }
.ma-or::before, .ma-or::after { content: ""; flex: 1; border-top: 1px solid var(--ma-line); }

/* ---------- landscape: the app's only orientation ----------
   A phone on its side is short: a slimmer bar and the plant tabs in it, the
   pairing page in two columns, popups as centred cards. */
@media (orientation: landscape) {
  :root { --ma-bar: 48px; }
  .ma-bar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(4px, env(safe-area-inset-right, 0px)); }
  .ma-mark { width: 28px; height: 28px; border-radius: 7px; }
  .ma-brand { flex-direction: row; align-items: baseline; gap: 10px; }
  .ma-title { font-size: 16px; flex: 0 1 auto; min-width: 0; }
  .ma-sub { flex: 0 1 auto; min-width: 0; }
  .ma-page { padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }

  /* pairing: welcome on the left, the form on the right */
  #ma-pair:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); column-gap: 24px;
    align-content: start; padding-top: 20px;
  }
  #ma-pair > * { max-width: none; margin-left: 0; margin-right: 0; }
  #ma-pair .ma-hero {
    grid-column: 1; grid-row: 1; margin: 0; padding: 28px 22px; border-radius: var(--ma-radius);
    text-align: left; align-self: start;
  }
  #ma-pair .ma-hero .ma-logo { margin: 0 0 14px; }
  #ma-pair .ma-hero + .ma-card { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; }
  #ma-pair .ma-assure { grid-column: 1; grid-row: 2; margin-top: 14px; }
  .ma-steps { margin-bottom: 16px; }
  .ma-steps li { margin-bottom: 8px; }
  #ma-code { height: 52px; }

  /* station list and notices: wider, shorter */
  #ma-list > * { max-width: 760px; }
  .ma-notice { margin-top: 5vh; padding: 22px; }

  /* popups: a centred card, not a sheet stretched across a wide screen */
  body.ma .hmi-dialog { align-items: center; }
  body.ma .hmi-dialog-card { width: min(680px, calc(100% - 32px)); max-height: calc(100% - 24px); border-radius: 16px; padding-bottom: 0; }
  body.ma .hmi-ap { align-items: center; padding: calc(var(--ma-bar) + var(--ma-safe-top) + 8px) 16px 8px; }
  body.ma .hmi-ap-card { width: min(960px, 100%); border-radius: 14px; padding-bottom: 0; }
  body.ma .hmi-ap-body { min-height: 0; }

  .ma-toast { bottom: calc(14px + var(--ma-safe-bottom)); }
}

/* ---------- full screen (double tap on the plant) ---------- */
body.ma.ma-full { --ma-bar: 0px; }
body.ma.ma-full .ma-bar,
body.ma.ma-full .ma-menu,
body.ma.ma-full .hmi-header { display: none !important; }
body.ma.ma-full #hmi-root.hmi-root { padding-bottom: 0; }
