/* Palette 3 "Graphite", light and dark.
   Every colour used anywhere in the app is a token here; nothing else
   hardcodes one, so a palette change means editing only this block. */
:root {
  color-scheme: light;

  --bg: #F4F4F4;
  --surface: #FFFFFF;
  --surface-2: #E9E9E9;
  --surface-3: #DBDBDB;
  --border: #D0D0D0;

  --text: #161616;
  --text-secondary: #555555;
  --text-muted: #747474;

  --brand-red: #AF0101;
  --red-hover: #8E0000;
  --red-bg: #F7E7E7;
  --red-text: #AF0101;

  --success: #187747;
  --warning: #986100;
  --info: #256A9B;
  --error: #AF0101;

  /* Tinted backgrounds for status chips. The palette supplies only the red
     one, so the others follow the same recipe: a pale wash of the accent. */
  --success-bg: #E4F1EA;
  --success-text: #146239;
  --warning-bg: #F6EEDC;
  --warning-text: #7A4E00;
  --info-bg: #E3EDF5;
  --info-text: #1F587F;
  --error-bg: #F7E7E7;
  --error-text: #AF0101;

  /* Solid buttons need a fill that white text sits on comfortably. */
  --btn-success-bg: #187747;
  --btn-success-hover: #13603A;
  --btn-danger-bg: #AF0101;
  --btn-danger-hover: #8E0000;
  --btn-primary-bg: #256A9B;
  --btn-primary-hover: #1D5580;
  --btn-on-color: #FFFFFF;

  --focus: #256A9B;
  --overlay: rgba(20, 20, 20, 0.62);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  --thumb-bg: #DBDBDB;

  /* Production tags. Six hues that stay distinguishable in both themes. */
  --prod-0-bg: #E3EDF7; --prod-0-fg: #1B4F80;
  --prod-1-bg: #F6EBD9; --prod-1-fg: #7A4A00;
  --prod-2-bg: #EBE6F7; --prod-2-fg: #4B3A8A;
  --prod-3-bg: #DEF0EC; --prod-3-fg: #14574A;
  --prod-4-bg: #F8E4EE; --prod-4-fg: #8A2455;
  --prod-5-bg: #EEEEDA; --prod-5-fg: #56560F;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0D0D0E;
  --surface: #171718;
  --surface-2: #202022;
  --surface-3: #29292C;
  --border: #39393D;

  --text: #F7F7F7;
  --text-secondary: #BDBDBF;
  --text-muted: #8E8E92;

  --brand-red: #AF0101;
  --red-hover: #CF1010;
  --red-bg: #321617;
  --red-text: #FF7474;

  --success: #54C58A;
  --warning: #F1B64B;
  --info: #6CB0DF;
  --error: #FF7474;

  --success-bg: #12291D;
  --success-text: #54C58A;
  --warning-bg: #2F2413;
  --warning-text: #F1B64B;
  --info-bg: #162634;
  --info-text: #6CB0DF;
  --error-bg: #321617;
  --error-text: #FF7474;

  --btn-success-bg: #1F6B41;
  --btn-success-hover: #278150;
  --btn-danger-bg: #AF0101;
  --btn-danger-hover: #CF1010;
  --btn-primary-bg: #2A6B96;
  --btn-primary-hover: #347FB0;
  --btn-on-color: #FFFFFF;

  --focus: #6CB0DF;
  --overlay: rgba(6, 6, 7, 0.88);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --thumb-bg: #0D0D0E;

  --prod-0-bg: #1F3A5F; --prod-0-fg: #7DB4FF;
  --prod-1-bg: #3A2F1A; --prod-1-fg: #FFC46B;
  --prod-2-bg: #2B1F4A; --prod-2-fg: #B9A4FF;
  --prod-3-bg: #1C3B36; --prod-3-fg: #6FE0C8;
  --prod-4-bg: #4A1F36; --prod-4-fg: #FF8FC4;
  --prod-5-bg: #3B3B1C; --prod-5-fg: #E0E06F;
}

