:root,
html[data-theme="light"] {
    color-scheme: light;
    --page-bg: #f4f7fb;
    --header-bg: rgba(255, 255, 255, .92);
    --surface: #ffffff;
    --surface-soft: #eef3f9;
    --surface-strong: #e3eaf4;
    --input-bg: #ffffff;
    --text: #233044;
    --text-strong: #111827;
    --muted: #68778e;
    --border: #dfe6f0;
    --border-soft: #edf1f6;
    --primary: #2859d7;
    --primary-hover: #1f49b4;
    --primary-soft: #edf3ff;
    --primary-soft-text: #2558d9;
    --success-bg: #e9f8ef;
    --success-border: #b7e2c7;
    --success-text: #176b37;
    --danger-bg: #fff0f0;
    --danger-border: #efc0c0;
    --danger-text: #9b2525;
    --shadow: 0 8px 30px rgba(22, 39, 73, .08);
    --card-shadow: 0 5px 22px rgba(22, 39, 73, .06);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --page-bg: #090f1d;
    --header-bg: rgba(15, 23, 42, .94);
    --surface: #111a2b;
    --surface-soft: #1a263b;
    --surface-strong: #26334a;
    --input-bg: #0d1628;
    --text: #dbe4f0;
    --text-strong: #f8fafc;
    --muted: #94a3b8;
    --border: #29364d;
    --border-soft: #223047;
    --primary: #6d91ef;
    --primary-hover: #82a2f4;
    --primary-soft: #1e2e52;
    --primary-soft-text: #c3d3ff;
    --success-bg: #123322;
    --success-border: #286241;
    --success-text: #bbf7d0;
    --danger-bg: #3c171b;
    --danger-border: #7f3038;
    --danger-text: #fecaca;
    --shadow: 0 10px 32px rgba(0, 0, 0, .28);
    --card-shadow: 0 8px 28px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page-bg); }
body { min-height: 100vh; margin: 0; background: var(--page-bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; }

.site-header,
.app-bar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 max(24px, calc((100% - 1180px) / 2));
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow);
}
.site-header { min-height: 82px; }
.brand,
.site-brand { color: var(--text-strong); font-size: 21px; font-weight: 850; text-decoration: none; letter-spacing: -.03em; }
.brand span,
.site-brand span { color: var(--primary); }
.site-actions,
nav { display: flex; align-items: center; gap: 8px; }
nav a,
.link-button,
.header-link { padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); text-decoration: none; cursor: pointer; }
nav a:hover,
.link-button:hover,
.header-link:hover { color: var(--primary); background: var(--surface-soft); }
.user { color: var(--muted); font-size: 14px; }
.theme-toggle { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text-strong); cursor: pointer; }

main { width: min(1180px, calc(100% - 40px)); margin: 34px auto; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.hero h1 { margin-bottom: 6px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
h1 { margin: 6px 0 10px; color: var(--text-strong); font-size: clamp(28px, 4vw, 38px); line-height: 1.08; letter-spacing: -.04em; }
h2, h3 { margin-top: 0; color: var(--text-strong); }
p, li, td, label { color: var(--text); }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.card { min-width: 0; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--card-shadow); }
.metric strong { display: block; margin-top: 7px; color: var(--text-strong); font-size: 31px; letter-spacing: -.04em; }
.wide { grid-column: span 3; }
.side { grid-column: span 1; }
.detail { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; }
.stack { display: flex; flex-wrap: wrap; gap: 10px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.list-stack { display: grid; gap: 10px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); color: var(--text); text-decoration: none; }
.list-item:hover { border-color: var(--primary); }
.list-item p { margin: 5px 0 0; }
.checkbox-row { display: flex; align-items: flex-start; gap: 9px; margin: 0 0 16px; }
.checkbox-row input { width: auto; margin-top: 3px; accent-color: var(--primary); }

.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th,
.table td { padding: 13px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: color-mix(in srgb, var(--primary) 7%, transparent); }
.table a { color: var(--primary); text-decoration: none; font-weight: 700; }

.badge { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-soft-text); font-size: 12px; font-weight: 750; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 15px; border: 0; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 750; text-decoration: none; cursor: pointer; }
.button:hover { background: var(--primary-hover); }
.button.secondary { background: var(--surface-soft); color: var(--text-strong); }
.button.secondary:hover { background: var(--surface-strong); }

