:root {
  /* theme: everything except the status colours below changes with data-theme */
  --bg: #07111f;
  --bg2: #0b1a2e;
  --panel: #0f2139;
  --panel2: #132a47;
  --panel-end: #0c1c32;
  --line: #1f3d63;
  --row-line: #17324f;
  --text: #e6eefb;
  --muted: #8ea6c6;
  --accent: #38bdf8;
  --topbar-a: #0a1a30;
  --topbar-b: #0d2340;
  --input: #081627;
  --th: #0b1b30;
  --card: #0b1a2d;
  --pill: #0a1628;
  --primary: #0369a1;
  --primary-border: #0ea5e9;
  --primary-text: #ffffff;
  --footer: #4d6585;
  --floor: #0c1d33;
  --floor-line: #1b3656;
  --floor-target: #12365c;
  --warn-text: #fdba74;
  --info-text: #bae6fd;
  --comm-bg: #1c1a17;
  /* status colours: the same in every theme */
  --green: #16a34a;
  --green-hi: #22c55e;
  --yellow: #eab308;
  --yellow-hi: #facc15;
  --red: #dc2626;
  --red-hi: #ef4444;
  --gray: #6b7280;
  --gray-hi: #9ca3af;
  --nodata: #334155;
  --warn: #f97316;
  --radius: 10px;
  font-family: "Segoe UI", "Leelawadee UI", Tahoma, sans-serif;
}

/* ---- colour themes (settings → dashboard → theme) ---------------------- */
:root[data-theme="graphite"] {
  --bg: #0b0c0e; --bg2: #16181c; --panel: #1b1e23; --panel2: #252930; --panel-end: #16191d;
  --line: #343a42; --row-line: #2a2f36; --text: #eceef1; --muted: #9ba3ae; --accent: #22d3ee;
  --topbar-a: #121417; --topbar-b: #1b1e23; --input: #111316; --th: #171a1e; --card: #15181c;
  --pill: #121417; --primary: #0e7490; --primary-border: #22d3ee; --footer: #5f6873;
  --floor: #17191d; --floor-line: #2b3037; --floor-target: #1f3a42;
}
:root[data-theme="gold"] {
  --bg: #0d0b07; --bg2: #1a160d; --panel: #1d1911; --panel2: #29231a; --panel-end: #17140d;
  --line: #4a3f25; --row-line: #352d1b; --text: #f6f1e7; --muted: #bcae90; --accent: #e0b84a;
  --topbar-a: #15120b; --topbar-b: #231d11; --input: #120f09; --th: #1a160e; --card: #16130c;
  --pill: #120f09; --primary: #8a6a14; --primary-border: #e0b84a; --footer: #7a6c4e;
  --floor: #17140d; --floor-line: #34301f; --floor-target: #3a2f12;
}
:root[data-theme="teal"] {
  --bg: #03151a; --bg2: #062329; --panel: #0a2a31; --panel2: #0f3740; --panel-end: #072229;
  --line: #1c5560; --row-line: #164550; --text: #e2f6f8; --muted: #8cb9c0; --accent: #2dd4bf;
  --topbar-a: #04191e; --topbar-b: #082d34; --input: #031418; --th: #072329; --card: #062027;
  --pill: #041a1f; --primary: #0f766e; --primary-border: #2dd4bf; --footer: #4f7f86;
  --floor: #062228; --floor-line: #134650; --floor-target: #0d4a4a;
}
:root[data-theme="light"] {
  --bg: #e9eef5; --bg2: #f7f9fc; --panel: #ffffff; --panel2: #eef3f9; --panel-end: #f8fafc;
  --line: #cdd7e3; --row-line: #e3e9f1; --text: #0f172a; --muted: #5a6a80; --accent: #0369a1;
  --topbar-a: #ffffff; --topbar-b: #eef3f9; --input: #ffffff; --th: #f1f5f9; --card: #ffffff;
  --pill: #f8fafc; --primary: #0369a1; --primary-border: #0284c7; --footer: #64748b;
  --floor: #e2e9f2; --floor-line: #c5d1df; --floor-target: #cfe4f5;
  --warn-text: #c2410c; --info-text: #075985; --comm-bg: #fff7ed;
}
:root[data-theme="light"] .logo-on-dark, :root:not([data-theme="light"]) .logo-on-light { display: none; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  color: var(--text);
  font-size: 15px;
  /* header on top, footer at the bottom of the window even when the page is short */
  display: flex; flex-direction: column; min-height: 100vh;
}
body > main { flex: 1 0 auto; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 20px;
  background: linear-gradient(90deg, var(--topbar-a), var(--topbar-b));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 46px; height: 46px; flex: none; object-fit: contain; }
