:root {
    --bg: #F3F4F1;
    --panel: #FFFFFF;
    --ink: #1C242B;
    --muted: #6B7580;
    --line: #DDE1E0;
    --schedule: #2E6E8E;
    --cost: #B5772E;
    --ok: #3F8F5F;
    --exception: #C1443A;
    --exception-bg: #FBEEEC;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Public Sans", -apple-system, sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

code {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    background: #EDEFEC;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.92em;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 32px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}
.brand-logo-link { display: flex; align-items: center; flex-shrink: 0; }
.brand-logo { height: 28px; width: auto; display: block; }
.brand-divider { color: var(--line); font-weight: 300; }
.brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: -0.01em;
}
.brand-link { color: var(--schedule); }
.brand-sub { color: var(--muted); font-size: 0.85rem; flex: 1; }
.topnav a {
    color: var(--schedule);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid var(--schedule);
    padding: 6px 14px;
    border-radius: 5px;
}
.topnav a:hover { background: var(--schedule); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 28px 32px 80px; }

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}
.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 18px 20px;
    border-left: 3px solid var(--schedule);
}
.stat-cost { border-left-color: var(--cost); }
.stat-exception { border-left-color: var(--exception); }
.stat-value { font-family: "IBM Plex Mono", monospace; font-size: 1.7rem; font-weight: 600; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 22px 24px;
    margin-bottom: 22px;
}
.panel-head h1, .panel-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.panel-sub { color: var(--muted); font-size: 0.87rem; margin: 0 0 16px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
    text-align: left;
    padding: 8px 10px;
    color: var(--muted);
    font-weight: 500;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #EEF0EE;
    white-space: nowrap;
}
.data-table td.descr { white-space: normal; min-width: 220px; }
.data-table .num { text-align: right; }
.data-table tr.row-exception { background: var(--exception-bg); }
.data-table tr:hover { background: #F7F8F6; }
.data-table tr.row-exception:hover { background: #F8E4E1; }

.code-link { color: var(--schedule); font-weight: 600; text-decoration: none; }
.code-link:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge-exception { background: var(--exception-bg); color: var(--exception); }
.badge-ok { background: #E9F4EC; color: var(--ok); }

.back-link {
    display: inline-block;
    margin-bottom: 18px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.back-link:hover { color: var(--ink); }

.detail-head { margin-bottom: 22px; }
.detail-head h1 { margin: 0 0 12px; font-size: 1.4rem; }
.detail-descr { color: var(--muted); font-weight: 400; font-size: 1rem; margin-left: 10px; }

.window-strip {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px 20px;
}
.window-item { display: flex; flex-direction: column; gap: 3px; }
.window-label { font-size: 0.78rem; font-weight: 600; text-transform: none; }
.schedule-color { color: var(--schedule); }
.cost-color { color: var(--cost); }
.exception-color { color: var(--exception); }
.ok-color { color: var(--ok); }

.chart-wrap { height: 320px; }

/* --- flash messages --- */
.flashes { margin-bottom: 20px; }
.flash { padding: 11px 16px; border-radius: 6px; margin-bottom: 8px; font-size: 0.9rem; }
.flash-success { background: #E9F4EC; color: var(--ok); border: 1px solid #CDE8D5; }
.flash-error { background: var(--exception-bg); color: var(--exception); border: 1px solid #F0CFCB; }

/* --- upload page --- */
.upload-panel { max-width: 560px; }
.current-data {
    background: #F5F6F4;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 0.87rem;
    margin-bottom: 20px;
}
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }
.field input[type="file"] {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #FBFBFA;
    font-size: 0.87rem;
}
.field input[type="text"],
.field input[type="password"] {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #FBFBFA;
    font-size: 0.87rem;
    font-family: inherit;
}
.field input[type="text"]:focus,
.field input[type="password"]:focus {
    outline: none;
    border-color: var(--schedule);
}
.field.checkbox-field label { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.submit-btn {
    display: inline-block;
    background: var(--ink);
    color: #fff;
    border: none;
    padding: 11px 22px;
    border-radius: 5px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.submit-btn:hover { background: #33404A; }

.empty-state { text-align: left; max-width: 560px; }
.empty-state h1 { margin-top: 0; }

/* --- processing overlay --- */
.processing-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(28, 36, 43, 0.72);
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.processing-overlay.visible { display: flex; }
.processing-box {
    background: #fff;
    border-radius: 8px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--line);
    border-top-color: var(--schedule);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-text { font-weight: 600; margin-bottom: 4px; }
.processing-sub { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 760px) {
    .stats { grid-template-columns: 1fr; }
    main { padding: 20px 16px 60px; }
    .topbar { flex-wrap: wrap; }
}

/* --- footer --- */
.site-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px 32px;
    margin-top: 40px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.82rem;
}
.footer-logo { height: 20px; width: auto; opacity: 0.75; }

/* --- mapping page --- */
.pair-sep { color: var(--muted); margin: 0 6px; font-weight: 600; }
.warning-note {
    background: #FBF4E8;
    border: 1px solid #EEDDB8;
    color: #8A5D1F;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin: 10px 0 0;
}
.mapping-table { margin-bottom: 24px; }
.inline-form { display: inline; }
.remove-btn {
    background: none;
    border: 1px solid var(--line);
    color: var(--exception);
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    cursor: pointer;
}
.remove-btn:hover { background: var(--exception-bg); }
.mapping-form { max-width: 520px; }
.mapping-form select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #FBFBFA;
    font-size: 0.87rem;
}

/* --- group detail header --- */
.key-part {
    display: inline-flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    line-height: 1.15;
}
.key-part-label {
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--muted);
    text-transform: none;
}
.detail-descr-line { color: var(--muted); margin: -6px 0 14px; }

/* --- login + users --- */
.login-panel { max-width: 380px; margin: 60px auto 0; }
.user-info { color: var(--muted); font-size: 0.85rem; margin-left: 4px; }
.user-info a { color: var(--schedule); text-decoration: none; }
.user-info a:hover { text-decoration: underline; }
.you-badge { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.role-btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.user-actions { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.reset-pw summary {
    cursor: pointer;
    color: var(--schedule);
    font-size: 0.85rem;
    list-style: none;
}
.reset-pw summary::-webkit-details-marker { display: none; }
.reset-pw[open] summary { margin-bottom: 6px; }
.reset-pw form { display: flex; gap: 6px; }
.reset-pw input[type="password"] {
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.82rem;
    width: 140px;
}
.small-btn { padding: 6px 12px; font-size: 0.82rem; }

/* --- sortable headers + per-column filter row --- */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px;
}
.data-table th.sortable:hover { color: var(--ink); }
.data-table th.sortable::after {
    content: '';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    opacity: 0.25;
}
.data-table th.sort-asc::after { border-bottom-color: var(--ink); opacity: 1; margin-top: -3px; }
.data-table th.sort-desc::after { border-top-color: var(--ink); opacity: 1; margin-top: 3px; }
.data-table tr.filter-row td {
    padding: 4px 6px;
    background: #FAFAF8;
}
.data-table .col-filter {
    width: 100%;
    min-width: 60px;
    padding: 5px 7px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: inherit;
    background: #fff;
}
.data-table .col-filter:focus {
    outline: none;
    border-color: var(--schedule);
}