.form { max-width: 720px; }
.auth { max-width: 480px; margin: 64px auto; }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 7px; color: var(--text-strong); font-weight: 750; }
.field input,
.field select,
.field textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--input-bg); color: var(--text); }
.field input:focus,
.field select:focus,
.field textarea:focus { outline: 3px solid color-mix(in srgb, var(--primary) 22%, transparent); border-color: var(--primary); }
.field textarea { min-height: 130px; resize: vertical; }
.inline-check { display: flex; align-items: flex-start; gap: 9px; }
.inline-check input { width: auto; margin-top: 3px; accent-color: var(--primary); }

.timeline { padding: 16px 0 0 18px; border-left: 2px solid var(--border); }
.activity-panel { margin-top: 18px; }
.activity-note-form { max-width: 760px; margin-bottom: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.activity-timeline { list-style: none; margin: 0; padding: 0; }
.activity-item { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 12px; padding-bottom: 20px; }
.activity-item:not(:last-child)::before { content: ""; position: absolute; top: 15px; bottom: -2px; left: 6px; width: 2px; background: var(--border); }
.activity-marker { width: 14px; height: 14px; margin-top: 3px; border: 3px solid var(--surface); border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 1px var(--primary); z-index: 1; }
.activity-item--note .activity-marker { background: var(--success-text); box-shadow: 0 0 0 1px var(--success-text); }
.activity-content { min-width: 0; padding: 0 0 0 2px; }
.activity-content p { margin: 6px 0 0; white-space: normal; overflow-wrap: anywhere; }
.activity-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.activity-item--note .activity-content { padding: 12px 14px; border: 1px solid var(--success-border); border-radius: 12px; background: var(--success-bg); }
.activity-readonly { margin: 4px 0 0 30px; font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--border); }
.flash,
.error { margin-bottom: 18px; padding: 13px 16px; border-radius: 10px; }
.flash { border: 1px solid var(--success-border); background: var(--success-bg); color: var(--success-text); }
.error { border: 1px solid var(--danger-border); background: var(--danger-bg); color: var(--danger-text); }
.empty-state { padding: 42px 20px; text-align: center; }
.empty-state p { max-width: 520px; margin-inline: auto; }

footer { padding: 34px 20px; color: var(--muted); text-align: center; }
footer p { margin: 4px 0; color: var(--muted); }

@media (max-width: 800px) {
    .site-header, .app-bar { position: static; flex-wrap: wrap; padding: 14px 18px; }
    .app-bar .brand { width: 100%; }
    nav { width: 100%; flex-wrap: wrap; }
    main { width: min(100% - 28px, 1180px); margin-top: 24px; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .wide, .side { grid-column: span 2; }
    .detail { grid-template-columns: minmax(0, 1fr); }
    .hero { align-items: flex-start; flex-direction: column; }
    .section-heading { align-items: flex-start; flex-direction: column; }
    .list-item { align-items: flex-start; flex-direction: column; }
    .activity-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
    .user { display: none; }
}

@media (max-width: 520px) {
    .grid { grid-template-columns: minmax(0, 1fr); }
    .wide, .side { grid-column: span 1; }
    .site-actions .header-link { display: none; }
    .card { padding: 17px; }
    .actions { width: 100%; }
    .actions .button { flex: 1 1 100%; }
    .activity-note-form .button { width: 100%; }
    .activity-readonly { margin-left: 0; }
    .table th:nth-child(4), .table td:nth-child(4) { display: none; }
}