/* Styling for the host's pages (sign-in and administration), in the same look as the viewer: one teal accent, hairline borders, 8 px controls,
   12 px panels, system font, light and dark by the operating system setting. No external requests.
   The token values below repeat the viewer's css/tokens.css (src/Dta.SurveyCloud.Viewer/css/tokens.css): these pages link only this file, so keep the two in step. */
:root {
  --font: system-ui, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --radius: 8px; --radius-lg: 12px; --radius-pill: 999px;
  --control-h: 36px;
  --bg: #edf0f3; --surface: #ffffff; --surface-2: #f4f6f8; --surface-3: #e8ecf0;
  --ink: #14212b; --ink-muted: #4a5a68; --line: #dde3e8; --line-strong: #758595;
  --accent: #0a766f; --accent-hover: #086860; --accent-ink: #ffffff; --accent-soft: #d9f0ed; --accent-text: #0a6963;
  --danger: #b3261e; --danger-soft: #fbe4e2; --danger-line: #e8aaa5;
  --ok-text: #14683a; --ok-soft: #dff3e6; --ok-line: #93d0aa;
  --focus: #0a766f;
  --shadow: 0 1px 2px rgba(16, 28, 38, 0.1), 0 6px 20px rgba(16, 28, 38, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1016; --surface: #111a22; --surface-2: #17222c; --surface-3: #1f2c38;
    --ink: #e9eff4; --ink-muted: #9fb2c1; --line: #223140; --line-strong: #5a6f80;
    --accent: #2fc9b6; --accent-hover: #4ad8c6; --accent-ink: #03211e; --accent-soft: #0f3b3a; --accent-text: #5ddccb;
    --danger: #ff8f86; --danger-soft: #3a1c1b; --danger-line: #7a3330;
    --ok-text: #6fd69a; --ok-soft: #0f2f20; --ok-line: #1f6b44;
    --focus: #5ddccb;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; font: 0.875rem/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: var(--sp-2); top: var(--sp-2); background: var(--accent); color: var(--accent-ink); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius); z-index: 10; }

.bar { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; min-height: 52px; padding: var(--sp-2) var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 600; }
.brand::before { content: ""; width: 14px; height: 14px; border: 2px solid var(--accent); border-radius: 50%; }
.bar nav { display: flex; gap: var(--sp-4); align-items: center; }
.bar nav a { color: var(--ink-muted); text-decoration: none; font-weight: 500; padding: var(--sp-1) 0; border-bottom: 2px solid transparent; }
.bar nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }

main { max-width: 64rem; margin: 0 auto; padding: var(--sp-5) var(--sp-4); }
h1 { font-size: 1.5rem; font-weight: 600; line-height: 1.25; margin: var(--sp-2) 0 var(--sp-4); }
h2 { font-size: 1.125rem; font-weight: 600; margin: var(--sp-5) 0 var(--sp-2); }
a { color: var(--accent-text); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

table { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
/* No overflow clipping on the table (it would cut the caption's first letter at the rounded corner): the header cells round their own corners. */
thead th:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); }
thead th:last-child { border-top-right-radius: calc(var(--radius-lg) - 1px); }
th, td { border-bottom: 1px solid var(--line); padding: var(--sp-2) var(--sp-3); text-align: left; vertical-align: top; }
tr:last-child td, tr:last-child th { border-bottom: 0; }
th { background: var(--surface-2); color: var(--ink-muted); font-size: 0.8125rem; font-weight: 600; }
/* The caption is a quiet heading for the table, left-aligned like everything else. */
caption { caption-side: top; text-align: left; padding: 0 0 var(--sp-2); color: var(--ink-muted); font-size: 0.8125rem; font-weight: 600; }
td.num, th.num { white-space: nowrap; }
td.folder { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.8125rem; color: var(--ink-muted); overflow-wrap: anywhere; min-width: 0; }

form.stack { display: grid; gap: var(--sp-3); max-width: 28rem; background: var(--surface); padding: var(--sp-5); border: 1px solid var(--line); border-radius: var(--radius-lg); }
form.stack label { display: grid; gap: var(--sp-1); font-weight: 500; }
input, select, textarea { font: inherit; min-height: var(--control-h); padding: 0 var(--sp-3); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
textarea { padding: var(--sp-2) var(--sp-3); }
input:hover, select:hover { border-color: var(--ink-muted); }
input:focus-visible, select:focus-visible { border-color: var(--focus); outline-offset: 0; }
input[type="checkbox"], input[type="radio"] { min-height: 0; accent-color: var(--accent); }
input[type="file"] { padding: 3px var(--sp-2); color: var(--ink-muted); cursor: pointer; }
input[type="file"]::file-selector-button { font: inherit; font-weight: 500; min-height: 28px; padding: 0 var(--sp-3); margin-right: var(--sp-3); border: 1px solid var(--line-strong); border-radius: calc(var(--radius) - 2px); background: transparent; color: var(--ink); cursor: pointer; }
input[type="file"]::file-selector-button:hover { background: var(--surface-3); }
input:disabled, select:disabled, button:disabled { opacity: 0.6; cursor: not-allowed; }
.upload-progress { display: grid; gap: var(--sp-2); }
.upload-progress-text { margin: 0; font-weight: 500; }
form.stack .upload-progress progress { width: 100%; }
form.stack .upload-progress button { justify-self: start; }

button { font: inherit; font-weight: 600; min-height: var(--control-h); padding: 0 var(--sp-4); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: var(--radius); cursor: pointer; }
/* The fade is on hover only, so a change of colour scheme never leaves a button part-way between two colours. */
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); transition: background-color 120ms ease, border-color 120ms ease; }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); font-weight: 500; }
button.secondary:hover { background: var(--surface-3); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.link { background: none; border: 0; min-height: 0; color: var(--accent-text); text-decoration: underline; font-weight: 500; padding: 0; }
button.link:hover { background: none; }
form.inline { display: inline; }
.row-form { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

.notice { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--ok-line); background: var(--ok-soft); color: var(--ok-text); border-radius: var(--radius); margin: 0 0 var(--sp-4); }
.error { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--danger-line); background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); margin: 0 0 var(--sp-4); }
.muted { color: var(--ink-muted); }
.state-Failed { color: var(--danger); font-weight: 600; }
.state-Ready { color: var(--ok-text); font-weight: 600; }
.status { margin: 0; }
/* An empty status line (a live region, so it stays in the page) takes no room: the form's row gap above it is taken back. */
form.stack > .status:empty { margin-top: calc(var(--sp-3) * -1); }
form.stack > .status { overflow-wrap: anywhere; }
progress { appearance: none; -webkit-appearance: none; width: 8rem; height: 8px; border: 0; border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-3); accent-color: var(--accent); }
progress::-webkit-progress-bar { background: var(--surface-3); border-radius: var(--radius-pill); }
progress::-webkit-progress-value { background: var(--accent); border-radius: var(--radius-pill); }
progress::-moz-progress-bar { background: var(--accent); border-radius: var(--radius-pill); }

