/* AMI Test Desk — plain CSS, system fonts, light and dark themes.
   Every colour is a variable on :root. The pairs used for text were chosen to pass WCAG AA
   (4.5:1 for body text, 3:1 for large text and control borders) in both themes. */

:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1b1f24;
    --muted: #57606a;
    --border: #d5dae1;
    --border-strong: #8b949e;
    --accent: #2456c7;
    --accent-hover: #1d47a8;
    --on-accent: #ffffff;
    --focus: #2456c7;

    --env-dev: #1a7f37;
    --env-test: #8a5a00;
    --env-stage: #c2212d;
    --on-env: #ffffff;

    --error-bg: #fdeceb;
    --error-border: #f1b7b3;
    --error-text: #8e1519;
    --success-bg: #e6f6ea;
    --success-border: #a6dcb4;
    --success-text: #135c28;
    --info-bg: #eef3fd;
    --info-border: #c3d3f5;
    --info-text: #1d3f8f;

    --radius: 10px;
    --radius-small: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --text: #e8ecf1;
    --muted: #a3acb8;
    --border: #2f3640;
    --border-strong: #6e7681;
    --accent: #6c9cff;
    --accent-hover: #8fb3ff;
    --on-accent: #0b1220;
    --focus: #8fb3ff;

    --env-dev: #3fb950;
    --env-test: #e3b341;
    --env-stage: #ff7b72;
    --on-env: #0b1220;

    --error-bg: #3a1618;
    --error-border: #6e2a2d;
    --error-text: #ffb4ae;
    --success-bg: #11301c;
    --success-border: #2a5c3a;
    --success-text: #8ce0a4;
    --info-bg: #15233f;
    --info-border: #2c4577;
    --info-text: #b8cdff;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 980px;
    margin: 0 auto;
    padding: 20px 20px 8px;
}

.brand {
    font-size: 18px;
    font-weight: 650;
    letter-spacing: -.01em;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.user {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.logout-form { margin: 0; }

/* ---------- layout ---------- */

.page {
    max-width: 980px;
    margin: 0 auto;
    padding: 8px 20px 48px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-top: 18px;
}

.card-title {
    font-size: 16px;
    font-weight: 620;
    margin: 0;
}

.card-lead {
    color: var(--muted);
    margin: 4px 0 16px;
}

.row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 200px;
    min-width: 0;
}

.field-grow { flex: 3 1 280px; }

.field label, .field-label {
    font-size: 13px;
    font-weight: 560;
    color: var(--text);
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 8px 0 0;
}

/* ---------- controls ---------- */

input, select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);
    padding: 9px 12px;
    min-height: 42px;
    width: 100%;
    min-width: 0;
}

input::placeholder { color: var(--muted); }

input:focus-visible, select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

.btn {
    font: inherit;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 18px;
    border-radius: var(--radius-small);
    border: 1px solid transparent;
    background: var(--accent);
    color: var(--on-accent);
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: .65; cursor: not-allowed; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
    min-height: 36px;
    padding: 6px 12px;
    font-weight: 560;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-block { width: 100%; }

.link-button {
    font: inherit;
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}

/* A spinner inside a busy button, or beside a running step. */
.spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    display: inline-block;
    animation: spin .8s linear infinite;
    flex: none;
}
.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- theme toggle ---------- */

.theme-toggle {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    padding: 0;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- environment ---------- */

.env-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 10px;
    border: 0;
    padding: 0;
}

.env-bar legend { float: left; padding: 0; margin-right: 4px; }

.segmented {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
}

.segmented input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    min-height: 0;
}

.segmented label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 18px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
}

.segmented label .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.segmented label[data-env="DEV"] .dot { color: var(--env-dev); }
.segmented label[data-env="TEST"] .dot { color: var(--env-test); }
.segmented label[data-env="STAGE"] .dot { color: var(--env-stage); }

.segmented input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

.segmented input:checked + label[data-env="DEV"] { background: var(--env-dev); color: var(--on-env); }
.segmented input:checked + label[data-env="TEST"] { background: var(--env-test); color: var(--on-env); }
.segmented input:checked + label[data-env="STAGE"] { background: var(--env-stage); color: var(--on-env); }
.segmented input:checked + label .dot { color: var(--on-env); }

