/* Panel styles, based on the mock-ups in docs/assets/mock_0*.html.
   WCAG 2.1 AA: text colours keep at least 4.5:1 contrast on their backgrounds,
   focus is always visible, layout works from 320 px (AGENTS.md, section 5). */

:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1d2330; --muted: #5f6b7a;
  --border: #d6dae1; --primary: #1f5eff; --primary-ink: #fff;
  --danger: #c62828; --danger-bg: #fdecea; --ok: #176b33; --ok-bg: #e8f5ec;
  --info: #7a5a00; --info-bg: #fff6d6;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
main:focus { outline: none; }

/* Accessibility helpers */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
                   overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 100; padding: 8px 12px;
             background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.skip-link:focus { top: 8px; }

/* Header */
header.app { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
             padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
header.app .brand { font-weight: 700; }
header.app .crumb { color: var(--muted); }
header.app nav { display: flex; gap: 12px; flex-wrap: wrap; }
header.app nav a[aria-current="page"] { font-weight: 600; text-decoration: none; }
header.app .right { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
header.app .right a, header.app .right button.link { font-size: 14px; }
header.app .role { font-size: 13px; padding: 3px 10px; border-radius: 999px;
                   background: #eef2ff; color: #2b3a8f; }
form.inline { display: inline; margin: 0; }

/* Layout */
main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
main.narrow { max-width: 860px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 20px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border);
                          border-radius: 6px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
.error, .errorlist { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.errorlist { list-style: none; padding: 0; }

/* Buttons */
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--border);
         background: var(--surface); color: var(--text); padding: 8px 14px; min-height: 40px; }
button:hover { filter: brightness(0.96); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
a.button.danger-text { color: var(--danger); }
button.ghost { border-style: dashed; color: var(--primary); }
button.link { border: none; background: none; padding: 0; min-height: 0; color: var(--primary);
              text-decoration: underline; }
button.copy { padding: 4px 10px; min-height: 32px; font-size: 13px; white-space: nowrap; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.actions .left { margin-right: auto; }

/* Links styled as buttons (navigation that looks like an action) */
a.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px;
           padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
           background: var(--surface); color: var(--text); text-decoration: none; }
a.button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.full { width: 100%; }
.center { text-align: center; margin: 16px 0 0; }
.actions.left-aligned { justify-content: flex-start; margin: 0 0 12px; }
.label { display: block; font-weight: 600; margin-bottom: 4px; }

/* Sign-in and MFA */
.secret { font-family: var(--mono); letter-spacing: 1px; overflow-wrap: anywhere; }
.qr { display: flex; justify-content: center; margin: 12px 0 16px; }
.qr svg { width: 200px; height: auto; max-width: 100%; background: #fff; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 0 0 16px; padding: 12px;
         list-style: none; background: var(--bg); border-radius: 6px; font-family: var(--mono); }

/* Campaign form: link rows (mock-up 1) */
fieldset.links { border: none; padding: 0; margin: 0 0 16px; min-width: 0; }
fieldset.links legend { font-size: 16px; font-weight: 600; padding: 0; margin-bottom: 4px; }
.links-head, .link-row { display: grid; grid-template-columns: minmax(140px, 200px) 1fr 40px;
                         gap: 8px; align-items: start; }
.links-head { color: var(--muted); font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.link-row { margin-bottom: 8px; }
button.icon { padding: 0; width: 40px; min-height: 40px; }
.rows-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

/* Messages and states */
.messages { margin-bottom: 16px; }
.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; }
.banner.success, .banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.info, .banner.warning { background: var(--info-bg); color: var(--info); }
.banner.error, .banner.err { background: var(--danger-bg); color: var(--danger); }
.pill { font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
        background: var(--ok-bg); color: var(--ok); white-space: nowrap; }
.pill.off { background: #e9ebef; color: var(--muted); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; margin: 0; }
.denied { text-align: center; padding: 64px 16px; }
.denied .big { font-size: 48px; }
.denied p { font-size: 18px; margin: 16px 0 24px; }

/* Tables: scroll inside the wrapper instead of the whole page */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono, td.url { font-family: var(--mono); }
td.url { overflow-wrap: anywhere; }

/* Pagination */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px;
         flex-wrap: wrap; padding-top: 12px; }
.pager .disabled { color: var(--muted); }

/* Modal dialogs */
dialog { border: none; border-radius: var(--radius); padding: 24px; max-width: 480px;
         width: calc(100% - 32px); color: var(--text); }
dialog::backdrop { background: rgba(20, 24, 33, .5); }

@media (max-width: 600px) {
  main { margin: 16px auto; }
  .card { padding: 16px; }
  header.app .right { margin-left: 0; width: 100%; }
  .actions { justify-content: stretch; }
  .actions button { flex: 1; }
  /* Narrow tables: mark less important columns with .optional to hide them */
  th.optional, td.optional { display: none; }
  /* Link rows stack: platform on its own line, tag and the remove button below */
  .links-head { display: none; }
  .link-row { grid-template-columns: 1fr 40px; padding: 10px; border: 1px solid var(--border);
              border-radius: 6px; }
  .link-row > select { grid-column: 1 / -1; }
  .actions a.button { flex: 1; }
}

/* Administration module (mock-up 2): tabs, toolbar, row actions */
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
nav.tabs a { padding: 8px 12px; border-bottom: 3px solid transparent; color: var(--muted); text-decoration: none; }
nav.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar form.search { display: flex; gap: 8px; flex: 1 1 280px; max-width: 480px; }
button.small, a.button.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
button.danger-text { color: var(--danger); }
button:disabled { cursor: not-allowed; color: var(--muted); filter: none; }
td.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.small-text { font-size: 12px; }
form.narrow-form { max-width: 640px; }
form.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; margin-bottom: 8px; }
form.filters .actions, form.filters .banner { grid-column: 1 / -1; }
td.details { overflow-wrap: anywhere; font-size: 13px; }
/* Statistics (apps.stats; mock-up docs/assets/mock_03_stats_dashboard.html) */
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
            flex-wrap: wrap; margin-bottom: 16px; }
.titlebar h1 { margin: 0; }
.titlebar .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.back { margin: 0 0 8px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;
        margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
       padding: 14px 16px; }
.kpi .lbl { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
            color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .val.small { font-size: 20px; overflow-wrap: anywhere; }
.kpi .sub { font-size: 13px; color: var(--muted); }
details.tip { display: inline-block; position: relative; text-transform: none; letter-spacing: 0; }
details.tip summary { list-style: none; cursor: pointer; width: 20px; height: 20px; border-radius: 50%;
                      border: 1px solid var(--border); text-align: center; line-height: 18px;
                      font-size: 12px; color: var(--muted); }
details.tip summary::-webkit-details-marker { display: none; }
details.tip p { position: absolute; z-index: 10; left: 0; top: 26px; width: min(320px, 80vw);
                margin: 0; padding: 10px 12px; background: var(--text); color: #fff; border-radius: 6px;
                font-size: 13px; font-weight: 400; line-height: 1.45; }
figure.chart { margin: 0; }
figure.chart svg { width: 100%; height: auto; display: block; }
figure.chart .bar { fill: var(--primary); }
figure.chart .bar:hover { fill: #1747c2; }
figure.chart .grid { stroke: var(--border); stroke-width: 1; }
figure.chart .axis { fill: var(--muted); font-size: 11px; }
.chart-data { margin-top: 8px; font-size: 13px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chips a { padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; }
.chips a[aria-current="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 16px;
           margin: 16px 0; }
dl.facts dt { font-weight: 600; font-size: 13px; }
dl.facts dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
tr.selected td { background: #eef2ff; }
