.portal { padding: 34px 0 70px; }
.portal > #view { padding: 0; }
.portal h1 { margin: 0 0 6px; font-size: 28px; }
.muted { color: var(--muted); }
.portal-card { max-width: 420px; margin: 8vh auto 0; padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.type-pick { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }
.type-pick .btn { flex: 1 1 120px; }
.portal-card label { display: block; margin: 18px 0 16px; font-size: 13px; font-weight: 600; }
.portal-card input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.portal-card input:focus { outline: none; border-color: var(--accent); }
.portal-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 24px; }
.portal-head h1 { margin: 0; font-size: 28px; letter-spacing: -.8px; }
.station-line { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.portal-head .pulse { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.portal-head .pulse span + span { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 500; }
.pulse.offline { color: var(--bad, #ff5468); }
.pulse.offline i { background: var(--bad, #ff5468); animation: none; }
.pulse.idle { color: var(--muted); }
.pulse.idle i { background: var(--muted); animation: none; }
.status-pill { padding: 6px 14px; border: 1px solid var(--line); border-radius: 20px; font-size: 13px; font-weight: 700; }
.status-pill.live { border-color: #3ddc97; color: #3ddc97; }
.status-pill.offline { border-color: #ff6b6b; color: #ff6b6b; }
.readings { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.reading { padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(160deg, var(--panel-2), var(--panel)); }
.reading small { display: block; color: var(--muted); font-size: 13px; }
.reading strong { display: block; margin: 4px 0 8px; font-size: 30px; line-height: 1.1; word-break: break-word; }
.reading svg { display: block; width: 100%; height: 40px; }
.reading polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.portal { transition: max-width .3s; }
.portal.phone { width: 390px; max-width: 100%; padding-inline: 14px; border-inline: 1px solid var(--line); }
.portal.phone .readings { grid-template-columns: 1fr; }
.portal.phone .portal-head { flex-direction: column; }
.portal.phone h1 { font-size: 22px; }
.view-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.screen-frame { border: 1px solid var(--line); border-radius: 12px; background: #000; min-height: 240px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.screen-frame img { display: block; width: 100%; height: auto; }
.screen-frame img.controllable { cursor: crosshair; }
.control-bar { margin-top: 12px; }
.history-range { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 12px; }
.history-range label { display: flex; align-items: center; gap: 6px; font-size: .9rem; }
.history-range input { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: inherit; color-scheme: dark; }
.history-range .btn { padding: 6px 12px; }
.history-wrap { overflow-x: auto; }
.history-device { margin: 18px 0 8px; font-size: 1.05rem; }
.history-search { display: flex; align-items: center; gap: 12px; margin: 0 0 8px; }
.history-search input { flex: 1; max-width: 380px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: inherit; }
.history-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.history-table th, .history-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history-table td.start { color: #3ddc84; font-weight: 600; }
.history-table td.stop { color: #ff7a7a; font-weight: 600; }
.history-table td.reading { color: #5ac8fa; font-weight: 600; }
.history-table td.clickable { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.history-table td.clickable:hover { background: rgba(255, 255, 255, .06); }
.bp-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgb(0 0 0 / 72%); backdrop-filter: blur(6px); }
.bp-overlay[hidden] { display: none; }
.bp-card { box-sizing: border-box; width: min(1200px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(160deg, var(--panel-2), var(--panel)); color: #e8eef5; box-shadow: 0 20px 60px rgb(0 0 0 / 50%); }
.bp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 24px 24px 14px; }
.bp-head h3 { margin: 0 0 6px; font-size: 22px; overflow-wrap: anywhere; }
.bp-head small { color: var(--muted); font-size: 13px; }
.bp-head small::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--ok); }
.bp-head.stop small::before { background: var(--bad); }
.bp-x { flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: #e8eef5; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.bp-x:hover { border-color: var(--accent); color: var(--accent); }
.bp-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.bp-rows { min-height: 0; overflow: auto; padding: 10px 24px 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; scrollbar-color: var(--line) var(--panel); }
.bp-row { min-width: 0; padding: 16px 18px; border-radius: 9px; background: #0e1722; }
.bp-row b { display: none; }
.bp-row span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.bp-row strong { display: block; color: #e8eef5; font-size: 26px; line-height: 1.35; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .bp-head { padding: 18px 16px 12px; }
  .bp-head h3 { font-size: 18px; }
  .bp-rows { padding: 4px 16px 16px; gap: 10px; }
  .bp-row { padding: 12px; }
  .bp-row span { font-size: 12px; }
  .bp-row strong { font-size: 20px; }
}
@media (max-width: 380px) { .bp-rows { grid-template-columns: 1fr; } }
@media (min-width: 900px) {
  .bp-rows { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1100px) and (max-height: 750px) {
  .bp-rows { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .bp-row { padding: 12px 14px; }
  .bp-row strong { font-size: 22px; }
  .bp-head { padding: 16px 24px 10px; }
}
.control-bar input { flex: 1; min-width: 140px; }
.screen-frame p { padding: 20px; }
@media (max-width: 760px) {
  #phone-toggle { display: none; }
  .readings { grid-template-columns: 1fr; }
}
.screens { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.screens.controllable img { cursor: crosshair; }
.grid-bar { align-items: center; margin-bottom: 12px; }
.screen-col .screen-frame { min-height: 90px; }
@media (max-width: 600px) { .screens { grid-template-columns: 1fr !important; } }
.screen-col h3 { margin: 0 0 8px; font-size: 1rem; }
.view-tabs[role="tablist"] { justify-content: flex-end; }
.readings.grouped { display: block; }
.site-group { margin-bottom: 24px; }
.site-group h3 { margin: 0 0 10px; font-size: 1.05rem; }
.screens .screen-frame { aspect-ratio: 4 / 3; min-height: 0; }
.screens .screen-frame img { width: 100%; height: 100%; object-fit: fill; }

.screen-col h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.screen-col .expand { padding: 2px 10px; font-size: .8rem; }
.screens .screen-frame img { cursor: zoom-in; }
.screens.controllable .screen-frame img, .full-view.controllable img { cursor: crosshair; }
.tap-dot { position: fixed; width: 22px; height: 22px; margin: -11px 0 0 -11px; border: 3px solid #fff; border-radius: 50%; background: rgba(255,80,80,.6); pointer-events: none; z-index: 1100; animation: tapfade .6s forwards; }
@keyframes tapfade { to { opacity: 0; transform: scale(2); } }
.full-view { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; flex-direction: column; }
.full-view[hidden] { display: none; }
.full-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; color: #fff; }
.full-view img { flex: 1; min-height: 0; width: 100%; object-fit: fill; }

.gas-panel { box-sizing: border-box; container-type: inline-size; width: 100%; min-width: 220px; aspect-ratio: 3 / 4; min-height: 400px; overflow: auto; padding: 14px; border: 1px solid #cfd8e3; border-radius: 12px; background: #fff; display: flex; flex-direction: column; gap: 1.6cqw; }
.gas-panel h3 { margin: 0 0 6px; font-size: clamp(.9rem, 5cqw, 1.5rem); color: #0b6fb8; }
.gas-row { flex: 1; min-height: 0; display: grid; grid-template-columns: 9cqw minmax(0, 1fr) 6cqw minmax(0, 1fr); align-items: stretch; gap: 0; font-size: clamp(.7rem, 3.6cqw, 1.2rem); }
.gas-row > * { display: flex; align-items: center; min-width: 0; color: #fff; }
.gas-num { justify-content: center; background: #0b5f9e; font-weight: 700; }
.gas-row span { background: linear-gradient(#1aa0e0, #0b84c6); padding: 0 2cqw; line-height: 1.15; }
.gas-arrow { justify-content: center; background: none; color: #9aa3ad; }
.gas-arrow::before { content: ""; width: 0; height: 0; border-top: 1.8cqw solid transparent; border-bottom: 1.8cqw solid transparent; border-left: 3.2cqw solid #b9bec5; }
.gas-row strong { justify-content: flex-end; text-align: right; word-break: break-word; background: linear-gradient(#ff8a2a, #f06a0c); padding: 0 2cqw; }
#readings:has(.gas-panel) { display: grid; gap: 16px; align-items: start; }
@media (max-width: 600px) { #readings:has(.gas-panel) { grid-template-columns: 1fr !important; } }
.company-info { margin: 4px 0 0; font-size: 13px; font-weight: 600; color: var(--accent, #22d3ee); }

/* History: device tabs, toolbar, summary, pager */
.hist-devs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.hist-dev { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
.hist-dev em { font-style: normal; font-size: .78rem; padding: 1px 8px; border-radius: 999px; background: rgb(255 255 255 / 10%); }
.hist-dev.active { background: var(--accent); border-color: var(--accent); color: #04222b; }
.hist-dev.active em { background: rgb(0 0 0 / 18%); }
.hist-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.hist-toolbar input { flex: 1 1 260px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: inherit; }
.hist-toolbar select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel, #121b26); color: inherit; }
.hist-toolbar .btn { padding: 8px 14px; }
.hist-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 0 0 8px; }
.hist-card { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel, #121b26); }
.hist-card small { display: block; color: var(--muted, #8fa3b8); font-size: .78rem; }
.hist-card strong { font-size: 1.1rem; }
.hist-card.start strong { color: #3ddc84; }
.hist-card.stop strong { color: #ff9a4a; }
.history-table tbody tr { cursor: pointer; }
.history-table tbody tr:hover { background: rgba(255, 255, 255, .05); }
.history-table th { position: sticky; top: 0; background: var(--panel, #121b26); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #8fa3b8); }
.hist-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 14px 0 0; }
.hist-pager .btn { padding: 6px 12px; }
.hist-pager .btn:disabled { opacity: .4; cursor: default; }
@media (max-width: 600px) {
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td { display: block; width: 100%; }
  .history-table tr { margin: 0 0 10px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
  .history-table td { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border: 0; white-space: normal; text-align: right; }
  .history-table td::before { content: attr(data-label); color: var(--muted, #8fa3b8); text-align: left; }
  .hist-toolbar select, .hist-toolbar .btn { flex: 1 1 45%; }
}
html.phone-view .history-table thead { display: none; }
html.phone-view .history-table, html.phone-view .history-table tbody, html.phone-view .history-table tr, html.phone-view .history-table td { display: block; width: 100%; }
html.phone-view .history-table tr, .portal.phone .history-table tr { margin: 0 0 10px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.portal.phone .history-table thead { display: none; }
.portal.phone .history-table, .portal.phone .history-table tbody, .portal.phone .history-table tr, .portal.phone .history-table td { display: block; width: 100%; }
.portal.phone .history-table td, html.phone-view .history-table td { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border: 0; white-space: normal; text-align: right; }
.portal.phone .history-table td::before, html.phone-view .history-table td::before { content: attr(data-label); color: var(--muted, #8fa3b8); text-align: left; }

/* Data View device cards (same look as the dashboard machine cards) */
.machine { padding: 24px; min-width: 0; }
.machine.offline { opacity: .8; }
.machine-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.machine-head h3 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.machine-head small { color: var(--muted); }
.badge { padding: 4px 12px; font-size: 12px; }
.badge.alarm { background: rgb(255 84 104 / 16%); color: var(--bad); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { padding: 14px 16px; min-width: 0; }
.metric small { display: block; color: var(--muted); font-size: 13px; }
.metric b { font-size: 28px; font-variant-numeric: tabular-nums; word-break: break-word; }
.metric b span { color: var(--muted); font-size: 13px; font-weight: 500; }
.spark { display: block; width: 100%; height: 46px; margin-top: 12px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-label { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 0 0 14px; }
.kpis[hidden] { display: none; }
.kpi { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.kpi small { color: var(--muted); font-size: 14px; }
.kpi strong { display: block; margin-top: 2px; font-size: 34px; font-variant-numeric: tabular-nums; }
.kpi.alert strong { color: var(--bad); }
.kpi.ok strong { color: var(--good, #1a9b4b); }
.kpi em { display: block; margin-top: 2px; font-size: 12px; font-style: normal; color: var(--muted); }
.kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.group-title { margin: 26px 0 14px; font-size: 18px; }
.metric b span { white-space: nowrap; }

@media (max-width: 700px) { .kpis { grid-template-columns: 1fr 1fr; } .kpi strong { font-size: 22px; } .kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; } .kpis-3 .kpi { padding: 12px 10px; } .kpis-3 .kpi em { font-size: 11px; } }
.portal.phone .kpis { grid-template-columns: 1fr 1fr; }
.portal.phone .kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.portal.phone .metrics { grid-template-columns: 1fr 1fr; }

.portal.phone #readings { grid-template-columns: 1fr !important; }
@media (max-width: 700px) {
  #readings { grid-template-columns: 1fr !important; }
  .machine { padding: 18px; }
  .metric { padding: 12px; }
  .metric b { font-size: 24px; }
}
