/* QCAP administration panel. Colors follow the desktop app (Qcap.Desktop/App.xaml and its dark palette in
   MainWindow.ToggleTheme). The panel uses no scripts and no inline styles; the CSP forbids both. */
:root {
  --canvas: #f3f6f8;
  --surface: #ffffff;
  --rail: #eaf0f3;
  --text: #162e3e;
  --muted: #5b6e7e;
  --line: #dce5ea;
  --accent: #087e83;
  --accent-hover: #066a6e;
  --accent-text: #ffffff;
  --link: #076d72;
  --soft: #e7f3f2;
  --selection: #d5edee;
  --input: #fffdf4;
  --input-border: #758c96;
  --focus: #087e83;
  --error: #fdeded;
  --error-text: #a6293f;
  --warning: #fff4d6;
  --warning-text: #6b4a00;
  --success: #ecf7f2;
  --success-text: #146346;
  --neutral: #edf1f4;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #142531;
    --surface: #1c303e;
    --rail: #182b38;
    --text: #e5eef3;
    --muted: #aec1cc;
    --line: #334a58;
    --accent: #137e84;
    --accent-hover: #17939a;
    --accent-text: #ffffff;
    --link: #7fdcd7;
    --soft: #23434c;
    --selection: #365967;
    --input: #263e4a;
    --input-border: #789daa;
    --focus: #63d4cf;
    --error: #4a2c36;
    --error-text: #ffafbd;
    --warning: #393b30;
    --warning-text: #f1dc9a;
    --success: #22453e;
    --success-text: #a6e3c8;
    --neutral: #2a3f4c;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
}

::selection { background: var(--selection); color: var(--text); }

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main[tabindex="-1"]:focus { outline: none; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 10;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.who .role { padding: 1px 8px; border-radius: 999px; background: var(--soft); color: var(--text); font-size: 12px; font-weight: 600; }

/* Signed-out pages: one centered form */
main.center { display: flex; justify-content: center; padding: 48px 16px; }

/* Signed-in shell: navigation rail and content */
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: calc(100vh - 56px); }

