/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: #1f2937;
    background: #f5f7fa;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; color: #111827; }
.container { max-width: 960px; margin: 0 auto; padding: 0 1rem; }
.muted { color: #6b7280; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 3px; font-size: 0.92em; }

/* ---------- Public site header ---------- */
:root { --brand: #0f172a; }
.site-header {
    background: var(--brand);
    color: #f1f5f9;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.site-header .site-title {
    color: #f8fafc;
    font-size: 1.25rem;
    margin: 0;
}
.site-header .site-title a {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .65rem;
}
.site-header .site-title a:hover { text-decoration: none; }
.site-header .site-nav a { color: #cbd5e1; margin-left: 1rem; }
.header-inner { display: flex; align-items: center; justify-content: space-between; }
.brand-logo {
    height: 36px;
    width: auto;
    max-width: 180px;
    display: block;
    object-fit: contain;
}
.site-brand { display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; }
.site-tagline {
    color: rgba(255,255,255,0.7);
    font-size: .85rem;
    margin: 0;
    line-height: 1.3;
}

/* Meta line below the status banner: timestamp + auto-refresh control. */
.status-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .6rem;
    font-size: .85rem;
    color: #6b7280;
    margin: .65rem 0 1.5rem;
    padding: 0 .25rem;
}
.status-meta .meta-sep { color: #cbd5e1; }
.auto-refresh-label {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin: 0;
    font-weight: 400;
    color: #6b7280;
}
.status-meta select {
    width: auto;
    margin: 0;
    padding: .15rem .4rem;
    font-size: .85rem;
    border: 1px solid #e5e7eb;
    background: white;
    color: #374151;
    border-radius: 4px;
}
#refresh-countdown {
    font-variant-numeric: tabular-nums;
    color: #9ca3af;
}

/* ---------- Banner ---------- */
.banner {
    margin: 2rem 0;
    padding: 2rem;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--banner) 0%, color-mix(in srgb, var(--banner) 75%, #000 25%) 100%);
    color: white;
    text-align: center;
    box-shadow: 0 6px 24px rgba(15,23,42,0.12);
    position: relative;
    overflow: hidden;
}
.banner h2 { color: white; font-size: 1.6rem; margin: 0; }
.banner-sub { color: rgba(255,255,255,0.85); margin: .25rem 0 0; font-size: .9rem; }
.banner-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: white; display: inline-block;
    box-shadow: 0 0 0 4px rgba(255,255,255,0.3);
    margin-bottom: .5rem;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(255,255,255,0.3); }
    50%      { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
}

/* ---------- Components / groups ---------- */
.components h3, .incidents-active h3, .incidents-past h3 {
    margin: 2rem 0 .75rem;
    font-size: 1.05rem;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.group {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
}
.group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.group-head h4 { margin: 0; font-size: 1rem; }
.group-pill {
    color: white;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.6;
    white-space: nowrap;
}

.component-list { list-style: none; margin: 0; padding: 0; }
.component {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .9rem 1.25rem;
    border-top: 1px solid #f3f4f6;
}
.component:first-child { border-top: 0; }
.component-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.component-text {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.component-name { font-weight: 500; color: #111827; }
.component-desc { font-size: .85rem; color: #6b7280; }
.component-status {
    font-size: .85rem;
    font-weight: 600;
    text-align: right;
}

/* ---------- Incidents (public) ---------- */
.incident {
    background: white;
    border: 1px solid #e5e7eb;
    border-left: 4px solid #6b7280;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.incident-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .5rem;
}
.incident-head h4 { margin: 0; flex: 1; font-size: 1.05rem; }
.affected { color: #6b7280; font-size: .9rem; margin: .25rem 0 .75rem; }
.updates { list-style: none; padding: 0; margin: .5rem 0 0; }
.updates li {
    border-top: 1px dashed #e5e7eb;
    padding: .6rem 0;
}
.updates li:first-child { border-top: 0; }
.updates p { margin: .25rem 0 0; color: #374151; }

.impact-pill {
    color: white;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.incident-status {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
}
.status-investigating { color: #f97316; }
.status-identified    { color: #eab308; }
.status-monitoring    { color: #3b82f6; }
.status-resolved      { color: #16a34a; }

/* ---------- Incident detail page ---------- */
.incident-detail {
    border-left-width: 6px;
    margin-top: 1rem;
    padding: 1.5rem;
}
.incident-detail .incident-head h2 { color: #111827; font-size: 1.4rem; }
.incident-meta { font-size: .9rem; margin: .25rem 0 1rem; }
.section-h {
    margin: 1.5rem 0 .5rem;
    font-size: .95rem;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.affected-list {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}
.updates-editable { padding-left: 0; list-style: none; margin: 0; }
.updates-editable li.update-edit {
    border-top: 1px solid #e5e7eb;
}
.updates-editable li.update-edit:first-child { border-top: 0; }

.updates-editable details > summary {
    list-style: none;
    cursor: pointer;
    padding: .85rem 0;
    display: flex;
    align-items: flex-start;
    gap: .75rem;
}
.updates-editable details > summary::-webkit-details-marker { display: none; }
.updates-editable details > summary:hover { background: #fafafa; }

.update-summary-text { flex: 1; min-width: 0; }
.update-summary-text p { margin: .25rem 0 0; color: #374151; }

.edit-toggle {
    display: inline-block;
    background: #f3f4f6;
    color: #111827;
    border: 1px solid #d1d5db;
    padding: .25rem .7rem;
    border-radius: 6px;
    font-size: .85rem;
    line-height: 1.4;
    flex-shrink: 0;
    align-self: center;
}
.update-edit details:not([open]) .edit-toggle::before,
.updates-editable details:not([open]) .edit-toggle::before { content: "Edit"; }
.updates-editable details[open] .edit-toggle::before { content: "Close"; }

.update-edit-body {
    padding: 0 0 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.update-edit-form { margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.update-edit-row {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(180px, 1fr);
    gap: .75rem;
}
.update-edit-actions { display: flex; gap: .5rem; }
.update-delete-form { margin: 0; }

.incident-updates { padding-left: 0; }
.incident-updates li {
    border-top: 1px solid #e5e7eb;
    padding: .75rem 0;
}
.incident-updates li:first-child { border-top: 0; }
.permalink-box {
    margin-top: 1.5rem;
    padding: .75rem 1rem;
    background: #f9fafb;
    border: 1px dashed #e5e7eb;
    border-radius: 6px;
    font-size: .85rem;
    word-break: break-all;
}
.permalink-label { color: #6b7280; margin-right: .5rem; font-weight: 600; }

.past-list { list-style: none; padding: 0; margin: 0; }
.past-list li {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: .65rem 1rem;
    margin-bottom: .5rem;
    display: flex;
    align-items: center;
    gap: .75rem;
}
.past-title { flex: 1; font-weight: 500; }
.past-meta  { font-size: .85rem; }

.site-footer {
    margin: 3rem 0 1.5rem;
    color: #6b7280;
    font-size: .85rem;
}
.site-footer .container {
    display: flex; justify-content: space-between;
    border-top: 1px solid #e5e7eb;
    padding-top: 1rem;
}

/* ---------- Auth ---------- */
.auth-body {
    background: #0f172a;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-card {
    background: white;
    width: 100%;
    max-width: 420px;
    margin: 1rem;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-card h1 { margin-bottom: .5rem; font-size: 1.5rem; }
.auth-card label { display: block; margin-bottom: .9rem; font-size: .9rem; color: #374151; font-weight: 500; }
.auth-card input { width: 100%; padding: .55rem .65rem; border: 1px solid #d1d5db; border-radius: 6px; margin-top: .25rem; font: inherit; }
.auth-card-wide { max-width: 540px; }
.auth-card .small { font-size: .85rem; }

/* TOTP enrolment layout */
.totp-enrol {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin: 1rem 0 1.25rem;
    padding: 1rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    align-items: center;
}
.totp-qr-wrap { flex-shrink: 0; }
#totp-qr { width: 220px; height: 220px; background: white; padding: 8px; border-radius: 6px; }
#totp-qr img, #totp-qr canvas { display: block; width: 100%; height: 100%; }
.totp-secret-block { flex: 1; min-width: 200px; }
.totp-secret {
    display: inline-block;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: .55rem .75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1rem;
    letter-spacing: 0.04em;
    color: #111827;
    word-break: break-all;
    margin: .25rem 0;
}
.totp-confirm input[name="code"] {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.4rem;
    letter-spacing: 0.4em;
    text-align: center;
}

/* ---------- Admin ---------- */
.admin-body { background: #f5f7fa; }
.admin-header {
    background: var(--brand);
    color: #f1f5f9;
    padding: .75rem 0;
}
.admin-header .site-title {
    color: #f8fafc;
    font-weight: 600;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: .55rem;
}
.admin-header .brand-logo { height: 28px; max-width: 140px; }
.admin-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.admin-nav a { color: #cbd5e1; font-size: .9rem; padding: .25rem .5rem; border-radius: 4px; }
.admin-nav a.active { background: #1e293b; color: #f1f5f9; }
.admin-nav .who { margin-left: auto; }
.admin-nav .logout { color: #fca5a5; }
.role-pill {
    display: inline-block;
    margin-left: .35rem;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.role-pill.role-admin  { background: #dc2626; color: white; }
.role-pill.role-member { background: #475569; color: white; }

.user-actions {
    margin-top: .65rem;
    padding: .65rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    min-width: 280px;
}
.user-actions form {
    margin: 0;
    display: flex;
    gap: .35rem;
    align-items: center;
    flex-wrap: wrap;
}
.user-actions input[type="password"] { flex: 1; min-width: 140px; }

.admin-main { padding: 1.5rem 1rem 4rem; }
.admin-main h2 { margin: .5rem 0 1rem; }

.card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.card > header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.card > header h3 { margin: 0; font-size: 1.05rem; }

/* Settings tab strip */
.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin: 0 0 1.5rem;
}
.settings-tabs a {
    padding: .55rem 1rem;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-weight: 500;
    text-decoration: none;
}
.settings-tabs a:hover { color: #2563eb; }
.settings-tabs a.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

/* Emergency notice — public alert strip + dashboard card */
.emergency-strip {
    background: #fef3c7;
    color: #78350f;
    border-left: 6px solid #f59e0b;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin: 1.25rem 0 .5rem;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.18);
}
.emergency-strip strong {
    display: block;
    margin-bottom: .15rem;
    font-size: 1.05rem;
}
.emergency-strip span { color: #92400e; font-size: .95rem; }

.emergency-card {
    border-left: 6px solid #fca5a5;
}
.emergency-card.emergency-card-on {
    border-left-color: #f59e0b;
    background: #fffbeb;
}
.emergency-card > header { flex-direction: column; align-items: flex-start; gap: .15rem; }
.emergency-card > header h3 { margin: 0; }
.emergency-card form { margin: 0; display: flex; flex-direction: column; gap: .65rem; }
.emergency-card label { font-weight: 400; color: #374151; }
.emergency-status { color: #991b1b; margin: .25rem 0; font-size: 1rem; }
.emergency-preview { margin: 0 0 .25rem; }

.btn-danger-lg, .btn-success-lg {
    align-self: flex-start;
    padding: 1rem 2rem;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 8px;
    color: white;
    border: 1px solid transparent;
    cursor: pointer;
    line-height: 1.2;
}
.btn-danger-lg {
    background: #dc2626;
    border-color: #b91c1c;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}
.btn-danger-lg:hover { background: #b91c1c; }
.btn-success-lg {
    background: #16a34a;
    border-color: #15803d;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);
}
.btn-success-lg:hover { background: #15803d; }

/* Stats */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
}
.stat-num { font-size: 2rem; font-weight: 700; color: #111827; }
.stat-label { color: #6b7280; font-size: .85rem; text-transform: uppercase; letter-spacing: 0.05em; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; }
.row-list { list-style: none; padding: 0; margin: 0; }
.row-list li {
    padding: .55rem 0;
    border-top: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.row-list li:first-child { border-top: 0; }

/* Forms */
.form-inline { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .9rem;
}
.form-grid .full { grid-column: 1 / -1; }

/* Hide "Resolved at" unless the status select is currently set to "resolved". */
.resolved-field { display: none; }
form:has(select[name="status"] option[value="resolved"]:checked) .resolved-field { display: block; }
label { display: block; font-size: .9rem; color: #374151; font-weight: 500; }
input, select, textarea {
    width: 100%;
    padding: .45rem .55rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    margin-top: .25rem;
    background: white;
    color: #1f2937;
}
textarea { resize: vertical; }
.status-select { font-weight: 600; }

/* Component checkbox grid */
.component-checks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.check-group {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: .75rem 1rem;
}
.check-group strong {
    display: block;
    color: #374151;
    margin-bottom: .5rem;
    text-transform: uppercase;
    font-size: .8rem;
    letter-spacing: 0.05em;
}
.check-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .35rem 0;
    font-weight: 400;
}
.check-row .check-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
    cursor: pointer;
    margin: 0;
    min-width: 0;
}
.check-row .check-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.check-row input[type="checkbox"] { width: auto; margin: 0; }
.check-row .check-status {
    width: auto;
    min-width: 11em;
    margin: 0;
    padding: .25rem .4rem;
    font-size: .85rem;
}

/* Tables */
table.data {
    width: 100%;
    border-collapse: collapse;
    background: white;
}
table.data th, table.data td {
    padding: .55rem .65rem;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    vertical-align: middle;
}
table.data th {
    background: #f9fafb;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
}
table.data td input, table.data td select { margin: 0; }
.actions { white-space: nowrap; display: flex; gap: .25rem; }

/* Buttons */
.btn {
    display: inline-block;
    background: #f3f4f6;
    color: #111827;
    border: 1px solid #d1d5db;
    padding: .4rem .85rem;
    border-radius: 6px;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
    font: inherit;
}
.btn:hover { background: #e5e7eb; text-decoration: none; }
.btn-primary {
    background: #2563eb;
    border-color: #1d4ed8;
    color: white;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-danger {
    background: white;
    border-color: #fecaca;
    color: #dc2626;
}
.btn-danger:hover { background: #fef2f2; }

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}
.alert-ok    { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert ul { margin: 0; padding-left: 1.25rem; }

@media (max-width: 640px) {
    .header-inner { flex-direction: column; gap: .5rem; align-items: flex-start; }
    .admin-nav .who { margin-left: 0; }
    .component { flex-wrap: wrap; }
    .component-status { width: 100%; text-align: left; padding-left: 18px; }
}
