:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #667085;
    --border: #dde1e7;
    --primary: #1f4e8c;
    --primary-hover: #183e70;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --warning: #a15c07;
    --warning-bg: #fef4e2;
    --success: #067647;
    --success-bg: #e8f6ee;
    --info: #1f4e8c;
    --info-bg: #e8eef8;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }

code, pre { font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.9em; }
pre { background: #eef0f3; padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; }

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.5rem 1.25rem;
    min-height: 56px;
    background: #14213d;
    color: #fff;
    flex-wrap: wrap;
}
.topbar a { color: #cfd8e8; }
.topbar a:hover { color: #fff; text-decoration: none; }
.brand { font-weight: 700; color: #fff !important; font-size: 1.05rem; }
.mainnav { display: flex; gap: 0.15rem; flex: 1; flex-wrap: wrap; }
.mainnav a { padding: 0.35rem 0.6rem; border-radius: 6px; font-size: 0.92rem; }
.mainnav a.active { background: rgba(255, 255, 255, 0.14); color: #fff; }
.usernav { display: flex; gap: 1rem; align-items: center; font-size: 0.9rem; }
.usernav form { margin: 0; }
.linkbutton { background: none; border: 0; color: #cfd8e8; cursor: pointer; font: inherit; padding: 0; }
.linkbutton:hover { color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.pagehead p { margin: 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.25rem;
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid .card { margin-bottom: 0; }
.grid + h2, .tablewrap + .grid, p + .grid { margin-top: 1.25rem; }
.twocol { display: grid; gap: 1.25rem; grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .twocol { grid-template-columns: 1fr; } }

.company-card h3 { margin: 0 0 0.5rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.75rem 0; }
.stat { text-align: center; padding: 0.4rem; border-radius: 6px; background: #f2f4f7; }
.stat strong { display: block; font-size: 1.35rem; line-height: 1.2; }
.stat span { font-size: 0.75rem; color: var(--muted); }
.stat.danger { background: var(--danger-bg); color: var(--danger); }
.stat.warning { background: var(--warning-bg); color: var(--warning); }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: center; }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 1.25rem; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.muted { background: #eef0f3; color: var(--muted); }

/* ---- Alerts ---- */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert.success { background: var(--success-bg); color: var(--success); border-color: #b7e2c8; }
.alert.warning { background: var(--warning-bg); color: var(--warning); border-color: #f5d79e; }
.alert.danger { background: var(--danger-bg); color: var(--danger); border-color: #f4c2bd; }

/* ---- Forms ---- */
form.stack { display: grid; gap: 0.9rem; max-width: 720px; }
.field { display: grid; gap: 0.3rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
.row { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid #c4cad4;
    border-radius: 6px;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { min-height: 140px; resize: vertical; }
textarea.editor { min-height: 60vh; font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.9rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fb1e3; outline-offset: 0; border-color: var(--primary); }
.checkbox { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; font-size: 0.9rem; }
.hint { font-size: 0.82rem; color: var(--muted); }
.field-validation-error, .validation-summary-errors { color: var(--danger); font-size: 0.85rem; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }
.validation-summary-valid { display: none; }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 150px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
    padding: 0.5rem 0.95rem;
    border-radius: 6px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    font: inherit; font-weight: 600; font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none !important;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.secondary { background: #fff; color: var(--primary); border-color: #c4cad4; }
.btn.secondary:hover { background: #f2f4f7; }
.btn.danger { background: #fff; color: var(--danger); border-color: #f0b4ae; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn.chip { padding: 0.25rem 0.65rem; font-size: 0.8rem; background: #fff; color: var(--text); border-color: #c4cad4; font-weight: 500; }
.btn.chip:hover { background: #f2f4f7; }
.inline { display: inline; margin: 0; }

/* ---- Notes ---- */
.notelist { list-style: none; margin: 0; padding: 0; }
.notelist li { padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.notelist li:last-child { border-bottom: 0; }
.notehead { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.notehead strong { font-size: 1rem; }
.notebody { margin: 0.35rem 0 0; white-space: pre-wrap; }

/* ---- Report ---- */
.report { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 2.5rem; max-width: 900px; }
.report h1 { font-size: 1.6rem; color: #1f3864; }
.report h2 { color: #2f5496; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
.report table { border: 1px solid var(--border); margin: 0.75rem 0; }
.report th { background: #d9e2f3; color: var(--text); text-transform: none; font-size: 0.85rem; }
.report blockquote { margin: 1rem 0; padding: 0.5rem 1rem; border-left: 4px solid #f5d79e; background: var(--warning-bg); }

/* ---- Sign-in ---- */
.auth { max-width: 400px; margin: 8vh auto 0; }
.auth h1 { text-align: center; margin-bottom: 1.25rem; }
.qr { display: block; width: 200px; height: 200px; margin: 0.5rem 0; image-rendering: pixelated; }
.key { font-family: Consolas, monospace; font-size: 1rem; letter-spacing: 0.05em; background: #eef0f3; padding: 0.4rem 0.6rem; border-radius: 6px; display: inline-block; }
.codes { columns: 2; font-family: Consolas, monospace; }

.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* ---- Company sections ---- */
.subnav { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.subnav a { padding: 0.35rem 0.75rem; border: 1px solid var(--border); border-radius: 999px; background: #fff; font-size: 0.88rem; color: var(--text); }
.subnav a:hover { background: #f2f4f7; text-decoration: none; }
.subnav .count { color: var(--muted); margin-left: 0.25rem; }

/* ---- Goals ---- */
progress { width: 90px; height: 10px; vertical-align: middle; accent-color: var(--primary); }

/* ---- Risk heat map ---- */
table.heatmap { width: auto; background: none; }
table.heatmap th, table.heatmap td { border: 0; padding: 0.15rem; text-align: center; font-size: 0.75rem; }
table.heatmap .axis { color: var(--muted); font-weight: 600; writing-mode: horizontal-tb; }
table.heatmap td.cell { width: 42px; height: 34px; border-radius: 4px; font-weight: 700; font-size: 0.9rem; }
table.heatmap td.low { background: #e8f6ee; color: var(--success); }
table.heatmap td.medium { background: #fef4e2; color: var(--warning); }
table.heatmap td.high { background: #fdecea; color: var(--danger); }

.list-compact { list-style: none; margin: 0; padding: 0; }
.list-compact li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.list-compact li:last-child { border-bottom: 0; }

@media print {
    .topbar, .pagehead .actions, .noprint { display: none !important; }
    body { background: #fff; }
    .container { padding: 0; max-width: none; }
    .report { border: 0; padding: 0; }
}
