@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:wght@400;500;600&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #d8dee9;
    --accent: #1f7a68;
    --accent-dark: #155d50;
    --sidebar: #101828;
    --sidebar-soft: #1d2939;
    --danger: #b42318;
}

* { box-sizing: border-box; }
html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
body {
    margin: 0;
    font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--ink);
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
a { color: inherit; }
.app-shell { width: 100%; max-width: 100vw; min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); overflow-x: hidden; }
.sidebar { background: var(--sidebar); color: white; padding: 16px 13px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center;
    background: var(--accent); color: white; font-weight: 800;
}
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; color: #98a2b3; font-size: 11px; margin-top: 2px; }
.sidebar nav { margin-top: 24px; display: grid; gap: 5px; }
.sidebar nav a {
    color: #d0d5dd; text-decoration: none; padding: 9px 10px; border-radius: 7px;
    font-size: 12px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: var(--sidebar-soft); color: white; }
.main { min-width: 0; max-width: 100%; overflow-x: hidden; }
.topbar {
    min-height: 60px; padding: 12px 20px; background: white; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h1 { margin: 0; font-size: 19px; line-height: 1.2; }
.userbar { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.content { padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; max-width: 100%; overflow-x: hidden; }
.content > * { min-width: 0; max-width: 100%; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric, .panel {
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
    min-width: 0;
}
.metric { padding: 14px; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 24px; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(320px, .7fr); gap: 14px; }
.dashboard-top-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
}
.dashboard-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(260px, .55fr);
    gap: 14px;
    align-items: start;
}
.compact-panel {
    justify-self: start;
    width: 100%;
    max-width: 360px;
}
.panel { overflow: hidden; }
.panel-head {
    padding: 11px 13px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.panel-head h2 { margin: 0; font-size: 14px; }
.panel-head a { color: var(--accent-dark); font-weight: 600; text-decoration: none; }
.plain-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.plain-table th, .plain-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.plain-table th { background: #f8fafc; color: #475467; font-weight: 700; }
.compact-table { font-size: 12px; }
.compact-table th, .compact-table td { padding: 7px 9px; }
.number-cell {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.table-subline {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; background: #eef4ff; color: #3538cd; font-weight: 600; }
.button {
    display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 7px 11px;
    border-radius: 7px; border: 1px solid var(--line); text-decoration: none; cursor: pointer; font-weight: 700;
    font-size: 12px;
}
.button.small { min-height: 28px; padding: 5px 9px; font-size: 11px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: white; color: var(--ink); }
.button.full { width: 100%; }
.filters-row, .report-toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: end;
    background: white; border: 1px solid var(--line); border-radius: 8px; padding: 9px;
}
label { display: grid; gap: 3px; color: #344054; font-size: 11px; font-weight: 700; }
input, select {
    min-height: 31px; border: 1px solid #cfd6e4; border-radius: 7px; padding: 5px 8px;
    background: white; color: var(--ink); min-width: 136px; font: inherit; font-size: 12px;
}
.search-input { min-width: 250px; }
.compact-filters { gap: 6px; padding: 7px; }
.compact-filters label { max-width: 190px; }
.compact-filters .wide-filter { max-width: 270px; }
.compact-filters input, .compact-filters select { min-height: 29px; padding: 4px 7px; }
.filter-actions { display: flex; align-items: end; min-height: 45px; }
.companies-report-shell, #companies-report {
    width: 100%;
    max-width: min(100%, calc(100vw - 270px));
    min-width: 0;
    overflow-x: hidden;
    contain: inline-size;
}
.table-shell { background: white; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-width: 0; width: 100%; max-width: 100%; contain: inline-size; }
.table-meta { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; min-width: 0; max-width: 100%; }
.table-meta > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-meta { padding: 7px 9px; gap: 8px; }
.toolbar-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 7px; max-width: 100%; }
.sort-summary {
    display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px;
    max-width: min(520px, 44vw); color: var(--muted); font-size: 11px;
}
.sort-chip {
    display: inline-flex; align-items: center; max-width: 190px; min-height: 24px; padding: 3px 7px;
    border: 1px solid #cfd6e4; border-radius: 999px; background: #f8fafc; color: #344054;
    cursor: pointer; font: inherit; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: "IBM Plex Sans Condensed", "Manrope", ui-sans-serif, system-ui, sans-serif;
    font-size: 12px;
}
.data-table th, .data-table td {
    padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top;
    background: white;
}
.data-table th {
    position: sticky; top: 0; z-index: 3; background: #f8fafc; color: #475467; white-space: nowrap;
    font-weight: 600; box-shadow: inset 0 -1px 0 var(--line);
}
.data-table td { max-width: 360px; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:nth-child(even) td { background: #f8fbff; }
.data-table tbody tr:hover td { background: #eaf6f1; }
.data-table tbody tr.is-selected td,
.data-table tbody tr.is-selected:hover td {
    background: #d8f4e8;
    box-shadow: inset 0 1px 0 rgba(31, 122, 104, .12), inset 0 -1px 0 rgba(31, 122, 104, .12);
}
.table-scroll-top {
    display: block; width: 100%; max-width: 100%; min-width: 0; height: 16px;
    overflow-x: auto; overflow-y: hidden; background: #fbfcfe; border-bottom: 1px solid var(--line);
}
.table-scroll-top::-webkit-scrollbar, .table-scroll::-webkit-scrollbar { height: 12px; width: 12px; }
.table-scroll-top::-webkit-scrollbar-thumb, .table-scroll::-webkit-scrollbar-thumb { background: #98a2b3; border-radius: 999px; border: 3px solid #eef2f7; }
.table-scroll-spacer { height: 1px; }
.table-scroll { display: block; width: 100%; max-width: 100%; min-width: 0; overflow: auto; overscroll-behavior-x: contain; }
.companies-scroll { max-height: calc(100vh - 238px); }
.audit-scroll { max-height: calc(100vh - 210px); }
.wide-table { width: max-content; min-width: 100%; table-layout: auto; }
.resizable-table { table-layout: fixed; }
.dense-table { font-size: 11px; line-height: 1.2; }
.dense-table th, .dense-table td { min-width: 112px; max-width: 260px; padding: 5px 7px; }
.dense-table th {
    position: sticky;
}
.table-sort-button {
    display: inline-flex; align-items: center; justify-content: flex-start; gap: 5px; width: calc(100% - 8px);
    min-height: 20px; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer;
    font: inherit; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden;
}
.table-sort-button span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.column-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    z-index: 5;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
}
.column-resize-handle::after {
    content: "";
    position: absolute;
    top: 7px;
    right: 3px;
    width: 2px;
    height: calc(100% - 14px);
    border-radius: 999px;
    background: transparent;
}
.resizable-table th { position: sticky; }
.resizable-table th:hover .column-resize-handle::after { background: #cfd6e4; }
.resizable-table th .column-resize-handle:hover::after { background: var(--accent); }
.sort-marker {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 16px;
    padding: 0 4px; border-radius: 999px; background: #d1fadf; color: #067647; font-size: 10px; font-weight: 700;
}
.dense-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dense-table th:nth-child(3), .dense-table td:nth-child(3) { min-width: 240px; }
.dense-table th:nth-child(7), .dense-table td:nth-child(7) { min-width: 150px; }
.column-panel { border-bottom: 1px solid var(--line); background: #fbfcfe; padding: 9px; display: grid; gap: 8px; }
.column-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.column-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 10px; max-height: 220px; overflow: auto; padding: 2px; }
.check-label, .switch-label {
    display: flex; align-items: center; gap: 8px; min-height: 27px; padding: 4px 6px; border-radius: 6px;
    color: #344054; font-size: 11px; font-weight: 600;
}
.check-label:hover, .switch-label:hover { background: #eef2f7; }
.switch-label input { position: absolute; opacity: 0; pointer-events: none; }
.switch-control {
    flex: 0 0 auto; width: 30px; height: 16px; border-radius: 999px; background: #cfd6e4;
    position: relative; transition: background .15s ease;
}
.switch-control::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
    background: white; box-shadow: 0 1px 2px rgba(16, 24, 40, .25); transition: transform .15s ease;
}
.switch-label input:checked + .switch-control { background: var(--accent); }
.switch-label input:checked + .switch-control::after { transform: translateX(14px); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.muted { color: var(--muted); }
.negative { color: var(--danger); }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 12px; }
.compact-pagination { padding: 7px 9px; font-size: 12px; }
.login-page { min-height: 100vh; display: grid; place-items: center; background: #eef2f7; }
.login-box {
    width: min(420px, calc(100vw - 32px)); background: white; border: 1px solid var(--line);
    border-radius: 8px; padding: 24px; display: grid; gap: 16px; box-shadow: 0 12px 40px rgba(16, 24, 40, .10);
}
.login-brand { margin-bottom: 6px; }
.alert { background: #fef3f2; border: 1px solid #fecdca; color: var(--danger); padding: 10px 12px; border-radius: 7px; }

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .stats-grid, .split-grid, .dashboard-top-grid, .dashboard-detail-grid { grid-template-columns: 1fr; }
    .compact-panel { max-width: 100%; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .search-input { min-width: 100%; }
    .companies-report-shell, #companies-report { max-width: calc(100vw - 32px); }
}
