:root {
    --blue: #0b63d8;
    --blue-dark: #084eae;
    --page: #f4f7fb;
    --surface: #ffffff;
    --text: #182234;
    --muted: #68758a;
    --border: #dce5ef;
    --border-strong: #cbd7e5;
    --green: #229653;
    --orange: #ea5b1b;
    --cyan: #138b9e;
    --danger: #c63c3c;
}

* { box-sizing: border-box; }

html, body {
    min-height: 100%;
    margin: 0;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--page);
    font-size: 14px;
    letter-spacing: 0;
}

body { min-width: 320px; }
a { color: var(--blue); }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
h1:focus { outline: none; }

.app-shell { min-height: 100vh; }

.app-header {
    height: 48px;
    color: #fff;
    background: var(--blue);
    border-bottom: 1px solid rgba(0, 0, 0, .08);
}

.header-inner,
.nav-inner,
.app-main {
    width: min(1180px, calc(100% - 28px));
    margin: 0 auto;
}

.header-inner {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
}

.brand-mark,
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.brand-mark svg { width: 18px; height: 18px; }

.environment-badge {
    padding: 2px 8px;
    color: #084a9d;
    background: #dcecff;
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
}

.account-area { margin-left: auto; }
.account-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}

.avatar {
    width: 26px;
    height: 26px;
    color: var(--blue);
    background: #fff;
    border-radius: 50%;
}
.avatar svg { width: 15px; height: 15px; }

.main-nav {
    height: 48px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 5px rgba(23, 46, 77, .07);
}

