:root {
    --blue: #1f4f8f;
    --blue-dark: #12315d;
    --red: #c9232d;
    --green: #4f6f52;
    --amber: #f0a23a;
    --bg: #f3f6fa;
    --panel: #ffffff;
    --line: #d8e0ea;
    --text: #172033;
    --muted: #697386;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, "Helvetica Neue", sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--red); }
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--blue-dark);
    color: white;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.brand { display: grid; gap: 10px; color: white; font-weight: 700; }
.brand img { width: 174px; max-width: 100%; background: white; padding: 8px; border-radius: 6px; }
.nav { display: grid; gap: 8px; }
.nav a {
    color: white;
    padding: 11px 12px;
    border-radius: 6px;
    background: rgba(255,255,255,.08);
}
.nav a:hover { background: rgba(255,255,255,.16); color: white; }
.logout-form { margin-top: auto; display: grid; gap: 12px; color: white; }
.logout-form small { display: block; color: rgba(255,255,255,.72); overflow-wrap: anywhere; }
.logout-form button, .secondary-button, .primary-button {
    border: 0;
    border-radius: 6px;
    padding: 11px 16px;
    font-weight: 700;
    cursor: pointer;
}
.logout-form button { color: white; background: rgba(255,255,255,.16); }
.content { padding: 28px; min-width: 0; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 28px; }
.eyebrow {
    margin: 0 0 5px;
    color: var(--red);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 700;
}
.panel, .auth-card, .metric {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(18,49,93,.06);
}
.panel { padding: 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.auth-card {
    max-width: 430px;
    margin: 7vh auto;
    padding: 30px;
}
.auth-logo { width: 190px; margin-bottom: 20px; }
.auth-card h1 { margin-top: 0; font-size: 25px; }
.form, .filter-bar { display: grid; gap: 16px; }
.filter-bar {
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    align-items: end;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 18px;
}
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 16px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    font: inherit;
    color: var(--text);
    background: white;
}
textarea { resize: vertical; }
.check-row { display: flex; align-items: center; gap: 9px; }
.check-row input { width: auto; }
.form-actions { display: flex; align-items: end; }
.counterparty-analysis-filters { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.counterparty-analysis-filters .form-actions {
    grid-column: 1 / -1;
    gap: 10px;
    flex-wrap: wrap;
}
.counterparty-analysis-filters .form-actions > * { white-space: nowrap; }
.count-condition {
    display: grid;
    grid-template-columns: 76px minmax(100px, 1fr);
    gap: 8px;
}
.primary-button { background: var(--red); color: white; }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; background: white; color: var(--blue); border: 1px solid var(--line); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.alert {
    padding: 13px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    border: 1px solid;
}
.alert.success { background: #edf8ee; border-color: #badfbe; color: #295c30; }
.alert.error { background: #fff0f1; border-color: #f0bdc2; color: #8f1720; }
.totals-note { color: var(--muted); font-size: 13px; }
.report-form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.autosave-status { color: var(--muted); font-size: 13px; font-weight: 700; }
.autosave-status.saving { color: #87530c; }
.autosave-status.saved { color: #295c30; }
.autosave-status.error { color: #8f1720; }
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.metric { padding: 16px; }
.metric-link { display: block; color: inherit; }
.metric-link:hover, .metric-link.active { border-color: var(--blue); color: inherit; }
.metric span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metric strong { font-size: 28px; color: var(--blue-dark); }
.metric small {
    display: block;
    margin-top: 9px;
    font-weight: 700;
}
.delta.positive { color: #295c30; }
.delta.negative { color: #8f1720; }
.delta.neutral { color: var(--muted); }
.charts-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.chart-panel { min-width: 0; }
.insight-list { display: grid; gap: 10px; }
.insight {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px 14px;
    font-weight: 700;
}
.insight.ok { background: #edf8ee; border-color: #badfbe; color: #295c30; }
.insight.warning { background: #fff6e8; border-color: #f3d8a8; color: #87530c; }
.insight.danger { background: #fff0f1; border-color: #f0bdc2; color: #8f1720; }
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 10px;
}
.table-toolbar h2 { margin: 0; }
.table-toolbar span { color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
.brief-report-table { min-width: 620px; }
.brief-report-table th:not(:first-child), .brief-report-table td { text-align: center; }
.brief-report-table tbody th { color: var(--text); font-size: 14px; text-transform: none; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.sort-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.sort-link.active, .sort-link:hover { color: var(--blue); }
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.pager-summary { color: var(--muted); font-size: 13px; font-weight: 700; }
.pager-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-link, .pager-gap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    padding: 8px 11px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
}
.pager-link {
    border: 1px solid var(--line);
    background: white;
    color: var(--blue);
}
.pager-link:hover { border-color: var(--blue); color: var(--blue-dark); }
.pager-link.active { background: var(--blue); border-color: var(--blue); color: white; }
.pager-link.disabled { color: var(--muted); background: #f6f8fb; cursor: default; }
.pager-gap { color: var(--muted); min-width: 24px; padding-left: 4px; padding-right: 4px; }
.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    background: #eef2f7;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.status-pending { background: #fff6e8; color: #87530c; }
.status-failed { background: #fff0f1; color: #8f1720; }
.status-completed { background: #edf8ee; color: #295c30; }
.detail-grid {
    display: grid;
    grid-template-columns: minmax(160px, 220px) 1fr;
    gap: 12px 18px;
    margin: 0;
}
.detail-grid dt { color: var(--muted); font-weight: 700; }
.detail-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .filter-bar, .form-grid, .metric-grid, .charts-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .content { padding: 18px; }
}
