:root {
    --navy: #12324a;
    --navy-dark: #0b2436;
    --blue: #1e6fa8;
    --blue-dark: #155781;
    --sky: #eaf4fb;
    --teal: #17766f;
    --green: #247a49;
    --green-bg: #e8f6ed;
    --red: #aa2f35;
    --red-bg: #fdecef;
    --amber: #966000;
    --amber-bg: #fff4d7;
    --ink: #1c2730;
    --muted: #687681;
    --line: #d8e0e5;
    --surface: #ffffff;
    --background: #f4f7f9;
    --shadow: 0 8px 28px rgba(17, 45, 64, 0.08);
    --radius: 12px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--background);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.site-header {
    color: #fff;
    background: var(--navy);
    box-shadow: 0 2px 10px rgba(5, 28, 43, 0.24);
}
.header-inner {
    width: min(1440px, 100%);
    min-height: 68px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand {
    flex: 0 0 auto;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: .01em;
}
.brand:hover { text-decoration: none; }
.main-nav { display: flex; align-items: stretch; gap: 4px; align-self: stretch; }
.main-nav a {
    color: #dce9f2;
    display: flex;
    align-items: center;
    padding: 0 13px;
    border-bottom: 3px solid transparent;
    font-weight: 650;
}
.main-nav a:hover, .main-nav a.active { color: #fff; text-decoration: none; background: rgba(255,255,255,.06); border-bottom-color: #70c1ef; }
.user-area { margin-left: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.user-name { font-weight: 650; }
.role-pill { color: #dce9f2; font-size: .78rem; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 2px 8px; }
.account-link { color: #dce9f2; font-size: .9rem; }
.site-header .link-button { color: #fff; }

.page-shell { width: min(1360px, calc(100% - 32px)); min-height: calc(100vh - 132px); margin: 0 auto; padding: 30px 0 56px; }
.page-heading h1 { margin: 0 0 18px; color: var(--navy-dark); font-size: clamp(1.65rem, 2.2vw, 2.15rem); line-height: 1.2; }
.heading-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin: -4px 0 20px; }
.heading-actions > * { margin-top: 0; margin-bottom: 0; }
.record-title { margin: 0 0 9px; font-size: 1.35rem; color: var(--ink); }
.site-footer { color: var(--muted); padding: 22px 16px 32px; text-align: center; font-size: .9rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
}
.card h2 { margin: 0; color: var(--navy-dark); font-size: 1.14rem; }
.card h3 { margin: 22px 0 8px; color: var(--navy-dark); font-size: 1rem; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.card-grid { display: grid; gap: 22px; }
.card-grid.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-grid .card { margin-bottom: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric-card { min-height: 112px; display: flex; flex-direction: column; justify-content: space-between; padding: 17px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--ink); }
.metric-card:hover { text-decoration: none; border-color: #9bc3df; transform: translateY(-1px); }
.metric-card span { color: var(--muted); font-weight: 650; font-size: .86rem; }
.metric-card strong { color: var(--navy); font-size: 2rem; line-height: 1; }
.metric-card.metric-alert strong { color: var(--red); }

.cost-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cost-summary div { background: var(--background); border-radius: 9px; padding: 16px; }
.cost-summary span { display: block; color: var(--muted); font-size: .86rem; }
.cost-summary strong { display: block; margin-top: 4px; color: var(--navy); font-size: 1.45rem; }
.compact-list > div { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf1f3; }
.compact-list > div:last-child { border-bottom: 0; }
.compact-list em { color: var(--red); font-size: .8rem; font-style: normal; }
.item-list { display: grid; }
.item-list a { display: grid; gap: 2px; padding: 10px 0; border-bottom: 1px solid #edf1f3; color: var(--ink); }
.item-list a:last-child { border-bottom: 0; }
.item-list a:hover { text-decoration: none; }
.item-list a:hover span { color: var(--blue-dark); }
.item-list small { color: var(--muted); }

label { display: grid; gap: 6px; color: #34434e; font-weight: 650; font-size: .91rem; }
input, select, textarea {
    width: 100%;
    color: var(--ink);
    background: #fff;
    border: 1px solid #b9c6ce;
    border-radius: 8px;
    padding: 10px 11px;
    outline: none;
    font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30,111,168,.13); }
textarea { resize: vertical; min-height: 72px; }
fieldset { border: 1px solid var(--line); border-radius: 9px; padding: 17px; margin: 0 0 20px; }
legend { color: var(--navy); font-weight: 800; padding: 0 8px; }
.form-grid { display: grid; gap: 17px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.record-form > .card label + label, .stacked-form label + label, .auth-card label + label { margin-top: 15px; }
.record-form .form-grid label + label { margin-top: 0; }
.field-help { color: var(--muted); font-size: .79rem; font-weight: 400; }
.checkbox-label { display: flex; align-items: center; align-self: end; min-height: 43px; flex-direction: row; gap: 9px; }
.checkbox-label input { width: 18px; height: 18px; }
.span-all { grid-column: 1 / -1; }
.span-two { grid-column: span 2; }
.form-actions, .filter-actions, .button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.form-actions { margin: 0 0 25px; }

.button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 750;
    line-height: 1.1;
    text-decoration: none;
}
.button:hover { text-decoration: none; }
.button-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { color: var(--navy); background: #fff; border-color: #aebdc7; }
.button-secondary:hover { background: var(--sky); }
.button-success { color: #fff; background: var(--green); border-color: var(--green); }
.button-warning { color: #3d2a00; background: #f2c458; border-color: #dbaa36; }
.button-danger { color: #fff; background: var(--red); border-color: var(--red); }
.button-plain { color: var(--blue-dark); background: transparent; border-color: transparent; }
.button-small { min-height: 32px; padding: 6px 10px; font-size: .84rem; }
.button-block { width: 100%; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--blue-dark); font-weight: 650; }
.inline-form { display: inline-flex; margin: 0; }

.filter-card { padding: 17px; }
.filter-grid { display: grid; grid-template-columns: 2fr repeat(5, minmax(130px, 1fr)); gap: 12px; align-items: end; }
.filter-actions { margin-top: 14px; }
.filter-inline { display: flex; align-items: end; gap: 9px; }
.filter-inline label { min-width: 170px; }
.search-inline { flex: 1; max-width: 620px; }
.search-inline label { flex: 1; }
.result-count { color: var(--muted); font-weight: 650; }

.table-card { padding: 0; overflow: hidden; }
.table-card > .empty-state { padding: 30px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { color: #53636e; background: #f1f5f7; font-size: .76rem; text-transform: uppercase; letter-spacing: .045em; text-align: left; }
th, td { padding: 13px 14px; border-bottom: 1px solid #e5eaed; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
.record-link { display: grid; color: var(--ink); }
.record-link span { margin-top: 2px; }
.record-link:hover { text-decoration: none; color: var(--blue-dark); }
.table-meta { margin-top: 4px; color: var(--muted); font-size: .8rem; }
.table-details summary { color: var(--blue-dark); font-weight: 700; cursor: pointer; }
.table-details[open] { min-width: 270px; }
.mini-form { display: grid; gap: 9px; margin-top: 10px; }
.mini-form label { font-size: .79rem; }
.danger-zone { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

.badge-row { display: flex; flex-wrap: wrap; gap: 7px; }
.badge { display: inline-flex; align-items: center; width: fit-content; padding: 3px 8px; border-radius: 999px; font-size: .75rem; font-weight: 750; line-height: 1.35; }
.badge-success { color: #165e36; background: var(--green-bg); }
.badge-danger { color: #8f252d; background: var(--red-bg); }
.badge-warning { color: #765000; background: var(--amber-bg); }
.badge-info { color: #135d84; background: var(--sky); }
.badge-muted { color: #5d6971; background: #edf1f3; }
.badge-neutral { color: #394b57; background: #e9eef1; }

.alert { border: 1px solid; border-radius: 9px; padding: 12px 14px; margin-bottom: 18px; }
.alert-success { color: #155d35; background: var(--green-bg); border-color: #a7d7b8; }
.alert-danger { color: #86262d; background: var(--red-bg); border-color: #efb8bd; }
.alert-warning { color: #6f4a00; background: var(--amber-bg); border-color: #efd38e; }
.alert-info { color: #155978; background: var(--sky); border-color: #a9d5ec; }
.action-alert { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.detail-list { margin: 0; }
.detail-list > div { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf1f3; }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-weight: 650; }
.detail-list dd { margin: 0; }
.compact-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.compact-details > div { display: block; border: 0; background: rgba(255,255,255,.65); border-radius: 8px; padding: 10px; }
.compact-details dt { font-size: .8rem; }
.compact-details dd { margin-top: 3px; font-weight: 700; }
.prose { overflow-wrap: anywhere; }
.completion-card { border-color: #a7d7b8; background: #f6fcf8; }
.action-details { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.action-details summary { cursor: pointer; color: var(--blue-dark); font-weight: 750; }
.action-details form { margin-top: 15px; }
.supplier-link-form { margin-top: 16px; }

.attachment-list { display: grid; }
.attachment-list > div { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #edf1f3; }
.attachment-list > div:last-child { border-bottom: 0; }
.attachment-list > div > span { color: var(--muted); font-size: .82rem; margin-left: auto; }
.upload-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

.timeline article { display: grid; grid-template-columns: 20px 1fr; gap: 10px; position: relative; padding-bottom: 20px; }
.timeline article:not(:last-child)::before { content: ""; position: absolute; left: 6px; top: 15px; bottom: 0; width: 2px; background: #d8e4eb; }
.timeline-marker { width: 14px; height: 14px; margin-top: 5px; border: 3px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); z-index: 1; }
.timeline-content { padding: 0 0 2px; }
.timeline-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 5px; }
.timeline-meta > span:not(.badge) { color: var(--muted); font-size: .8rem; }
.audit-list { margin-top: 15px; }
.audit-list > div { display: grid; grid-template-columns: 165px 190px 130px 1fr; gap: 10px; border-top: 1px solid var(--line); padding: 8px 0; font-size: .78rem; }
.audit-list code { white-space: pre-wrap; overflow-wrap: anywhere; }

.inline-add-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; margin-bottom: 17px; }
.settings-list > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #edf1f3; }
.settings-list > div:last-child { border-bottom: 0; }
.settings-list em { display: block; color: var(--green); font-size: .77rem; font-style: normal; }
.role-explainer { margin-top: 20px; padding: 14px; background: var(--background); border-radius: 8px; }
.role-explainer p { margin: 5px 0; font-size: .87rem; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #0b2639, #1b587b); }
.auth-shell { width: min(430px, 100%); }
.installer-shell { width: min(820px, 100%); }
.auth-card { background: #fff; border-radius: 15px; box-shadow: 0 24px 70px rgba(0,0,0,.25); padding: 30px; }
.auth-card h1 { margin: 8px 0 4px; color: var(--navy-dark); }
.auth-card form { margin-top: 20px; }
.auth-card .button { margin-top: 18px; }
.auth-brand { color: var(--blue-dark); font-size: 1.25rem; font-weight: 850; }
.narrow-content { max-width: 620px; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.text-danger { color: var(--red) !important; }
.text-warning { color: var(--amber); }
.empty-state { color: var(--muted); text-align: center; padding: 18px 8px; }

@media (max-width: 1180px) {
    .header-inner { flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; gap: 10px 18px; }
    .main-nav { order: 3; width: 100%; height: 42px; overflow-x: auto; }
    .main-nav a { flex: 0 0 auto; }
    .metric-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .filter-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
}

@media (max-width: 800px) {
    .page-shell { width: min(100% - 22px, 1360px); padding-top: 22px; }
    .heading-actions { align-items: stretch; flex-direction: column; }
    .heading-actions .button-row { justify-content: flex-start; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid.two-up, .form-grid.two-columns, .form-grid.three-columns { grid-template-columns: 1fr; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-two, .span-all { grid-column: auto; }
    .compact-details { grid-template-columns: 1fr; }
    .audit-list > div { grid-template-columns: 1fr; }
    .attachment-list > div { align-items: flex-start; flex-direction: column; }
    .attachment-list > div > span { margin-left: 0; }
    .user-area { width: 100%; margin-left: 0; flex-wrap: wrap; }
}

@media (max-width: 520px) {
    .header-inner { padding-left: 14px; padding-right: 14px; }
    .metric-grid, .filter-grid, .cost-summary { grid-template-columns: 1fr; }
    .card { padding: 17px; }
    .auth-card { padding: 22px; }
    .action-alert { align-items: stretch; flex-direction: column; }
    .filter-inline, .search-inline, .upload-form, .inline-add-form { display: grid; grid-template-columns: 1fr; width: 100%; max-width: none; }
    .filter-inline label { min-width: 0; }
    .detail-list > div { grid-template-columns: 1fr; gap: 2px; }
    .button-row .button, .form-actions .button { flex: 1 1 auto; }
}
