:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e2e8f0;
    --ink: #1e293b;
    --ink-soft: #64748b;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --primary-soft: #eff4ff;
    --danger: #dc2626;
    --success: #16a34a;
    --amber: #d97706;
    --teal: #0d9488;
    --purple: #7c3aed;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* Top bar */
.topbar { background: #0f172a; color: #e2e8f0; box-shadow: var(--shadow); }
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; gap: 20px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
    background: var(--primary); color: #fff; font-weight: 800; font-size: .8rem;
    padding: 6px 8px; border-radius: 8px; letter-spacing: .5px;
}
.brand-mark-lg { font-size: 1.4rem; padding: 12px 16px; }
.brand-text { font-size: 1rem; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
    color: #cbd5e1; padding: 8px 14px; border-radius: 8px; font-weight: 500; font-size: .92rem;
}
.mainnav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.mainnav a.active { background: var(--primary); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; flex-direction: column; line-height: 1.1; font-size: .85rem; color: #e2e8f0; text-align: right; }
.user-chip small { color: #94a3b8; font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; }
.inline-form { display: inline; margin: 0; }

/* Layout */
.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; width: 100%; flex: 1; }
.container-auth { display: flex; align-items: center; justify-content: center; max-width: 460px; }
.appfooter {
    max-width: 1200px; margin: 12px auto; padding: 12px 20px; width: 100%;
    display: flex; justify-content: space-between; color: var(--ink-soft); font-size: .8rem;
    border-top: 1px solid var(--border);
}
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head-actions, .form-actions, .filter-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* Cards */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-title { margin: 0 0 12px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.card-centered { text-align: center; max-width: 460px; margin: 60px auto; }
.subhead { margin: 16px 0 6px; color: var(--ink-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; }
.narrow { max-width: 560px; }
.lead { font-size: 1.1rem; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: .82rem; margin: 8px 0 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.text-right { text-align: right; }
.meta-line { font-size: .82rem; margin-top: 12px; }

/* Auth */
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 34px; box-shadow: var(--shadow); width: 100%; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 1.3rem; margin: 14px 0 4px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 8px; padding: 9px 16px;
    font-size: .9rem; font-weight: 600; cursor: pointer; font-family: inherit;
    background: #e2e8f0; color: var(--ink); transition: background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fee2e2; border-color: #f87171; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.row-actions { display: inline-flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.link-danger { color: var(--danger); }

/* Forms */
label { display: block; margin-bottom: 4px; }
label > span { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=time],
input[type=datetime-local], input[type=file], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    font-size: .92rem; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; }
.stack > label, .stack > fieldset { margin-bottom: 14px; }
.block { display: block; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-bottom: 14px; }
.checkbox-inline { display: flex; align-items: center; gap: 8px; }
.checkbox-inline input { width: auto; }
.checkbox-inline span { margin: 0; font-weight: 500; color: var(--ink); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 18px; }
fieldset.card legend, fieldset legend { font-weight: 700; padding: 0 8px; color: var(--primary-dark); }
.subfield { background: #f8fafc; }
.field-error { display: block; color: var(--danger); font-size: .8rem; margin-top: 4px; font-weight: 600; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--ink-soft); font-size: .76rem; text-transform: uppercase; letter-spacing: .5px; cursor: default; }
.table tbody tr:hover { background: #f8fafc; }
.table-sortable th { cursor: pointer; }
.link-sm { font-size: .82rem; font-weight: 600; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-grid-sm { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); max-width: 420px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 4px;
}
a.stat-card:hover { text-decoration: none; transform: translateY(-1px); transition: transform .1s; }
.stat-value { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.stat-label { color: var(--ink-soft); font-size: .82rem; }
.stat-blue { border-left-color: var(--primary); }
.stat-red { border-left-color: var(--danger); }
.stat-amber { border-left-color: var(--amber); }
.stat-purple { border-left-color: var(--purple); }
.stat-teal { border-left-color: var(--teal); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: #e2e8f0; color: #334155; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge-teal { background: #ccfbf1; color: #115e59; }
.badge-status { background: #e0e7ff; color: #3730a3; }
.badge-sev-minor { background: #dcfce7; color: #166534; }
.badge-sev-moderate { background: #fef3c7; color: #92400e; }
.badge-sev-serious { background: #ffedd5; color: #9a3412; }
.badge-sev-emergency { background: #fee2e2; color: #991b1b; }
.count-pill { background: #e2e8f0; color: #475569; border-radius: 999px; padding: 1px 10px; font-size: .78rem; font-weight: 700; }

/* Attention list */
.attention-list { list-style: none; margin: 0; padding: 0; }
.attention-list li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.attention-list li:last-child { border-bottom: none; }
.attention-list .muted { flex: 1; }

/* Detail lists */
.detail-list { margin: 0; }
.detail { display: grid; grid-template-columns: 180px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f1f5f9; }
.detail dt { color: var(--ink-soft); font-weight: 600; font-size: .85rem; margin: 0; }
.detail dd { margin: 0; }
.flag-yes { color: var(--danger); font-weight: 700; }
@media (max-width: 560px) { .detail { grid-template-columns: 1fr; gap: 2px; } }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px; padding: 3px 12px; font-size: .8rem; font-weight: 600; }

/* Workflow */
.workflow { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.wf-step { padding: 5px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .8rem; color: var(--ink-soft); position: relative; }
.wf-active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 4px 0 16px 18px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.timeline p { margin: 4px 0; }

/* File list */
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; flex-wrap: wrap; }

/* Add-form disclosure */
.add-form { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 12px; }
.add-form summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.add-form[open] summary { margin-bottom: 12px; }

/* Filter bar */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.filter-wide { grid-column: span 2; }
@media (max-width: 640px) { .filter-wide { grid-column: span 1; } }

/* Report bars */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: 130px 1fr 40px; align-items: center; gap: 10px; padding: 4px 0; }
.bar-label { font-size: .85rem; }
.bar-track { background: #eef2f7; border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 6px; }
.bar-value { text-align: right; font-weight: 700; font-size: .85rem; }

.error-code { font-size: 3rem; margin: 0; color: var(--primary); }

/* Print view */
body.print { background: #fff; display: block; }
.print-sheet { max-width: 800px; margin: 0 auto; padding: 30px; }
.print-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--ink); padding-bottom: 12px; margin-bottom: 16px; }
.print-header h1 { font-size: 1.4rem; }
.print-ref { text-align: right; font-size: .9rem; }
.print-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.print-table th, .print-table td { border: 1px solid #cbd5e1; padding: 6px 10px; text-align: left; vertical-align: top; font-size: .85rem; }
.print-table th { background: #f1f5f9; width: 200px; }
.print-table-list th { width: auto; }
.print-footer { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 12px; font-size: .8rem; color: var(--ink-soft); }
@media print {
    .no-print { display: none !important; }
    .print-sheet { padding: 0; }
    a { color: #000; }
}
@page { margin: 15mm; }