/* ---- Administration console: side menu, forms, state pills, the shown-once panel, stacked tables on narrow screens ---- */
[hidden] { display: none !important; }
main { max-width: 80rem; }
h3 { font-size: 1rem; font-weight: 600; margin: var(--sp-5) 0 var(--sp-2); }
section + section { margin-top: var(--sp-5); }
.crumbs { margin: 0; color: var(--ink-muted); }
.note { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--surface); border-radius: var(--radius); max-width: 48rem; }

.console { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.side { position: sticky; top: var(--sp-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--sp-3); }
.side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-1); }
.side a { display: block; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-weight: 500; }
.side a:hover { background: var(--surface-3); }
.side a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.side-heading { margin: var(--sp-4) var(--sp-3) var(--sp-1); color: var(--ink-muted); font-size: 0.8125rem; font-weight: 600; }
.console-body { min-width: 0; }

form.stack.wide { max-width: 40rem; }
form.search { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: end; margin: 0 0 var(--sp-4); }
form.search label { display: grid; gap: var(--sp-1); font-weight: 500; }
.check { display: flex; gap: var(--sp-2); align-items: flex-start; font-weight: 400; }
form.stack label.check { display: flex; font-weight: 400; }
.check input { margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0; padding: var(--sp-3) var(--sp-4); display: grid; gap: var(--sp-2); min-width: 0; }
fieldset legend { padding: 0 var(--sp-2); color: var(--ink-muted); font-weight: 600; }
fieldset.ticks { background: var(--surface-2); }
details { margin: 0 0 var(--sp-2); }
summary { cursor: pointer; color: var(--accent-text); font-weight: 500; padding: var(--sp-1) 0; }
summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }
details[open] > summary { margin-bottom: var(--sp-2); }