.nav-inner {
    height: 100%;
    display: flex;
    align-items: stretch;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav-inner::-webkit-scrollbar { display: none; }

.nav-entry {
    position: relative;
    min-width: 112px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: #36445a;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.nav-entry svg { width: 15px; height: 15px; }
.nav-entry:hover { color: var(--blue); }
.nav-entry.active { color: var(--blue); }
.nav-entry.active::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 0;
    height: 2px;
    background: var(--blue);
}

.logout-form { margin-left: auto; display: flex; align-items: center; }
.logout-button { color: #59677a; }

.app-main { padding-top: 16px; padding-bottom: 28px; }

.workspace {
    width: 100%;
    padding: 18px;
    background: var(--surface);
    border: 1px solid #e5ebf3;
    border-radius: 7px;
    box-shadow: 0 3px 12px rgba(28, 50, 80, .06);
}

.section-heading {
    min-height: 38px;
    margin-bottom: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}
.section-heading h1 { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 750; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

.filter-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 10px 12px;
    align-items: end;
}
.field-service, .field-sender { grid-column: span 5; }
.field-date { grid-column: span 3; }
.field-criterion { grid-column: span 4; }
.field-counterparty { grid-column: span 5; }
.load-button { grid-column: span 2; width: 100%; }

.field { display: flex; min-width: 0; flex-direction: column; gap: 5px; }
.field > span { color: #435066; font-size: 10px; font-weight: 700; }
.field input,
.field select {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    color: #263247;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    outline: none;
    font-size: 11px;
}
.field input::placeholder { color: #98a3b2; }
.field input:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11, 99, 216, .12); }

.primary-button,
.secondary-button {
    min-height: 34px;
    padding: 0 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.primary-button { color: #fff; background: var(--blue); border: 1px solid var(--blue); }
.primary-button:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.secondary-button { color: var(--blue); background: #fff; border: 1px solid #a9c7ea; }
.secondary-button:hover { background: #f1f7ff; }
.primary-button svg, .secondary-button svg { width: 14px; height: 14px; }

.icon-button {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #536175;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
}
.icon-button:hover { color: var(--blue); background: #eef5fd; border-color: #d6e5f7; }
.icon-button svg { width: 15px; height: 15px; }

.status-row {
    margin: 15px 0 10px;
    padding-top: 9px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #536175;
    border-top: 1px solid #edf1f6;
    font-size: 10px;
}
.load-status, .last-run { display: inline-flex; align-items: center; gap: 6px; }
.status-dot { width: 8px; height: 8px; background: #35a85b; border-radius: 50%; }
.status-dot.neutral { background: #9aa5b4; }
.last-run svg { width: 12px; height: 12px; }

.metric-grid {
    margin-bottom: 10px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}
.metric-card {
    min-width: 0;
    height: 70px;
    padding: 11px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.metric-card > div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.metric-label { overflow: hidden; text-overflow: ellipsis; font-size: 10px; font-weight: 700; white-space: nowrap; }
.metric-card strong { font-size: 20px; line-height: 1; }
.metric-card > svg { width: 21px; height: 21px; flex: 0 0 auto; }
.metric-card.blue { color: #1469dc; border-color: #cfe0f7; }
.metric-card.cyan { color: var(--cyan); border-color: #cae4e8; }
.metric-card.green { color: var(--green); border-color: #cee8d6; }
.metric-card.orange { color: var(--orange); border-color: #f1d7ca; }
.metric-card.gray { color: #667085; border-color: #dce2e9; }
.dashboard-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.table-shell { overflow: hidden; border: 1px solid var(--border); border-radius: 6px; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11px; }
.data-table th {
    height: 32px;
    padding: 0 12px;
    color: #344054;
    background: #edf2f7;
    text-align: left;
    font-size: 10px;
    font-weight: 750;
}
.data-table td { height: 35px; padding: 0 12px; color: #354156; border-top: 1px solid #e8edf3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table th:nth-child(1), .data-table td:nth-child(1) { width: 14%; }
.data-table th:nth-child(2), .data-table td:nth-child(2) { width: 18%; }
.data-table th:nth-child(4), .data-table td:nth-child(4),
.data-table th:nth-child(5), .data-table td:nth-child(5) { width: 16%; }
.number-column { text-align: right !important; font-variant-numeric: tabular-nums; }
.reference-cell { font-family: Consolas, monospace; }
.matched-row td { background: #f1faf4; }
.table-footer { min-height: 46px; padding: 7px 10px 7px 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: #f8fafc; border-top: 1px solid var(--border); }
.totals { display: flex; align-items: center; gap: 60px; font-size: 10px; }

.date-chip, .role-badge, .state-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.date-chip, .role-badge { color: #31557d; background: #edf4fb; border: 1px solid #d9e7f5; }
.state-badge.active { color: #187743; background: #e8f6ed; }
.state-badge.inactive { color: #7b4a4a; background: #f7eded; }

.empty-state, .upload-zone {
    min-height: 250px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px dashed #c9d6e5;
    border-radius: 6px;
    background: #fafcfe;
}
.empty-state.compact { min-height: 180px; margin-top: 14px; }
.empty-state > svg, .upload-zone > svg { width: 28px; height: 28px; margin-bottom: 10px; color: #7690ad; }
.empty-state h2, .upload-zone h2 { margin: 0; font-size: 14px; }
.empty-state p, .upload-zone p { margin: 5px 0 16px; color: var(--muted); font-size: 11px; }
.consultation-filters .field { grid-column: span 3; }
.consultation-filters .load-button { grid-column: span 3; }
.consultation-results, .import-history { margin-top: 14px; }

.import-grid {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) minmax(260px, 2fr) 130px;
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
}
.file-field input[type="file"] {
    width: 100%;
    height: 34px;
    padding: 5px 8px;
    color: #435066;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    font-size: 10px;
}
.reconciliation-table th:nth-child(n), .reconciliation-table td:nth-child(n),
.consultation-table th:nth-child(n), .consultation-table td:nth-child(n),
.import-table th:nth-child(n), .import-table td:nth-child(n),
.dashboard-table th:nth-child(n), .dashboard-table td:nth-child(n),
.report-table th:nth-child(n), .report-table td:nth-child(n) { width: auto; }
.reconciliation-table th:first-child { width: 12%; }
.reconciliation-table th:nth-child(2) { width: 13%; }
.reconciliation-table th:nth-child(3) { width: 18%; }
.reconciliation-table th:nth-child(5), .reconciliation-table th:nth-child(6) { width: 14%; }

.notice { margin: 0 0 12px; padding: 9px 11px; border: 1px solid; border-radius: 5px; font-size: 11px; }
.notice-success { color: #176a3c; background: #edf8f1; border-color: #cde8d6; }
.notice-error { color: #963434; background: #fdf1f1; border-color: #efcccc; }
.validation-summary { margin-bottom: 12px; color: var(--danger); font-size: 11px; }
.validation-summary ul { margin: 0; padding-left: 18px; }

.editor-panel, .settings-section { margin-bottom: 14px; padding: 14px; background: #f9fbfd; border: 1px solid var(--border); border-radius: 6px; }
.panel-heading { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.panel-heading h2, .settings-heading h2 { margin: 0; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; }
.form-action { display: flex; align-items: end; }
.form-action .primary-button { width: 100%; }
.admin-table .data-table th:nth-child(n), .admin-table .data-table td:nth-child(n) { width: auto; }
.admin-table .data-table th:first-child { width: 22%; }
.admin-table .data-table th:nth-child(2) { width: 30%; }
.admin-table .action-column { width: 100px !important; text-align: right; }
.table-empty { height: 70px !important; color: var(--muted) !important; text-align: center; }

.settings-workspace { max-width: 860px; margin: 0 auto; }
.settings-heading { margin-bottom: 14px; display: flex; align-items: flex-start; gap: 10px; }
.settings-heading > svg { width: 18px; height: 18px; color: var(--blue); }
.settings-heading p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.settings-grid .span-two { grid-column: span 2; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; }

#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; padding: 10px 18px; color: #fff; background: #9e3434; box-shadow: 0 -1px 4px rgba(0,0,0,.2); }
#blazor-error-ui .dismiss { float: right; color: #fff; background: transparent; border: 0; }

@media (max-width: 720px) {
    .header-inner, .nav-inner, .app-main { width: calc(100% - 16px); }
    .account-link > span:first-child { display: none; }
    .main-nav { height: 44px; }
    .nav-inner { gap: 2px; }
    .nav-entry { min-width: max-content; padding: 0 5px; gap: 3px; font-size: 9px; }
    .nav-entry.active::after { left: 6px; right: 6px; }
    .logout-form { margin-left: 0; }
    .workspace { padding: 12px; }
    .metric-grid { gap: 5px; }
    .metric-card { height: 60px; padding: 8px; }
    .metric-card strong { font-size: 15px; }
    .metric-card > svg { display: none; }
    .metric-label { font-size: 8px; }
    .data-table th, .data-table td { padding: 0 7px; }
    .totals { gap: 16px; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .consultation-filters .field, .consultation-filters .load-button { grid-column: span 6; }
    .import-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
    .environment-badge { display: none; }
    .section-heading { align-items: flex-start; }
    .section-heading p { display: none; }
    .status-row { align-items: flex-start; gap: 6px; }
    .last-run { justify-content: flex-end; text-align: right; }
    .metric-grid { grid-template-columns: repeat(5, minmax(58px, 1fr)); overflow-x: auto; padding-bottom: 3px; }
    .field-service, .field-sender { grid-column: span 6; }
    .field-date, .field-criterion, .field-counterparty { grid-column: span 6; }
    .load-button { grid-column: span 6; }
    .dashboard-metrics { grid-template-columns: 1fr; }
    .table-shell { overflow-x: auto; }
    .data-table { min-width: 540px; }
    .table-footer { min-width: 540px; }
    .form-grid { grid-template-columns: 1fr; }
    .settings-grid .span-two { grid-column: span 1; }
    .import-grid { grid-template-columns: 1fr; }
}