/* --- Shared shell ------------------------------------------------------- */

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px;
}
body.centred {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px; box-sizing: border-box;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 28px 0 12px; color: var(--text-secondary); }

.top { display: flex; justify-content: space-between; align-items: center;
       margin-bottom: 20px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 40px; height: 40px; border-radius: 9px; }
.nav { display: flex; align-items: center; gap: 10px; }
.who { color: var(--text-secondary); font-size: 13px; }
.who strong { color: var(--text); }

a.navlink, .logout-btn, .theme-btn {
  color: var(--text-secondary); font-size: 13px; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-family: inherit;
}
a.navlink:hover, .logout-btn:hover, .theme-btn:hover {
  color: var(--text); border-color: var(--text-muted);
}
form.logout { display: inline; }
.theme-btn { line-height: 1; }
.theme-btn .theme-dark-label { display: none; }
[data-theme="dark"] .theme-btn .theme-dark-label { display: inline; }
[data-theme="dark"] .theme-btn .theme-light-label { display: none; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Tables ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; background: var(--surface);
        border-radius: 10px; overflow: hidden; }
th, td { padding: 12px 14px; text-align: left; font-size: 14px;
         border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px;
     text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mono { font-family: ui-monospace, monospace; color: var(--text-secondary); font-size: 13px; }
.sub-cell { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.totals td { border-top: 1px solid var(--border); background: var(--surface-2);
             color: var(--text-secondary); font-weight: 700; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }

/* --- Status chips ------------------------------------------------------- */

.badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-running { background: var(--success-bg); color: var(--success-text); }
.badge-stopped { background: var(--error-bg); color: var(--error-text); }
.badge-pending, .badge-stopping { background: var(--warning-bg); color: var(--warning-text); }
.badge-admin { background: var(--prod-2-bg); color: var(--prod-2-fg); }
.badge-user { background: var(--info-bg); color: var(--info-text); }
.pill { padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; margin-left: 6px; }
.pill-snooze { background: var(--prod-2-bg); color: var(--prod-2-fg); }
/* Ready for connection (AutoReady over SSM), under the state badge. */
.ready-line { margin-top: 5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ready { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
         color: var(--text-secondary); white-space: nowrap; }
.ready-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.ready-ready { color: var(--success-text); }
.ready-ready .ready-dot { background: var(--success); }
.ready-not_ready { color: var(--warning-text); }
.ready-not_ready .ready-dot { background: var(--warning); }
.ready-starting .ready-dot, .ready-fixing .ready-dot, .ready-unknown .ready-dot {
  background: var(--info); animation: ready-pulse 1.4s ease-in-out infinite; }
@keyframes ready-pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .ready-dot { animation: none !important; } }
.btn-fix { padding: 1px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; cursor: pointer;
           font-family: inherit; background: var(--warning-bg); color: var(--warning-text);
           border: 1px solid var(--warning); }
.btn-fix:hover { filter: brightness(.95); }
.btn-dcv { padding: 1px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; text-decoration: none;
           background: var(--btn-primary-bg); color: var(--btn-on-color); white-space: nowrap; }
.btn-dcv:hover { background: var(--btn-primary-hover); }
.warn { color: var(--warning); font-weight: 700; }
.cost { color: var(--text); font-weight: 700; }

/* --- Buttons ------------------------------------------------------------ */

.btn { padding: 6px 12px; border-radius: 6px; border: none; cursor: pointer;
       font-weight: 600; font-size: 13px; font-family: inherit;
       position: relative; transition: transform .06s ease, filter .12s ease; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
/* A press you can feel, so it is obvious the click registered. */
.btn:active:not(:disabled) { transform: scale(0.96); }

/* --- In-flight feedback -------------------------------------------------
   htmx puts .htmx-request on the button it is running a request for, and
   hx-disabled-elt disables it, so a second click cannot be sent while AWS
   is still thinking. The spinner keeps its button's colour rather than the
   flat disabled grey, so it reads as "working" not "unavailable". */
.btn-busy-label { display: none; }
.btn.htmx-request { cursor: progress; padding-right: 30px; }
.btn.htmx-request .btn-label { display: none; }
.btn.htmx-request .btn-busy-label { display: inline; }
.btn.htmx-request::after,
.btn-working::after {
  content: ""; position: absolute; right: 9px; top: 50%; margin-top: -7px;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #FFFFFF;
  animation: spin 0.7s linear infinite;
}
/* Keep the button's own colour while busy; the grey disabled look would
   suggest the click failed. */
.btn:disabled:not(.htmx-request):not(.btn-working) {
  background: var(--surface-2); color: var(--text-muted); cursor: default;
}
.btn.htmx-request:disabled { opacity: 0.9; }
/* A machine mid-transition (pending/stopping) keeps spinning, so the wait
   for AWS is visible rather than looking stalled. */
.btn-working { padding-right: 30px; cursor: progress;
               background: var(--surface-3); color: var(--text-secondary); }
.btn-working::after { border-color: var(--text-muted); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .btn.htmx-request::after, .btn-working::after { animation-duration: 2.4s; }
  .btn:active:not(:disabled) { transform: none; }
}

.lv-toggle.htmx-request { cursor: progress; opacity: 0.75; }
.lv-toggle.htmx-request .lv-dot { animation: pulse 0.8s ease-in-out infinite; }
.thumb-enable.htmx-request { cursor: progress; color: var(--text); }
.btn-start { background: var(--btn-success-bg); color: var(--btn-on-color); }
.btn-start:hover { background: var(--btn-success-hover); }
.btn-stop, .btn-danger { background: var(--btn-danger-bg); color: var(--btn-on-color); }
.btn-stop:hover, .btn-danger:hover { background: var(--btn-danger-hover); }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-on-color); }
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-quiet { background: var(--surface-2); color: var(--text-secondary);
             border: 1px solid var(--border); }
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

input, select {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit;
}
input::placeholder { color: var(--text-muted); }

/* --- Dashboard header --------------------------------------------------- */

.sub { color: var(--text-secondary); font-size: 13px;
       display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.thresh { display: inline-flex; align-items: center; gap: 5px; margin: 0; }
.thresh select { padding: 2px 5px; }
.dot { color: var(--text-muted); }
.presence-label { color: var(--text-secondary); }
.chip { background: var(--surface-2); color: var(--text-secondary);
        border-radius: 20px; padding: 2px 9px; font-size: 12px; }
.chip-me { background: var(--prod-2-bg); color: var(--prod-2-fg); }
#busy { display: none; color: var(--text-muted); font-size: 12px; }
#busy.htmx-request { display: inline; }

/* --- Instance rows ------------------------------------------------------ */

.namecell { display: flex; align-items: center; gap: 12px; }
.tags { margin-top: 4px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.prod { padding: 1px 8px; border-radius: 4px; font-size: 11px; font-weight: 700;
        letter-spacing: .02em; }
.prod-0 { background: var(--prod-0-bg); color: var(--prod-0-fg); }
.prod-1 { background: var(--prod-1-bg); color: var(--prod-1-fg); }
.prod-2 { background: var(--prod-2-bg); color: var(--prod-2-fg); }
.prod-3 { background: var(--prod-3-bg); color: var(--prod-3-fg); }
.prod-4 { background: var(--prod-4-bg); color: var(--prod-4-fg); }
.prod-5 { background: var(--prod-5-bg); color: var(--prod-5-fg); }
.prod-x { background: var(--surface-2); color: var(--text-secondary); font-weight: 600; }
.live { background: var(--brand-red); color: #FFFFFF; padding: 1px 8px; border-radius: 4px;
        font-size: 11px; font-weight: 800; animation: pulse 1.6s ease-in-out infinite; }
.rec { background: var(--error-bg); color: var(--error-text); padding: 1px 8px;
       border-radius: 4px; font-size: 11px; font-weight: 700; }
@keyframes pulse { 50% { opacity: .55; } }

.lv-toggle { display: inline-flex; align-items: center; gap: 5px; border-radius: 4px;
             padding: 1px 8px; font-size: 11px; font-weight: 700; cursor: pointer;
             font-family: inherit; border: 1px solid transparent; }
.lv-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.lv-on { background: var(--success-bg); color: var(--success-text); border-color: var(--success); }
.lv-on:hover { filter: brightness(1.08); }
.lv-off { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.lv-off:hover { background: var(--surface-3); color: var(--text-secondary); }

.error-row { color: var(--error-text); }
.notice-row { color: var(--info-text); }
.failure-row td { background: var(--error-bg); color: var(--error-text); font-size: 13px; }
.fail-tag { background: var(--brand-red); color: #FFFFFF; padding: 2px 8px; border-radius: 4px;
            font-size: 11px; font-weight: 700; margin-right: 8px; }
.fail-body { display: flex; align-items: center; gap: 10px; }
.retry-row td { background: var(--info-bg); color: var(--info-text); font-size: 13px; }
.retry-tag { display: inline-flex; align-items: center; gap: 5px; background: var(--btn-primary-bg);
             color: #FFFFFF; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700;
             margin-right: 6px; }
.retry-tag .ready-dot { background: #FFFFFF; animation: ready-pulse 1.4s ease-in-out infinite; }
.fail-msg { flex: 1; }
.btn-x { background: none; border: none; color: var(--error-text); cursor: pointer;
         font-size: 18px; line-height: 1; padding: 0 4px; opacity: 0.75; font-family: inherit; }
.btn-x:hover { opacity: 1; }

/* --- Output preview ----------------------------------------------------- */

.thumb-link { flex: none; line-height: 0; padding: 0; border: none; background: none;
              cursor: zoom-in; border-radius: 5px; }
.thumb { width: 128px; height: 72px; object-fit: cover; border-radius: 5px;
         border: 1px solid var(--border); background: var(--thumb-bg); display: block; }
.thumb-enable, .thumb-wait {
  display: flex; align-items: center; justify-content: center; text-align: center;
  flex: none; font-size: 11px; line-height: 1.3; color: var(--text-muted);
  border: 1px dashed var(--border); background: var(--surface-2);
  cursor: pointer; font-family: inherit;
}
.thumb-enable:hover { color: var(--text); border-color: var(--focus); background: var(--surface-3); }
.thumb-wait { cursor: default; }

.zoom { position: fixed; inset: 0; z-index: 50; background: var(--overlay);
        display: none; align-items: center; justify-content: center; padding: 24px; }
.zoom.is-open { display: flex; }
.zoom-box { width: 100%; max-width: 1180px; }
.zoom-bar { display: flex; align-items: center; justify-content: space-between;
            gap: 12px; margin-bottom: 10px; color: #FFFFFF; font-size: 14px; font-weight: 600; }
.zoom-close { width: 38px; height: 38px; flex: none; border-radius: 8px; cursor: pointer;
              background: var(--surface); border: 1px solid var(--border); color: var(--text);
              font-size: 22px; line-height: 1; font-family: inherit; }
.zoom-close:hover { background: var(--surface-2); }
.zoom-box img { display: block; width: 100%; height: auto; max-height: 78vh;
                object-fit: contain; background: #000; border-radius: 8px;
                border: 1px solid var(--border); }
body.zoom-open { overflow: hidden; }

/* --- Users page --------------------------------------------------------- */

.row-form { display: inline-flex; gap: 6px; align-items: center; }
.add { background: var(--surface); border: 1px solid var(--border); padding: 16px;
       border-radius: 10px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.msg-error { background: var(--error-bg); color: var(--error-text); }
.msg-ok { background: var(--success-bg); color: var(--success-text); }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 8px; }
.hint-inline { color: var(--text-muted); font-size: 11px; }
.machines { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.machine { font-size: 13px; color: var(--text-secondary); display: flex;
           align-items: center; gap: 6px; }
.machine input { width: auto; }
.all-tag { color: var(--text-muted); font-size: 12px; font-style: italic; }
.self-note { color: var(--text-muted); }

/* --- Login and snooze cards --------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--border); padding: 32px;
        border-radius: 12px; box-shadow: var(--shadow); }
.card-login { width: 280px; }
.card-note { max-width: 420px; text-align: center; }
.card-login input { width: 100%; margin-bottom: 12px; padding: 10px; box-sizing: border-box; }
.card-login button { width: 100%; padding: 10px; border-radius: 6px; border: none;
                     background: var(--btn-primary-bg); color: var(--btn-on-color);
                     font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px; }
.card-login button:hover { background: var(--btn-primary-hover); }
.card-login h1 { font-size: 18px; margin: 0 0 16px; text-align: center; }
.logo { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 14px; }
.card-note img { width: 64px; height: 64px; border-radius: 14px; margin-bottom: 16px; }
.card-note h1 { font-size: 19px; margin: 0 0 10px; }
.card-note p { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin: 0 0 18px; }
.error { color: var(--error-text); font-size: 13px; margin-bottom: 12px; }
.ok { color: var(--success-text); }
.bad { color: var(--error-text); }

/* --- Narrow screens ----------------------------------------------------- */

@media (max-width: 720px) {
  body { padding: 12px; }
  .col-id, .col-type, .col-rate, .col-ip { display: none; }
  th, td { padding: 9px 6px; font-size: 13px; }
  th { font-size: 11px; }
  .top { flex-wrap: wrap; }
  .brand img { width: 32px; height: 32px; }
  .thumb { width: 84px; height: 47px; }
  .namecell { gap: 8px; }
  .btn { padding: 6px 9px; font-size: 12px; }
  .actions { gap: 4px; }
  .sub-cell { font-size: 10px; }
  .add { flex-direction: column; align-items: stretch; }
}

/* --- Lit buttons ----------------------------------------------------------
   Buttons look like lit physical keys: a top light, a bottom shade, a contact
   shadow and a soft glow in the button's own colour. Glow is kept lower than
   the house standard here, since a row of Start/Stop buttons sits on every
   machine line. Ghost buttons (.btn-x) stay flat. */
:root {
  --lift-top: inset 0 1px 0 rgb(255 255 255 / .9);
  --lift-bottom: inset 0 -1px 0 rgb(16 20 27 / .07);
  --lift-contact: 0 1px 2px rgb(16 20 27 / .09);
  --lift-glow: 0 2px 6px -2px rgb(16 20 27 / .07);
  --lit-top: inset 0 1px 0 rgb(255 255 255 / .28);
  --lit-bottom: inset 0 -2px 0 rgb(0 0 0 / .2);
  --lit-glow-mix: 30%;
}
[data-theme="dark"] {
  --lift-top: inset 0 1px 0 rgb(255 255 255 / .07);
  --lift-bottom: inset 0 -1px 0 rgb(0 0 0 / .35);
  --lift-contact: 0 1px 2px rgb(0 0 0 / .5);
  --lift-glow: 0 2px 6px -2px rgb(0 0 0 / .45);
  --lit-top: inset 0 1px 0 rgb(255 255 255 / .16);
  --lit-bottom: inset 0 -2px 0 rgb(0 0 0 / .35);
  --lit-glow-mix: 24%;
}

.btn, .btn-fix, .btn-dcv, .lv-toggle, .card-login button,
a.navlink, .logout-btn, .theme-btn {
  transition: box-shadow .15s ease, transform .1s ease, filter .15s ease;
}
.btn { border-radius: 8px; }
.card-login button { border-radius: 10px; }

/* Coloured keys: Start, Stop/danger, primary, Open in browser, sign in. */
.btn-start, .btn-stop, .btn-danger, .btn-primary, .btn-dcv, .card-login button {
  --key: var(--btn-primary-bg);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--key), #fff 14%) 0%, var(--key) 55%,
    color-mix(in srgb, var(--key), #000 12%) 100%);
  text-shadow: 0 1px 0 rgb(0 0 0 / .22);
  box-shadow: var(--lit-top), var(--lit-bottom),
    0 1px 2px color-mix(in srgb, var(--key), #000 55%),
    0 4px 12px -5px color-mix(in srgb, var(--key) var(--lit-glow-mix), transparent);
}
.btn-start { --key: var(--btn-success-bg); }
.btn-stop, .btn-danger { --key: var(--btn-danger-bg); }
.btn-start:hover, .btn-stop:hover, .btn-danger:hover, .btn-primary:hover,
.btn-dcv:hover, .card-login button:hover { background: linear-gradient(180deg,
    color-mix(in srgb, var(--key), #fff 14%) 0%, var(--key) 55%,
    color-mix(in srgb, var(--key), #000 12%) 100%); filter: brightness(1.06); }

/* Neutral keys: quiet buttons, header links, theme and sign-out. */
.btn-quiet, a.navlink, .logout-btn, .theme-btn, .lv-off {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--lift-top), var(--lift-bottom), var(--lift-contact), var(--lift-glow);
}
.btn-quiet, a.navlink, .logout-btn, .theme-btn { border-radius: 8px; }
.btn-quiet:hover, a.navlink:hover, .logout-btn:hover, .theme-btn:hover, .lv-off:hover {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  filter: brightness(1.04);
}
[data-theme="dark"] .btn-quiet, [data-theme="dark"] a.navlink, [data-theme="dark"] .logout-btn,
[data-theme="dark"] .theme-btn, [data-theme="dark"] .lv-off {
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
}
[data-theme="dark"] .btn-quiet:hover, [data-theme="dark"] a.navlink:hover,
[data-theme="dark"] .logout-btn:hover, [data-theme="dark"] .theme-btn:hover,
[data-theme="dark"] .lv-off:hover { filter: brightness(1.12); }

/* Fix is a warning-tinted key. */
.btn-fix {
  border-radius: 6px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--warning-bg), #fff 25%), var(--warning-bg));
  box-shadow: var(--lift-top), var(--lift-bottom), var(--lift-contact),
    0 3px 8px -4px color-mix(in srgb, var(--warning) 35%, transparent);
}
.btn-fix:hover { filter: brightness(1.04); }
[data-theme="dark"] .btn-fix { background: linear-gradient(180deg,
    color-mix(in srgb, var(--warning-bg), #fff 6%), var(--warning-bg)); }
.btn-dcv { border-radius: 6px; }

/* Selected toggle (live view on): pressed in, with a soft tinted ring. */
.lv-toggle { border-radius: 6px; }
.lv-on {
  box-shadow: inset 0 1px 2px rgb(0 0 0 / .18),
    0 0 0 2px color-mix(in srgb, var(--success) 22%, transparent);
}

/* Pressed: sink 1px, lights and glow off. Replaces the old scale(.96). */
.btn:active:not(:disabled), .btn-fix:active, .btn-dcv:active, .lv-toggle:active,
.card-login button:active, a.navlink:active, .logout-btn:active, .theme-btn:active {
  transform: translateY(1px);
  box-shadow: var(--lift-bottom), inset 0 1px 2px rgb(0 0 0 / .18);
  filter: none;
}

/* Working and disabled: lights mostly off, so they don't read as clickable. */
.btn-working, .btn:disabled:not(.htmx-request) {
  background: var(--surface-3); text-shadow: none;
  box-shadow: inset 0 -1px 0 rgb(0 0 0 / .06);
}
.btn:disabled:not(.htmx-request):not(.btn-working) { background: var(--surface-2); }
.btn.htmx-request { box-shadow: var(--lit-bottom); filter: none; }

.btn-x { box-shadow: none; background: none; }

@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled), .btn-fix:active, .btn-dcv:active, .lv-toggle:active,
  .card-login button:active, a.navlink:active, .logout-btn:active, .theme-btn:active {
    transform: none; }
}

/* --- Header menu ----------------------------------------------------------
   The nav sits in a <details> so phones can fold it behind a menu button.
   Wider screens hold it open (script in dashboard.html) and hide the button. */
.navmenu > summary { display: none; }
.navmenu > summary::-webkit-details-marker { display: none; }

/* --- Phones ---------------------------------------------------------------
   Each machine row becomes a card. The table markup stays the same, so the
   htmx row refresh and the busy spinners work unchanged. Desktop is untouched. */
@media (max-width: 640px) {
  .top { flex-wrap: nowrap; align-items: flex-start; position: relative; }
  .brand { min-width: 0; }
  .brand h1 { font-size: 17px; }
  .sub { font-size: 12px; }

  .navmenu > summary {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 8px; cursor: pointer; list-style: none;
    font-size: 20px; color: var(--text-secondary); border: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    box-shadow: var(--lift-top), var(--lift-bottom), var(--lift-contact), var(--lift-glow);
  }
  [data-theme="dark"] .navmenu > summary { background: linear-gradient(180deg, var(--surface-3), var(--surface-2)); }
  .navmenu[open] > summary { box-shadow: var(--lift-bottom), inset 0 1px 2px rgb(0 0 0 / .18); }
  .navmenu .nav {
    position: absolute; right: 0; top: 48px; z-index: 20;
    flex-direction: column; align-items: stretch; gap: 8px; min-width: 200px;
    padding: 12px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); box-shadow: var(--shadow);
  }
  .navmenu .nav .who { padding: 2px 2px 6px; border-bottom: 1px solid var(--border); }
  .navmenu .nav a.navlink, .navmenu .nav .theme-btn, .navmenu .nav .logout-btn {
    display: block; width: 100%; min-height: 40px; box-sizing: border-box; text-align: center; }
  .navmenu .nav .theme-btn { display: flex; align-items: center; justify-content: center; }
  .navmenu .nav form.logout { display: block; }

  /* Machine table -> cards. */
  .table-wrap:has(#instance-rows) { overflow: visible; }
  table:has(#instance-rows) { background: transparent; border-radius: 0; overflow: visible; }
  table:has(#instance-rows) thead { display: none; }
  #instance-rows { display: flex; flex-direction: column; gap: 10px; }
  #instance-rows > tr { display: block; }
  #instance-rows > tr > td { display: block; border: none; padding: 0; font-size: 14px; }

  #instance-rows > tr.inst-row {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
    padding: 12px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); box-shadow: var(--lift-contact), var(--lift-glow);
  }
  #instance-rows .col-name, #instance-rows .col-state, #instance-rows .actions { grid-column: 1 / -1; }
  #instance-rows .col-id, #instance-rows .col-type, #instance-rows .col-ip,
  #instance-rows .col-rate { display: none; }
  #instance-rows .col-name { font-weight: 600; }
  #instance-rows .thumb { width: 112px; height: 63px; }
  #instance-rows .col-state { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
    padding-top: 10px; border-top: 1px solid var(--border); }
  #instance-rows .col-state .ready-line { margin-top: 0; }
  #instance-rows .btn-dcv, #instance-rows .btn-fix { padding: 6px 10px; font-size: 12px; }
  #instance-rows [data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 2px; }
  #instance-rows .actions { display: flex; gap: 8px; }
  #instance-rows .actions .btn { flex: 1; min-height: 40px; font-size: 14px; padding: 8px 10px; }
  #instance-rows .actions .btn.btn-quiet { flex: 0 1 64px; }
  #instance-rows .actions .btn.htmx-request, #instance-rows .actions .btn-working { padding-right: 30px; }

  /* Keep-trying, failure and message rows: full-width notes under their card. */
  #instance-rows > tr.retry-row, #instance-rows > tr.failure-row {
    margin-top: -6px; border-radius: 12px; overflow: hidden; }
  #instance-rows > tr.retry-row > td, #instance-rows > tr.failure-row > td { padding: 10px 12px; }
  #instance-rows .fail-body { flex-wrap: wrap; }
  #instance-rows .fail-body .fail-msg { flex: 1 1 100%; }
  #instance-rows .fail-body .btn { flex: 1; min-height: 40px; }
  #instance-rows > tr > td.empty { padding: 16px; border-radius: 12px; background: var(--surface); }

  #instance-rows > tr.totals { display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
  #instance-rows > tr.totals > td { background: none; border: none; }
  #instance-rows > tr.totals > td:empty, #instance-rows > tr.totals > td.col-rate { display: none; }

  /* Users page: keep the table, scroll it sideways. */
  .users-table { min-width: 680px; }
}