td.actions { display: table-cell; }
td.actions > a, td.actions > form, td.actions > details { display: inline-block; margin: 0 var(--sp-3) var(--sp-1) 0; vertical-align: top; }
td.actions > details { display: block; }
ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-1); }
/* Pills sit in a div inside the cell (never a flex cell: that breaks the row's border line). */
.pills { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
dd.pills { margin: 0; }
/* A compact, aligned row of actions in a table cell. */
.action-set { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.action-set > form, .action-set > details { margin: 0; }
.action-set > details[open] { flex: 1 0 100%; }
.action-set button { min-height: 30px; padding: 0 var(--sp-3); font-size: 0.8125rem; white-space: nowrap; }
.action-set summary { padding: 0; white-space: nowrap; }
.action-set details[open] > summary { margin-bottom: var(--sp-2); }
td.actions > .action-set { min-width: 11rem; }

/* Storage page: numbers stay on one line, the folder takes room to wrap, rows are tighter. */
table.storage th, table.storage td { padding: var(--sp-2) 10px; }
table.storage td.folder { min-width: 13rem; }
table.storage td:first-child { min-width: 8.5rem; }
td .nw { white-space: nowrap; }

/* The page a failed address gets: a quiet card with a way out. */
.problem-page { max-width: 32rem; margin: var(--sp-6) auto 0; padding: var(--sp-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.problem-page h1 { margin-top: 0; }
.problem-links { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: 0; }
.problem-links a { display: inline-flex; align-items: center; min-height: var(--control-h); padding: 0 var(--sp-4); border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); font-weight: 600; text-decoration: none; }
.problem-links a:hover { background: var(--surface-3); }
.problem-links a:first-child { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.problem-links a:first-child:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
dl.facts, dl.levels { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-2) var(--sp-5); margin: 0 0 var(--sp-4); }
dl.facts dt, dl.levels dt { color: var(--ink-muted); font-weight: 600; }
dl.facts dd, dl.levels dd { margin: 0; }
dl.levels dt { color: var(--ink); }

.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 var(--sp-2); border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink); font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.pill-active { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok-text); }
.pill-expired { background: var(--surface-3); border-color: var(--line-strong); color: var(--ink-muted); }
.pill-withdrawn, .pill-disabled { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.pill-notice, .pill-info { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

/* The shown-once panel: a quiet card, one accent edge, the value in a read-only field with a Copy button. */
.once { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius-lg); padding: var(--sp-5); max-width: 40rem; display: grid; gap: var(--sp-4); box-shadow: var(--shadow); }
.once-note { margin: 0; }
.once-row { display: grid; gap: var(--sp-1); }
.once-row label { font-weight: 600; }
.once-value { display: flex; gap: var(--sp-2); }
.once-value input.secret { flex: 1; min-width: 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; background: var(--surface-2); }

@media (max-width: 960px) {
  .console { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  .side { position: static; }
  .side ul { display: flex; flex-wrap: wrap; }
}

/* Narrow screens (down to 390 px): each table row becomes a stacked card, each cell labelled by its column. */
@media (max-width: 640px) {
  main { padding: var(--sp-4) var(--sp-3); }
  table, tbody, tr, td { display: block; width: 100%; }
  table { border: 0; background: none; }
  thead { position: absolute; left: -9999px; }
  caption { display: block; text-align: left; margin-bottom: var(--sp-2); }
  tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: var(--sp-3); overflow: hidden; }
  td { border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: var(--sp-2); }
  td[data-label]::before { content: attr(data-label); color: var(--ink-muted); font-weight: 600; }
  td.actions { display: block; }
  td.actions::before { display: block; margin-bottom: var(--sp-1); }
  form.stack { padding: var(--sp-4); }
  dl.facts, dl.levels { grid-template-columns: minmax(0, 1fr); gap: var(--sp-1); }
  dl.facts dd, dl.levels dd { margin-bottom: var(--sp-2); }
  .once { padding: var(--sp-4); }
  .once-value { flex-direction: column; }
}

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