/* Facility Checklists — baseline styles. */
:root {
    --bg: #0f1117;
    --panel: #171a21;
    --panel-2: #1f232c;
    --text: #e7ebf0;
    --muted: #8b93a1;
    --accent: #4a9eff;
    --red: #ff5858;
    --orange: #ff9844;
    --yellow: #ffd460;
    --green: #4ade80;
    --blue: #4a9eff;
    --purple: #a78bfa;
    --grey: #6b7280;
    --border: #2a2f3a;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ----- top bar ----- */
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 10px 16px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 12px; flex-wrap: wrap; }
.topbar nav a { padding: 6px 4px; }
.topbar .user { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); flex-wrap: wrap; }
.tz-badge { font-size: 11px; color: var(--muted); background: var(--panel-2); padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border); cursor: help; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px; }
h1 { font-weight: 600; margin: 0 0 12px; font-size: 22px; }
h2 { font-weight: 600; margin: 24px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.muted { color: var(--muted); }
.flash { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.flash-ok    { background: #2d4e35; }
.flash-error { background: #4e2d2d; }
.error { color: var(--red); margin-bottom: 12px; padding: 10px 12px; background: rgba(255,88,88,.08); border-left: 3px solid var(--red); border-radius: 4px; }

/* ----- banners (drafts, info) ----- */
.banner {
    padding: 12px 14px; margin: 12px 0 16px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.banner-info { background: #1c2a3d; border-color: #2d4e7a; }

/* ----- tables ----- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; background: var(--panel); margin-bottom: 24px; min-width: 480px; }
table.data th, table.data td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { background: var(--panel-2); font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.row-actions { white-space: nowrap; }

/* ----- buttons ----- */
.btn {
    display: inline-block; padding: 10px 16px; min-height: 40px;
    background: var(--accent); color: #fff;
    border: 0; border-radius: 4px; cursor: pointer;
    font-size: 14px; line-height: 1.2; text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn-sm { padding: 6px 10px; min-height: 32px; font-size: 12px; }
.btn-muted { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 16px; }

/* ----- pills (status & drafts) ----- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 10px; font-size: 11px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill-sm { padding: 1px 6px; font-size: 10px; margin-left: 4px; }
.pill-overdue       { background: var(--red); color: #fff; }
.pill-due_soon      { background: var(--orange); color: #fff; }
.pill-on_track      { background: #2e6d3f; color: #fff; }
.pill-never         { background: #5a3a3a; color: #fff; }
.pill-event_driven  { background: #2d3a4e; color: #cfe0ff; }
.pill-draft         { background: var(--purple); color: #fff; }

.stat-bar { display: flex; gap: 8px; margin: 8px 0 24px; flex-wrap: wrap; }

/* ----- time ----- */
time.ts { font-variant-numeric: tabular-nums; }
.ts-empty { color: var(--muted); }

/* ----- login ----- */
.login-card { max-width: 380px; margin: 40px auto; padding: 24px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.login-card label { display: block; margin-bottom: 14px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; padding: 12px; font-size: 16px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 4px; }
.login-card button { width: 100%; padding: 12px; font-size: 16px; }

/* ----- checklist form ----- */
.checklist-form fieldset.q { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; margin: 12px 0; }
.checklist-form fieldset.q legend { padding: 0 6px; color: var(--text); font-weight: 500; line-height: 1.4; }
.checklist-form .req { color: var(--red); margin-left: 2px; }
.checklist-form .radios { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.checklist-form .radios label,
.checklist-form .checks label {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 10px; min-height: 40px;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
    cursor: pointer;
    line-height: 1.3;
}
.checklist-form .radios input[type=radio],
.checklist-form .checks input[type=checkbox] {
    width: 20px; height: 20px; flex-shrink: 0;
}
.checklist-form .other-text {
    flex: 1 1 200px; padding: 10px; min-height: 40px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px; min-width: 150px;
    font: inherit;
}
.checklist-form .checks { display: flex; flex-direction: column; gap: 8px; }
.checklist-form .checks label { align-items: flex-start; }
.checklist-form input[type=text],
.checklist-form input[type=email],
.checklist-form input[type=password],
.checklist-form textarea {
    width: 100%; padding: 10px; min-height: 40px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px; font: inherit;
    -webkit-appearance: none; appearance: none;
}
.checklist-form .scale { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; }
.checklist-form .scale-step { padding: 8px 10px; min-height: 40px; }
.checklist-form .scale-end { color: var(--muted); font-size: 12px; flex-basis: 100%; }
.checklist-form .scale-end:last-of-type { text-align: right; }

.checklist-form table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.checklist-form table.grid th, .checklist-form table.grid td {
    padding: 8px; border: 1px solid var(--border); text-align: center;
}
.checklist-form table.grid thead th { background: var(--panel-2); font-size: 11px; }
.checklist-form table.grid tbody th { background: var(--panel-2); text-align: left; }
.checklist-form table.grid input[type=checkbox] { width: 22px; height: 22px; }

.form-actions { margin-top: 20px; display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(180deg, transparent 0%, var(--bg) 30%); }

/* Public form: identity inputs sit in a small grid */
.public-id { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.public-id label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.public-id label:nth-child(3) { grid-column: 1 / -1; }
@media (max-width: 480px) { .public-id { grid-template-columns: 1fr; } .public-id label:nth-child(3) { grid-column: auto; } }

/* ----- preview ----- */
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.preview-list { list-style: decimal; padding-left: 24px; margin: 12px 0; }
.preview-q { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin: 8px 0; }
.preview-q-label { font-weight: 500; }
.preview-q-options { font-size: 13px; margin-top: 4px; }
.preview-options { margin: 4px 0 0 0; padding-left: 18px; color: var(--muted); }
.preview-grid-wrap { overflow-x: auto; }
.preview-grid-wrap table.grid { width: 100%; min-width: 480px; border-collapse: collapse; font-size: 12px; }
.preview-grid-wrap table.grid th, .preview-grid-wrap table.grid td { padding: 4px 6px; border: 1px solid var(--border); text-align: center; }

/* ----- report view ----- */
.report-header { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 16px 18px; margin-bottom: 16px; }
.report-header dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 13px; }
.report-header dl.meta dt { color: var(--muted); }
.report-q { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.report-q-label { color: var(--muted); font-size: 13px; }
.report-q-value .ans-yes { color: var(--green); font-weight: 600; }
.report-q-value .ans-no  { color: var(--muted); }
.report-q-value .ans-other { color: var(--orange); }
.report-q-value table.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-q-value table.grid th, .report-q-value table.grid td { padding: 4px 6px; border: 1px solid var(--border); text-align: center; }
.report-q-value ul.ans-checks { margin: 0; padding-left: 20px; }
.report-q-value .ans-long { white-space: pre-wrap; }
.toolbar { margin-top: 12px; }

/* ----- stats matrix ----- */
.stats-matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stats-matrix { font-size: 12px; }
.stats-matrix th { white-space: nowrap; }
.stats-matrix td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================================
 * Mobile breakpoints
 * ========================================================================== */
@media (max-width: 700px) {
    body { font-size: 15px; }
    main { padding: 14px 12px; }
    h1 { font-size: 20px; }

    .topbar { padding: 8px 12px; gap: 10px; }
    .topbar .user { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }

    /* Stack report rows */
    .report-q { grid-template-columns: 1fr; gap: 4px; padding: 10px 0; }
    .report-q-label { color: var(--text); font-weight: 500; }
    .report-header dl.meta { grid-template-columns: 1fr; }
    .report-header dl.meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
    .report-header dl.meta dd { margin: 0; }

    /* Form: bigger tap targets, tidier spacing */
    .checklist-form fieldset.q { padding: 12px 14px; }
    .checklist-form .radios { gap: 8px; }
    .checklist-form .radios label,
    .checklist-form .checks label { padding: 10px 12px; min-height: 44px; flex: 1 1 calc(50% - 8px); }
    .checklist-form .radios label.scale-step { flex: 0 0 auto; min-width: 48px; justify-content: center; }
    .checklist-form .other-text { flex-basis: 100%; }

    .form-actions { gap: 6px; }
    .form-actions .btn { flex: 1 1 calc(50% - 6px); text-align: center; }

    /* Tables with min-width keep their layout but scroll horizontally */
    table.data { min-width: 0; font-size: 13px; }
    table.data th, table.data td { padding: 8px 6px; }

    /* Hide secondary columns on very narrow screens to keep dashboard scannable */
    table.data .row-actions .btn { padding: 6px 10px; min-height: 32px; font-size: 12px; }
}

@media (max-width: 480px) {
    .checklist-form .radios label,
    .checklist-form .checks label { flex: 1 1 100%; }
    .stat-bar .pill { font-size: 10px; }
    h2 { font-size: 13px; }
}

/* Hide the cancel link on phones to save space — Submit + Save Draft are the real actions */
@media (max-width: 480px) {
    .form-actions a.btn-muted[href$="/list"] { display: none; }
}
