:root {
    --teal-900: #003f3f;
    --teal-700: #005d5d;
    --teal-500: #2f9478;
    --green: #48b093;
    --bg: #f3f6f5;
    --surface: #ffffff;
    --border: #dde5e3;
    --text: #1d2a28;
    --muted: #5d6b68;
    --warn-bg: #fff6e0;
    --warn-border: #f0cf7a;
    --warn-text: #6b4d00;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --ok-bg: #e7f5ef;
    --ok-text: #135c3f;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 40, 36, 0.06), 0 2px 8px rgba(16, 40, 36, 0.04);
    color-scheme: light;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 17px; }
p { margin: 0 0 10px; }
a { color: var(--teal-700); }
code, kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    background: #eef3f2;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0 5px;
    white-space: nowrap;
}
[hidden] { display: none !important; }

/* ── Top bar ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 24px;
    background: var(--teal-700);
    color: #fff;
}
.brand { display: flex; flex-direction: column; }
.brand strong { font-size: 17px; letter-spacing: 0.2px; }
.brand span { font-size: 12.5px; opacity: 0.8; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }

/* ── Cards & layout ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.layout {
    display: grid;
    grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    margin-bottom: 20px;
}
.steps { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.step h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.num {
    display: inline-grid;
    place-items: center;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--teal-700);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    flex: none;
}

label { display: block; font-weight: 600; font-size: 13.5px; margin: 12px 0 6px; }
label:first-of-type { margin-top: 0; }
input[type="text"], input[type="email"], input[type="password"] {
    width: 100%;
    font: inherit;
    padding: 9px 11px;
    border: 1px solid #c5d1ce;
    border-radius: 7px;
    background: #fff;
    color: var(--text);
}
input:focus-visible, button:focus-visible, summary:focus-visible, .file-pick:focus-within {
    outline: 3px solid rgba(47, 148, 120, 0.35);
    outline-offset: 1px;
}
.hint { color: var(--muted); font-size: 13.5px; }

/* File picker */
.file-pick {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1.5px dashed #b8c8c4;
    border-radius: 8px;
    padding: 12px 14px;
    background: #fafcfb;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.file-pick:hover, .file-pick.drag { border-color: var(--teal-500); background: #f1f8f5; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-pick .icon {
    flex: none;
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 7px;
    background: #e3efec;
    color: var(--teal-700);
    font-weight: 700;
    font-size: 11px;
}
.file-pick .name { font-weight: 600; overflow-wrap: anywhere; }
.file-pick .sub { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.file-pick.has-file { border-style: solid; border-color: var(--teal-500); background: #f4faf8; }

/* Buttons */
.btn {
    font: inherit;
    font-weight: 600;
    border-radius: 8px;
    padding: 10px 16px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--teal-700); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--teal-900); }