.env-now {
    font-size: 13px;
    color: var(--muted);
}
.env-now strong { color: var(--text); }

/* The chosen environment tints every card's edge, so a change is always made on purpose. */
body[data-env="DEV"] .card.tool { border-top: 4px solid var(--env-dev); }
body[data-env="TEST"] .card.tool { border-top: 4px solid var(--env-test); }
body[data-env="STAGE"] .card.tool { border-top: 4px solid var(--env-stage); }

.env-pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    color: var(--on-env);
    vertical-align: 1px;
}
.env-pill[data-env="DEV"] { background: var(--env-dev); }
.env-pill[data-env="TEST"] { background: var(--env-test); }
.env-pill[data-env="STAGE"] { background: var(--env-stage); }

/* ---------- messages ---------- */

.alert {
    border: 1px solid;
    border-radius: var(--radius-small);
    padding: 12px 14px;
    margin: 14px 0 0;
}
.alert p { margin: 0; }
.alert p + p { margin-top: 4px; font-size: 13px; }

.alert-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-text); }

.result:empty { display: none; }

/* ---------- OTP result ---------- */

.otp {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.otp-code {
    font-family: var(--mono);
    font-size: 30px;
    font-weight: 650;
    letter-spacing: .18em;
}

.otp-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    font-size: 13px;
    color: var(--muted);
}

.tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}
.tag-good { border-color: var(--success-border); color: var(--success-text); background: var(--success-bg); }
.tag-bad { border-color: var(--error-border); color: var(--error-text); background: var(--error-bg); }

/* ---------- confirm panel ---------- */

.confirm {
    margin-top: 16px;
    border: 1px solid var(--info-border);
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
}

.confirm-title { margin: 0 0 4px; font-size: 15px; }

.confirm-section { margin-top: 14px; }
.confirm-section h4 {
    margin: 0 0 6px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.confirm-section ul { margin: 0; padding-left: 20px; }
.confirm-section li { margin: 2px 0; }
.none { color: var(--muted); margin: 0; }

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
}

/* ---------- step checklist ---------- */

.checklist {
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
}

.checklist li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}
.checklist li:first-child { border-top: 0; }

.step-icon {
    flex: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    margin-top: 1px;
}
.step-ok .step-icon { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.step-failed .step-icon { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }
.step-running .step-icon { color: var(--accent); }
.step-skipped .step-icon { color: var(--muted); border: 1px dashed var(--border-strong); }
.step-skipped { color: var(--muted); }

.step-name { font-weight: 600; }
.step-detail { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- login ---------- */

.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.auth-top {
    display: flex;
    justify-content: flex-end;
    padding: 16px 20px 0;
}

.auth-main {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 6vh 16px 48px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.auth-card h1 { margin: 0; font-size: 20px; font-weight: 650; }
.auth-card .card-lead { margin-bottom: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .field { flex: none; }

.code-input {
    font-family: var(--mono);
    font-size: 22px;
    letter-spacing: .3em;
    text-align: center;
}

.auth-links {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    font-size: 14px;
}
.auth-links form { display: inline; }

/* ---------- narrow screens ---------- */

@media (max-width: 560px) {
    body { font-size: 15px; }
    .topbar { padding: 16px 16px 4px; }
    .page { padding: 4px 16px 40px; }
    .card { padding: 18px 16px; }
    .row { flex-direction: column; align-items: stretch; }
    .row .btn { width: 100%; }
    .field, .field-grow { flex-basis: auto; }
    .segmented { width: 100%; }
    .segmented label { flex: 1; justify-content: center; padding: 7px 8px; }
    .env-bar { gap: 8px; }
    .env-bar legend { float: none; width: 100%; }
    .otp-code { font-size: 26px; }
    .auth-card { padding: 22px 18px; }
    .actions .btn { flex: 1 1 100%; white-space: normal; text-align: center; }
    .topbar-actions { width: 100%; justify-content: flex-start; }
    .user { flex: 1 1 100%; }
}