.rail { padding: 16px 12px; background: var(--rail); border-right: 1px solid var(--line); }
.rail ul { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.rail a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.rail a:hover { background: var(--soft); }
.rail a[aria-current="page"] { background: var(--selection); font-weight: 600; }

.content { width: 100%; max-width: 1240px; padding: 28px 32px 48px; }

/* Headings and page structure */
h1 { margin: 0 0 8px; font-size: 24px; font-weight: 600; line-height: 1.25; }
h2 { margin: 32px 0 10px; font-size: 18px; font-weight: 600; line-height: 1.3; }
h3 { margin: 20px 0 8px; font-size: 15px; font-weight: 600; }
.lead { margin: 0 0 24px; color: var(--muted); }
.muted { color: var(--muted); }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-header h1 { margin-bottom: 4px; }
.page-header .lead { margin-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.breadcrumb { margin: 0 0 6px; font-size: 14px; }

.section { margin-top: 28px; padding: 20px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.section > h2:first-child { margin-top: 0; }

.card {
  width: 100%;
  max-width: 460px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.card.wide { max-width: 640px; }

/* Summary figures on the dashboard: compact, read in one line */
.summary { display: flex; flex-wrap: wrap; gap: 10px 36px; margin: 0; padding: 16px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.summary div { display: flex; flex-direction: column-reverse; }
.summary dt { color: var(--muted); font-size: 13px; }
.summary dd { margin: 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Definition lists for record details */
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0 0 8px; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
table.data tbody tr:hover { background: var(--canvas); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }
table.data .row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; justify-content: flex-end; }
table.data .row-actions select { width: auto; min-height: 32px; padding: 4px 8px; font-size: 14px; }
table.data td.code, .code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
table.data td.code { white-space: nowrap; }
table.data td.long { min-width: 18rem; max-width: 32rem; white-space: normal; overflow-wrap: anywhere; }
dd.code { overflow-wrap: anywhere; }
.empty { margin: 8px 0 0; padding: 20px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); text-align: center; }

/* Status badges: text always states the status; color only supports it */
.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--neutral);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
}
.badge.good { background: var(--success); color: var(--success-text); }
.badge.wait { background: var(--warning); color: var(--warning-text); }
.badge.bad { background: var(--error); color: var(--error-text); }

/* Forms */
.field { margin-bottom: 18px; }
label, .label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.hint { margin: -2px 0 6px; color: var(--muted); font-size: 13px; }
fieldset { margin: 0 0 18px; padding: 0; border: 0; }
legend { margin-bottom: 6px; padding: 0; font-weight: 600; font-size: 14px; }
.choice { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-weight: 400; }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

input[type="email"], input[type="password"], input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); }
input[readonly] { background: var(--soft); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"], .input-validation-error { border-color: var(--error-text); }
.form-narrow { max-width: 520px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 0 0 16px; }
.filters .field { flex: 1 1 180px; margin: 0; }
.filters .field.wide { flex-basis: 260px; }
.filters label { font-size: 13px; }
.filters input, .filters select { min-height: 38px; padding: 6px 10px; }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 20px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button:active { transform: translateY(1px); }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.button.full { width: 100%; }
.button.secondary { background: transparent; color: var(--link); border-color: var(--input-border); }
.button.secondary:hover { background: var(--soft); }
.button.danger { background: transparent; color: var(--error-text); border-color: var(--error-text); }
.button.danger:hover { background: var(--error); }
.button.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.filters .button { min-height: 38px; }
.link-button { padding: 0; border: 0; background: none; color: var(--link); font: inherit; text-decoration: underline; white-space: nowrap; cursor: pointer; }
form.inline { display: inline; }
table.data .number { text-align: right; font-variant-numeric: tabular-nums; }
.hash { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; font-size: 12px; word-break: break-all; }
.document { max-width: 80ch; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
textarea.document-input { min-height: 320px; font-family: inherit; line-height: 1.5; }
input[type="file"] { display: block; width: 100%; padding: 8px 0; font: inherit; color: var(--text); }
input[type="file"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Disclosure for confirmations: the form opens in place, no modal */
details.confirm { display: inline-block; }
details.confirm > summary { list-style: none; }
details.confirm > summary::-webkit-details-marker { display: none; }
details.confirm[open] { display: block; flex-basis: 100%; }
details.confirm .confirm-body { margin-top: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
details.confirm .confirm-body p { margin-top: 0; }

/* Messages */
.alert { margin: 0 0 18px; padding: 12px 14px; border-radius: 6px; background: var(--error); color: var(--error-text); }
.alert ul { margin: 0; padding-left: 18px; }
.alert:empty, .validation-summary-valid { display: none; }
.notice { margin: 0 0 18px; padding: 12px 14px; border-radius: 6px; background: var(--success); color: var(--success-text); }
.warning { margin: 0 0 18px; padding: 12px 14px; border-radius: 6px; background: var(--warning); color: var(--warning-text); }
.field-error { display: block; margin-top: 4px; color: var(--error-text); font-size: 14px; }

.secondary-links { margin-top: 20px; font-size: 14px; }
.secondary-links a + a { margin-left: 16px; }

/* Paging */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: 14px; }
.pager ul { display: flex; gap: 8px; margin: 0; padding: 0; list-style: none; }

/* Account security and enrollment */
.key, .codes { font-family: Consolas, "Cascadia Mono", monospace; }
.key { display: block; margin: 8px 0 16px; padding: 12px; background: var(--soft); border-radius: 6px; font-size: 18px; letter-spacing: 1px; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; margin: 16px 0 24px; padding: 16px; background: var(--soft); border-radius: 6px; font-size: 16px; list-style: none; }
.uri { font-size: 13px; color: var(--muted); word-break: break-all; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .rail ul { flex-direction: row; flex-wrap: nowrap; }
  .rail a { white-space: nowrap; }
  .content { padding: 20px 16px 40px; }
  .section { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
}

@media (max-width: 520px) {
  .topbar { padding: 10px 16px; }
  .who span.name { display: none; }
  main.center { padding: 24px 16px; }
  .card { padding: 24px 18px; }
  .codes { grid-template-columns: 1fr; }
  dl { grid-template-columns: 1fr; gap: 2px 0; }
  dd { margin-bottom: 8px; }
}

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