.brand .title { font-size: 22px; font-weight: 800; letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .subtitle { color: var(--accent); font-size: 13px; letter-spacing: 1px; }
.brand > div { min-width: 0; }     /* lets a long title end in … instead of running under the pills */
.tabs { display: flex; gap: 4px; }
/* the pills take what the title and tabs leave, and wrap into rows there */
.sysbar { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end;
  flex: 1 1 0; min-width: 0; }
.pill {
  display: flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 20px;
  background: var(--pill); border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
}
.pill .pdot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.pill .plabel { color: var(--muted); font-weight: 600; }
.pill .pvalue { color: var(--text); font-variant-numeric: tabular-nums; }
.pill.ok { --c: var(--green-hi); }
.pill.info { --c: var(--accent); }
.pill.warn { --c: var(--yellow-hi); }
.pill.bad { --c: var(--red-hi); border-color: rgba(239, 68, 68, .6); }
.pill.off { --c: var(--gray); }
.pill.off .pdot { box-shadow: none; }
.tabs a {
  color: var(--muted); text-decoration: none; padding: 8px 14px; border-radius: 8px; white-space: nowrap;
  border: 1px solid transparent; font-weight: 600;
}
.tabs a:hover { color: var(--text); background: var(--panel); }
.tabs a.active { color: var(--text); background: var(--panel2); border-color: var(--line); }
.clock { text-align: right; flex: none; }
/* ---- sign-in ---- */
.userchip { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 13px; flex: none; }
.userchip .links { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
button.linkish { background: none; border: none; padding: 0; color: var(--accent); font-size: 12px; text-decoration: underline; }
.userchip .who { color: var(--text); font-weight: 600; white-space: nowrap; }
.role { margin-left: 4px; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.role-admin { color: var(--warn-text); border-color: var(--warn); }
.small-link { font-size: 12px; white-space: nowrap; }
body.bare .clock { margin-left: auto; }
.auth-card { max-width: 440px; margin: 40px auto; padding: 24px 26px; }
.auth-card.wide-card { max-width: 680px; }
.auth-card h2 { font-size: 20px; margin-bottom: 14px; }
.auth-card .field input { width: 100%; }
.auth-card .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
button.wide { width: 100%; padding: 10px; font-size: 16px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; font-size: 13px; flex-wrap: wrap; }
input.otp { font-size: 24px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.totp-box { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.qr { background: #fff; padding: 6px; border-radius: 8px; line-height: 0; }
.qr svg { display: block; width: 240px; height: 240px; }
code.secret { font-size: 15px; letter-spacing: 1px; word-break: break-all; }
ol.steps { margin: 8px 0 0; padding-left: 22px; color: var(--text); font-size: 14px; line-height: 1.6; }
ol.steps li + li { margin-top: 4px; }
.manual { flex: 1 1 260px; min-width: 0; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; }
.manual-title { font-weight: 700; font-size: 14px; }
.manual-value { margin: 2px 0; word-break: break-all; }
#dlg-totp { width: min(760px, 96vw); }
/* LINE notifications (accounts page) */
.line-cols { display: flex; flex-wrap: wrap; gap: 16px; }
.line-box { flex: 1 1 340px; min-width: 0; }
.line-box h3 { margin: 0 0 6px; font-size: 15px; }
.line-box fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0 0 10px;
  display: flex; flex-direction: column; gap: 6px; }
.line-box legend { font-weight: 700; padding: 0 6px; }
.line-box input.num { width: 70px; padding: 3px 6px; }
#f-line-msg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; align-items: start; }
@media (max-width: 1100px) { #f-line-msg { grid-template-columns: minmax(0, 1fr); } }
#f-line-msg > .hint, #f-line-msg > .actions { grid-column: 1 / -1; }
.line-machines { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.line-groups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.line-state { font-size: 13px; margin-left: auto; }
.line-result { margin-top: 10px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); font-weight: 400; display: flex; flex-direction: column; gap: 2px; }
.line-result.ok { border-color: var(--green-hi); }
.line-result.bad { border-color: var(--red-hi); }
td.acts { display: flex; gap: 4px; flex-wrap: wrap; white-space: normal; }
@media (max-width: 640px) { .auth-card .grid2 { grid-template-columns: 1fr; } .userchip { order: 5; } }
.clock #clock-date { color: var(--muted); font-size: 13px; }
.clock #clock-time { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
body.kiosk .tabs { display: none; }
body.kiosk .clock { margin-left: 0; }

main { padding: 16px 20px 8px; }
.footer { padding: 4px 20px 10px; color: var(--footer); font-size: 12px; text-align: right; flex: none; }
/* show / hide password */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 42px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none;
  padding: 4px 8px; color: var(--muted); line-height: 0; }
.pw-eye:hover { color: var(--text); }
.pw-eye svg { width: 20px; height: 20px; }
body.kiosk .footer { display: none; }
.about { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.about img { width: min(420px, 100%); height: auto; }

/* ---- panels / common ---------------------------------------------------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-end));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.panel-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { font-size: 17px; text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); }
.banner {
  margin-bottom: 12px; padding: 10px 14px; border-radius: 8px; font-weight: 600;
  background: rgba(249, 115, 22, .15); border: 1px solid var(--warn); color: var(--warn-text);
}
.banner.info { background: rgba(56, 189, 248, .1); border-color: var(--accent); color: var(--info-text); }

button, .btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary-border); color: var(--primary-text); }
button.danger { background: #7f1d1d; border-color: #b91c1c; color: #fff; }
button.small { padding: 3px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

input, select {
  font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 9px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--primary-border); vertical-align: middle; }
label { color: var(--muted); font-size: 13px; }

table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--row-line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: var(--th); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; right: 20px; bottom: 20px; padding: 10px 16px; border-radius: 8px;
  background: #065f46; border: 1px solid #10b981; font-weight: 600; z-index: 50; color: #fff;
}
.toast.error { background: #7f1d1d; border-color: #ef4444; }

/* ---- dashboard -------------------------------------------------------- */
.summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 14px; }
.tile {
  border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; gap: 14px;
  border: 1px solid rgba(255,255,255,.12);
}
.tile .count { font-size: 40px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.tile .label { font-weight: 700; text-transform: uppercase; font-size: 14px; }
.tile .pct { font-size: 14px; opacity: .85; }
.tile.green, .tile.yellow, .tile.red, .tile.gray { color: #fff; }
.tile.green { background: linear-gradient(135deg, #15803d, #166534); }
.tile.yellow { background: linear-gradient(135deg, #ca8a04, #a16207); }
.tile.red { background: linear-gradient(135deg, #dc2626, #991b1b); }
.tile.gray { background: linear-gradient(135deg, #6b7280, #4b5563); }
.tile.comm_lost { background: var(--comm-bg); border: 2px dashed var(--warn); color: var(--warn-text); }

.dash-body { display: grid; grid-template-columns: 1fr 340px; gap: 14px; align-items: start; }
.dash-body.no-events { grid-template-columns: 1fr; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span::before {
  content: ""; display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  margin-right: 6px; vertical-align: -1px; background: var(--c);
}
.legend .l-green { --c: var(--green-hi); }
.legend .l-yellow { --c: var(--yellow-hi); }
.legend .l-red { --c: var(--red-hi); }
.legend .l-gray { --c: var(--gray-hi); }
.legend .l-comm::before { background: none; border: 2px dashed var(--warn); width: 8px; height: 8px; }
.shift-badge {
  margin-left: auto; padding: 4px 12px; border-radius: 20px; background: var(--panel2);
  border: 1px solid var(--line); font-weight: 600; font-size: 13px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.card {
  position: relative; border-radius: 9px; padding: 10px 12px 10px 16px; min-height: 108px;
  background: var(--card); border: 1px solid var(--line); overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.card .top { display: flex; justify-content: space-between; align-items: center; }
.card .code { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.card .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: 0 0 12px var(--c); }
.card .name { color: var(--muted); font-size: 14px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .state { margin-top: 8px; font-weight: 700; color: var(--c); }
.card .dur { font-variant-numeric: tabular-nums; font-size: 14px; }
.card .comm { display: none; margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--warn-text); }
.card.green { --c: var(--green-hi); }
.card.yellow { --c: var(--yellow-hi); }
.card.red { --c: var(--red-hi); background: linear-gradient(180deg, rgba(220,38,38,.18), var(--card) 70%); }
.card.gray { --c: var(--gray-hi); }
.card.nodata { --c: var(--nodata); }
.card.lost { --c: var(--warn); }
.card.lost { border: 2px dashed var(--warn); }
.card.lost .dot { box-shadow: none; opacity: .5; }
.card.lost .comm { display: block; }
.grid.no-code .code { display: none; }
.grid.no-code .name { color: var(--text); font-weight: 700; font-size: 16px; }
.grid.no-dur .dur { display: none; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---- floor view ---- */
.view-switch { display: flex; gap: 0; margin-left: 8px; }
.view-switch button { border-radius: 0; }
.view-switch button:first-child { border-radius: 8px 0 0 8px; }
.view-switch button:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.view-switch button.active { background: var(--primary); border-color: var(--primary-border); color: var(--primary-text); }
.floor { display: block; width: 100%; height: calc(100vh - 330px); min-height: 360px; }
body.kiosk .floor { height: calc(100vh - 250px); }
/* cards and floor together: the floor takes the rest of the screen height */
.machines-panel.both { display: flex; flex-direction: column; height: calc(100vh - 330px); min-height: 640px; }
body.kiosk .machines-panel.both { height: calc(100vh - 250px); }
.machines-panel.both .floor { flex: 1 1 auto; height: auto; min-height: 300px; margin-top: 10px;
  border-top: 1px solid var(--line); }
.fl-card { fill: var(--card); stroke: var(--line); stroke-width: 1; }
.fl-tile { fill: var(--floor); stroke: var(--floor-line); }
.fl-tint { fill: rgba(220, 38, 38, .18); }
.fl-label.lost .fl-card { stroke: var(--warn); stroke-width: 2; stroke-dasharray: 7 4; }
.fl-code { fill: var(--text); font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.fl-name { fill: var(--muted); font-size: 16px; }
.fl-state { font-size: 17px; font-weight: 700; }
.fl-dur { fill: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.fl-comm { fill: var(--warn-text); font-size: 14px; font-weight: 700; }
.fl-machine.off { opacity: .55; }
.lamp-stale { animation: stale 1.6s ease-in-out infinite; }
@keyframes stale { 50% { opacity: .25; } }
.floor.editing .fl-machine { cursor: grab; }
.floor.editing .fl-machine.dragging { cursor: grabbing; opacity: .75; }
.floor.editing .fl-label { cursor: move; }
.floor.editing .fl-label.dragging { opacity: .8; }
.slider { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.slider input { width: 120px; accent-color: var(--primary-border); }
.slider span { min-width: 40px; color: var(--text); }
.fl-floor polygon.target { fill: var(--floor-target); stroke: var(--accent); }

.events-panel table td { font-size: 13px; white-space: normal; }
.events-panel table td:first-child { white-space: nowrap; }
.events-panel .ev-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.ev-RUN { background: var(--green-hi); }
.ev-STOP { background: var(--red-hi); }
.events-scroll { max-height: calc(100vh - 290px); overflow: auto; }

/* ---- history / settings forms ------------------------------------------------ */
.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.machine-picks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; max-height: 120px; overflow: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.stack { display: grid; gap: 14px; }
/* grid / flex children may shrink below their content: wide tables scroll inside their box
   instead of widening the page (phones) */
.stack > *, .settings-grid > *, .dash-body > *, .panel { min-width: 0; }
.table-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--row-line); border-radius: 6px; }
.section-title { display: flex; align-items: center; gap: 12px; margin: 4px 0 10px; }
.section-title h3 { font-size: 15px; }
.mt { margin-top: 14px; }
.grow { flex: 1 1 320px; }
.pair { display: flex; gap: 6px; }
.span2 { grid-column: 1 / -1; }
.image-pick { display: flex; gap: 14px; align-items: flex-start; }
.image-pick img { width: 120px; height: 120px; object-fit: contain; background: var(--input);
  border: 1px dashed var(--line); border-radius: 8px; }
.image-pick img:not([src]) { visibility: hidden; }
.stack-sm { display: grid; gap: 8px; }
.actions.no-mt-left { margin: 0; align-items: center; }
.fl-glow { opacity: .3; }
.w-num { width: 96px; }
.grow input { width: 100%; }
.hint { font-size: 13px; color: var(--muted); }
.warn { color: var(--warn-text); font-weight: 600; }
.actions.no-mt { margin: 0 0 0 auto; }
#layout { height: 520px; min-height: 0; touch-action: none; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.settings-grid .wide { grid-column: 1 / -1; }
.col-stack { display: grid; gap: 14px; align-content: start; min-width: 0; }   /* panels stacked in one column */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 14px; }
.kv > div { overflow-wrap: anywhere; }   /* long folder paths wrap */
.kv .k { color: var(--muted); }
.ok { color: var(--green-hi); font-weight: 700; }
.bad { color: var(--red-hi); font-weight: 700; }
.result { margin-top: 10px; font-size: 14px; }
.mono { font-family: Consolas, monospace; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 12px; }
/* a form split into labelled boxes (settings → display) */
.groups { display: flex; flex-direction: column; gap: 12px; }
fieldset.group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px 12px; margin: 0; min-width: 0; }
fieldset.group legend { font-weight: 700; font-size: 14px; padding: 0 6px; }
fieldset.group .checks { margin-top: 4px; }
fieldset.group .hint { margin: 8px 0 0; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; }
fieldset.group .grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
fieldset.group .pair { width: 100%; }
.online-limits { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; }
.online-limits input { width: 100%; box-sizing: border-box; }
fieldset.group .pair > input { flex: 1 1 0; min-width: 0; }
fieldset.group .pair > select { flex: 0 0 auto; }
.grid3 .field > *, fieldset.group .grid2 .field > input { width: 100%; box-sizing: border-box; }
fieldset.group .grid2 .field > .pair > input { width: auto; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; width: min(560px, 94vw);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog#dlg-sessions { width: min(960px, 96vw); max-width: 96vw; }   /* after the dialog rule */
dialog .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog .err { color: var(--red-hi); min-height: 20px; margin-top: 8px; font-size: 14px; }

@media (max-width: 1100px) {
  .summary { grid-template-columns: repeat(3, 1fr); }
  .dash-body { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
/* medium screens: the status pills get a row of their own under the title */
@media (max-width: 1150px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .sysbar { order: 4; width: 100%; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .tabs { margin-left: 0; order: 3; width: 100%; }
  .sysbar { order: 4; width: 100%; justify-content: flex-start; margin-left: 0; }
  main { padding: 12px 16px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: repeat(2, 1fr) !important; }
  .brand .title { font-size: 17px; }
}
