/* MedAstrix Admin — phone first. Base rules are the phone layout; wider screens
   add to them (min-width queries). Touch targets are at least 44px, form fields
   are 16px so iOS does not zoom on focus, and the page never scrolls sideways. */
:root {
  --bg: #f5f6f4; --card: #ffffff; --ink: #1d2528; --muted: #5f6b70; --line: #d9dedb;
  --accent: #1f5f5b; --accent-ink: #ffffff; --danger: #a33a2b; --good: #2e7046; --warn: #a8661c;
  --tap: 44px;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141a1c; --card: #1c2427; --ink: #e6ecea; --muted: #9aa7a4; --line: #2d393c; --accent: #4fa39c; --accent-ink: #0d1415; --danger: #e0715f; --good: #6cc08a; --warn: #e3a35a; }
}
* { box-sizing: border-box; }
/* A class that sets `display` (main { display: grid }) beats the browser's own
   [hidden] rule, which made the signed-in console show on the sign-in screen.
   This restores "hidden means hidden" for everything on the page. */
[hidden] { display: none !important; }
html { color-scheme: light dark; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  min-height: 100dvh; overflow-x: hidden; overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header stays in view while scrolling a long message list. */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 10px; align-items: center; min-height: 52px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.bar strong { white-space: nowrap; }
.bar #who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.bar #signout { margin-left: auto; flex: none; }

main { max-width: 920px; margin: 0 auto; padding: 12px; display: grid; gap: 12px; }
.center { text-align: center; padding-top: 8vh; }
.center button { width: 100%; max-width: 320px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }

h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row h2 { margin: 0; }
.muted { color: var(--muted); }
.note { color: var(--muted); min-height: 1.5em; margin: 8px 0 0; }

button {
  font: inherit; min-height: var(--tap); padding: 8px 16px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; cursor: pointer; touch-action: manipulation;
}
button.ghost { background: transparent; color: var(--accent); }
button.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
button:active { filter: brightness(.9); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill { padding: 2px 12px; border-radius: 99px; font-size: .85rem; font-weight: 600; border: 1px solid var(--line); }
.pill.up { color: var(--good); border-color: var(--good); }
.pill.down { color: var(--muted); }
.pill.stopped { color: var(--warn); border-color: var(--warn); }

/* Status header: pill and Refresh sit on one line; Refresh goes to the right. */
#refresh { margin-left: auto; }

.facts { display: grid; grid-template-columns: 1fr; gap: 0; margin: 10px 0 14px; }
.facts dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-top: 8px; }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Up / Down: full width, stacked, with a clear gap so a thumb cannot hit the wrong one. */
.actions { display: grid; gap: 16px; }
.actions button { width: 100%; }

ul { list-style: none; padding: 0; margin: 0; }
.runs li, .audit li { border-top: 1px solid var(--line); font-size: .9rem; font-variant-numeric: tabular-nums; }
.runs a { display: block; padding: 11px 0; color: var(--accent); }
.audit li { padding: 9px 0; }

.messages li { border-top: 1px solid var(--line); }
.messages summary {
  cursor: pointer; display: flex; gap: 4px 10px; flex-wrap: wrap; align-items: baseline;
  min-height: var(--tap); padding: 10px 0;
}
.messages summary strong { flex: 1 1 100%; }
.messages summary .muted { font-size: .85rem; }
.messages pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .92rem; background: var(--bg); padding: 10px; border-radius: 8px; margin: 8px 0; }
.messages button { width: 100%; }
.tag { font-size: .8rem; padding: 0 8px; border-radius: 99px; border: 1px solid var(--line); }
.tag.failed, .tag.partial, .tag.no_recipients { color: var(--danger); border-color: var(--danger); }
#more { width: 100%; margin-top: 8px; }

.tag.kind-access { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.messages li[hidden] { display: none; }
select { font: inherit; font-size: 16px; width: 100%; min-height: var(--tap); padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); margin-bottom: 8px; }
textarea, input { font: inherit; font-size: 16px; width: 100%; min-height: var(--tap); padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
textarea { resize: vertical; }
#save-recipients { width: 100%; }
#recipients-msg { margin: 0; flex: 1 1 100%; }

/* Confirmation dialog: a sheet pinned to the bottom of the screen on phones. */
dialog {
  border: 1px solid var(--line); border-radius: 14px 14px 0 0; background: var(--card); color: var(--ink);
  width: 100%; max-width: 100%; margin: auto 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog label { display: block; margin: 12px 0; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
dialog .row button { width: 100%; }
code { background: var(--bg); padding: 0 4px; border-radius: 4px; }

/* Tablets and up: restore the compact desktop arrangement. */
@media (min-width: 640px) {
  :root { font-size: 15px; }
  main { padding: 16px; gap: 16px; }
  .card { padding: 16px 18px; }
  .center button, #more, #save-recipients, .messages button { width: auto; }
  .facts { grid-template-columns: max-content 1fr; gap: 4px 16px; }
  .facts dt { font-size: inherit; text-transform: none; letter-spacing: 0; margin-top: 0; }
  .actions { display: flex; gap: 10px; }
  .actions button { width: auto; }
  .messages summary strong { flex: 0 1 auto; }
  #recipients-msg { flex: 1 1 auto; }
  dialog { width: 520px; max-width: calc(100vw - 32px); margin: auto; border-radius: 12px; padding: 18px; }
  dialog .row { display: flex; justify-content: flex-end; }
  dialog .row button { width: auto; }
}

/* Short landscape phones: the sheet must scroll rather than overflow. */
@media (max-height: 480px) {
  dialog { max-height: 100dvh; overflow-y: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
