:root {
    --ink: #162638;
    --muted: #647383;
    --line: #d7e0e7;
    --surface: #ffffff;
    --surface-soft: #f4f7f9;
    --blue: #1769aa;
    --blue-dark: #0f4f82;
    --orange: #f28c28;
    --green: #19734a;
    --green-soft: #e7f5ed;
    --red: #a12b32;
    --red-soft: #fbeaec;
    --amber: #8a5b08;
    --amber-soft: #fff4d7;
}

* { box-sizing: border-box; }
html { color: var(--ink); background: var(--surface-soft); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; min-width: 320px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }

.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px clamp(18px, 4vw, 56px);
    color: white;
    background: #122334;
    border-bottom: 3px solid var(--orange);
}
.brand, .topbar-actions { display: flex; align-items: center; gap: 12px; }
.brand img { width: 118px; height: 38px; object-fit: contain; background: white; }
.brand span { font-weight: 700; }
.admin-identity { color: #cbd5df; font-size: 14px; }
.topbar form { margin: 0; }

.admin-main { width: min(1600px, 100%); margin: 0 auto; padding: 28px clamp(14px, 3vw, 42px) 48px; }
.admin-main-narrow { width: min(940px, 100%); }
.page-heading, .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.page-heading { margin-bottom: 20px; }
.page-heading h1, .section-heading h2 { margin: 0; letter-spacing: 0; }
.page-heading h1 { font-size: clamp(25px, 3vw, 34px); }
.section-heading h2 { font-size: 19px; }
.section-heading p, .snapshot-time { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.page-subtitle { margin: 7px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 12px; font-weight: 800; text-transform: uppercase; }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); border: 1px solid var(--line); background: var(--surface); }
.metric { min-height: 92px; padding: 16px 18px; border-right: 1px solid var(--line); border-top: 3px solid transparent; }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 28px; }
.metric-warning { border-top-color: #dda326; }
.metric-success { border-top-color: var(--green); }
.metric-danger { border-top-color: var(--red); }

.admin-section { margin-top: 26px; padding-top: 18px; border-top: 2px solid var(--line); }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); gap: 28px; }
.table-wrap { margin-top: 14px; overflow-x: auto; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 12px; text-align: left; color: #4d5c6b; background: #edf2f5; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #e7edf1; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafb; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; }
.url-cell { min-width: 250px; max-width: 480px; overflow-wrap: anywhere; }
.url-cell small { display: block; margin-top: 4px; color: var(--red); }
.empty-state { padding: 24px; text-align: center; color: var(--muted); }

.status { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 4px; background: #edf1f4; white-space: nowrap; font-size: 12px; font-weight: 700; }
.status-success { color: var(--green); background: var(--green-soft); }
.status-danger { color: var(--red); background: var(--red-soft); }
.status-warning { color: var(--amber); background: var(--amber-soft); }

.search-form { display: flex; gap: 10px; margin-top: 14px; max-width: 680px; }
.search-form input, .login-panel input { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid #aebbc6; border-radius: 4px; color: var(--ink); background: white; }
.search-form input:focus, .login-panel input:focus { outline: 3px solid rgba(23, 105, 170, .18); border-color: var(--blue); }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 8px 13px; border: 1px solid transparent; border-radius: 4px; cursor: pointer; font-weight: 700; white-space: nowrap; }
.button:hover { text-decoration: none; }
.button-primary { color: white; background: var(--blue); }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { color: white; background: transparent; border-color: #718093; }
.button-secondary:hover { background: rgba(255,255,255,.08); }
.button-outline { color: var(--blue); background: white; border-color: #9fb3c3; }
.button-outline:hover { background: #edf5fa; text-decoration: none; }

.breadcrumb { margin-bottom: 16px; font-size: 14px; }
.breadcrumb a::before { content: "←"; margin-right: 7px; }
.user-heading { align-items: center; }
.user-heading h1 { overflow-wrap: anywhere; }
.metrics-user { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.metrics-adjustment { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.detail-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    margin: 14px 0 0;
    border: 1px solid var(--line);
    background: var(--surface);
}
.detail-list > div { min-height: 76px; padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-list > div:nth-child(4n) { border-right: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.detail-list dd { margin: 7px 0 0; font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.credit-delta { font-weight: 800; }
.credit-positive { color: var(--green); }
.credit-negative { color: var(--red); }
.wrap-mono { white-space: normal; overflow-wrap: anywhere; }

.adjustment-form { margin-top: 26px; padding-top: 20px; border-top: 2px solid var(--line); }
.form-field { margin-bottom: 20px; }
.form-field label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 750; }
.form-field input, .form-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #aebbc6;
    border-radius: 4px;
    color: var(--ink);
    background: white;
}
.form-field input { min-height: 44px; max-width: 180px; }
.form-field textarea { min-height: 110px; resize: vertical; }
.form-field input:focus, .form-field textarea:focus { outline: 3px solid rgba(23, 105, 170, .18); border-color: var(--blue); }
.form-field small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.confirmation-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    margin: 0;
    border: 1px solid var(--line);
    background: var(--surface);
}
.confirmation-list > div { padding: 16px; border-right: 1px solid var(--line); }
.confirmation-list > div:last-child { border-right: 0; }
.confirmation-list dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.confirmation-list dd { margin: 7px 0 0; font-size: 22px; font-weight: 800; }
.reason-summary { margin-top: 22px; padding: 16px 18px; border-left: 4px solid var(--orange); background: var(--surface); }
.reason-summary h2 { margin: 0; font-size: 15px; }
.reason-summary p { margin: 8px 0 0; line-height: 1.5; overflow-wrap: anywhere; }
.confirmation-actions { margin-top: 22px; }

.request-filters {
    display: grid;
    grid-template-columns: minmax(170px, .65fr) minmax(190px, .75fr) minmax(280px, 1.6fr) auto;
    align-items: end;
    gap: 14px;
    margin-top: 24px;
    padding: 18px;
    border: 1px solid var(--line);
    background: var(--surface);
}
.filter-field label { display: block; margin-bottom: 6px; color: #4d5c6b; font-size: 12px; font-weight: 750; }
.filter-field input, .filter-field select {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #aebbc6;
    border-radius: 4px;
    color: var(--ink);
    background: white;
}
.filter-field input:focus, .filter-field select:focus { outline: 3px solid rgba(23, 105, 170, .18); border-color: var(--blue); }
.filter-actions { display: flex; gap: 9px; }
.request-results { margin-top: 22px; }
.request-table table { min-width: 1180px; }
.request-table td { max-width: 440px; }
.cell-detail { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; white-space: normal; overflow-wrap: anywhere; }
.error-detail { color: var(--red); }
.request-detail-list > div:nth-child(5) { grid-column: span 2; }
.request-source-list > div:last-child { grid-column: 1 / -1; border-right: 0; }
.request-instructions { margin-top: 18px; padding: 14px 16px; border-left: 4px solid var(--orange); background: var(--surface-soft); }
.request-instructions h3 { margin: 0; font-size: 14px; }
.request-instructions p { margin: 7px 0 0; line-height: 1.5; overflow-wrap: anywhere; }
.option-list { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 16px 0 0; }
.option-list > div { display: flex; gap: 7px; font-size: 12px; }
.option-list dt { color: var(--muted); font-weight: 700; }
.option-list dd { margin: 0; font-weight: 700; }

.login-page { min-height: 100vh; background: #eef3f6; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); padding: 30px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--orange); box-shadow: 0 16px 40px rgba(20, 40, 60, .12); }
.login-logo { display: block; width: 170px; height: 56px; margin-bottom: 20px; object-fit: contain; object-position: left center; }
.login-panel h1 { margin: 0 0 22px; font-size: 25px; }
.login-panel label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 750; }
.login-note { margin: 16px 0 0; padding: 10px 12px; border-left: 3px solid var(--green); color: var(--green); background: var(--green-soft); font-size: 12px; line-height: 1.45; }
.login-panel .button { width: 100%; margin-top: 20px; }
.alert { margin: 14px 0; padding: 11px 12px; border-left: 4px solid; }
.alert-error { color: var(--red); background: var(--red-soft); border-color: var(--red); }
.alert-success { color: var(--green); background: var(--green-soft); border-color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
    .metrics { grid-template-columns: repeat(3, 1fr); }
    .metric:nth-child(3) { border-right: 0; }
    .metric:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
    .metrics-user { grid-template-columns: repeat(2, 1fr); }
    .metrics-adjustment { grid-template-columns: repeat(3, 1fr); }
    .metrics-user .metric:nth-child(2n) { border-right: 0; }
    .metrics-user .metric:nth-child(3) { border-right: 1px solid var(--line); }
    .metrics-user .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .metrics-user .metric:nth-last-child(-n+2) { border-bottom: 0; }
    .admin-grid { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .detail-list > div:nth-child(4n) { border-right: 1px solid var(--line); }
    .detail-list > div:nth-child(2n) { border-right: 0; }
    .request-detail-list > div:nth-child(5) { grid-column: 1 / -1; border-right: 0; }
    .request-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-search { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .topbar-actions { width: 100%; flex-wrap: wrap; }
    .admin-identity { flex: 1 0 100%; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
    .metric { border-bottom: 1px solid var(--line); }
    .metric:nth-child(2n) { border-right: 0; }
    .search-form { flex-direction: column; }
    .search-form .button { width: 100%; }
    .user-heading { align-items: flex-start; }
    .page-actions { width: 100%; }
    .metrics-user { grid-template-columns: repeat(2, 1fr); }
    .metrics-adjustment { grid-template-columns: 1fr; }
    .metrics-adjustment .metric { border-right: 0; }
    .confirmation-list { grid-template-columns: repeat(2, 1fr); }
    .confirmation-list > div { border-bottom: 1px solid var(--line); }
    .confirmation-list > div:nth-child(2n) { border-right: 0; }
    .confirmation-list > div:nth-last-child(-n+2) { border-bottom: 0; }
    .detail-list { grid-template-columns: 1fr; }
    .detail-list > div { border-right: 0; }
    .detail-list > div:nth-child(4n) { border-right: 0; }
    .request-detail-list > div:nth-child(5) { grid-column: auto; }
    .request-filters { grid-template-columns: 1fr; }
    .filter-search { grid-column: auto; }
    .filter-actions { align-items: stretch; flex-direction: column; }
}