.btn-secondary { background: #fff; color: var(--teal-700); border-color: var(--teal-700); }
.btn-secondary:hover:not(:disabled) { background: #eef6f4; }
.btn-danger { background: #fff; color: var(--danger); border-color: #e3a6a1; }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255, 255, 255, 0.45); padding: 7px 12px; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn-link { background: none; border: none; color: var(--teal-700); padding: 0; font-weight: 600; text-decoration: underline; cursor: pointer; font: inherit; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.btn-wide { width: 100%; }

/* Badges */
.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 999px;
    background: #e8eeed;
    color: var(--muted);
    white-space: nowrap;
}
.badge-live { background: #dff0ea; color: var(--teal-700); }
.badge-test { background: #e9e7f7; color: #4b3f99; }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-bad { background: var(--danger-bg); color: var(--danger); }

/* Notes & messages */
.notes { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.note {
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13.5px;
    border: 1px solid var(--border);
    background: #f7faf9;
}
.note-ok { background: var(--ok-bg); border-color: #bfe3d3; color: var(--ok-text); }
.note-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.note-bad { background: var(--danger-bg); border-color: #f1b8b3; color: var(--danger); }
.note ul { margin: 4px 0 0; padding-left: 18px; }
.loading { color: var(--muted); font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.spinner {
    width: 14px; height: 14px;
    border: 2px solid #c8d6d3;
    border-top-color: var(--teal-700);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: #f6f9f8; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }

/* Guide */
details.guide { margin-top: 16px; border: 1px solid var(--border); border-radius: 8px; background: #fafcfb; }
details.guide > summary { cursor: pointer; padding: 10px 12px; font-weight: 600; color: var(--teal-700); }
.guide-body { padding: 0 14px 12px; font-size: 13.5px; }
.guide-body h3 { font-size: 13.5px; margin: 14px 0 6px; }
.guide-body ul { margin: 0; padding-left: 18px; }
.guide-body li { margin-bottom: 4px; }
.mini-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.mini-table th, .mini-table td { border: 1px solid var(--border); padding: 5px 7px; text-align: left; vertical-align: top; }
.mini-table th { background: #eef4f2; font-weight: 600; }
.table-scroll { overflow-x: auto; }

/* Test list */
.test-list { list-style: none; margin: 0 0 4px; padding: 0; font-size: 13.5px; }
.test-list li { padding: 4px 0; border-bottom: 1px solid #edf1f0; overflow-wrap: anywhere; }
.test-list li:last-child { border-bottom: none; }
.test-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px; margin-bottom: 6px; }
.test-row input { padding: 7px 8px; font-size: 13.5px; }
.icon-btn { border: 1px solid var(--border); background: #fff; border-radius: 7px; width: 34px; cursor: pointer; color: var(--muted); font-size: 16px; }
.icon-btn:hover { color: var(--danger); border-color: #e3a6a1; }

/* Preview */
.preview-pane { position: sticky; top: 16px; padding: 0; overflow: hidden; min-width: 0; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: inline-flex; background: #edf2f1; border-radius: 8px; padding: 3px; gap: 2px; }
.tabs button {
    font: inherit; font-size: 13px; font-weight: 600;
    border: none; background: transparent; color: var(--muted);
    padding: 6px 11px; border-radius: 6px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: #fff; color: var(--teal-700); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.preview-meta { padding: 10px 18px; border-bottom: 1px solid var(--border); font-size: 13.5px; background: #fbfcfc; }
.preview-meta div { overflow-wrap: anywhere; }
.preview-meta .label { color: var(--muted); display: inline-block; min-width: 64px; }
.preview-frame { display: block; width: 100%; height: 72vh; min-height: 520px; border: 0; background: #f4f7f6; }
.preview-empty { padding: 60px 24px; text-align: center; color: var(--muted); }

/* Job card */
.job-card { margin-bottom: 20px; }
.job-card.is-running { border-color: #9fd3c2; }
.job-card.is-paused { border-color: var(--warn-border); background: #fffdf6; }
.job-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.job-head h2 { font-size: 16px; overflow-wrap: anywhere; }
.progress { height: 10px; background: #e5eceb; border-radius: 999px; overflow: hidden; margin: 10px 0 8px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--teal-500), var(--green)); border-radius: 999px; transition: width 0.4s; }
.job-line { font-size: 14px; color: var(--muted); }
.job-message { font-size: 14px; margin-top: 6px; }
.results { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.results .badge { white-space: normal; line-height: 1.4; padding: 4px 10px; }

/* Recent table */
.recent { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 12px; }
.recent th, .recent td { padding: 8px 10px; border-bottom: 1px solid #edf1f0; text-align: left; vertical-align: top; }
.recent th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.3px; }
.recent td.num-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.recent .subject-cell { overflow-wrap: anywhere; min-width: 160px; }

/* Dialogs */
dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    width: min(520px, calc(100vw - 32px));
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    color: var(--text);
}
dialog::backdrop { background: rgba(10, 30, 28, 0.45); }
.dialog-body { padding: 22px; }
.dialog-body h2 { margin-bottom: 12px; font-size: 19px; }
.dialog-body dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0; font-size: 14px; }
.dialog-body dt { color: var(--muted); }
.dialog-body dd { margin: 0; overflow-wrap: anywhere; }
.choice { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-top: 8px; cursor: pointer; font-weight: 400; }
.choice input { margin-top: 3px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: #f8faf9; flex-wrap: wrap; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { font-size: 21px; margin-bottom: 4px; color: var(--teal-700); }
.login-card p { color: var(--muted); }
.error-text { color: var(--danger); font-size: 13.5px; min-height: 20px; margin-top: 8px; }

@media (max-width: 960px) {
    .layout { grid-template-columns: 1fr; }
    .preview-pane { position: static; }
    .preview-frame { height: 70vh; min-height: 420px; }
}
@media (max-width: 560px) {
    main { padding: 16px 16px 40px; }
    .topbar { padding: 12px 16px; flex-wrap: wrap; }
    .brand span { display: none; }
    .topbar-right { flex: 1; }
    .card { padding: 16px; }
    .test-row { grid-template-columns: 1fr 1fr auto; }
    .test-row input[data-field="email"] { grid-column: 1 / -1; }
    .recent .hide-sm { display: none; }
}
