:root {
    --bg: #f4f7fb;
    --surface: rgba(255, 255, 255, 0.94);
    --surface-strong: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: rgba(148, 163, 184, 0.24);
    --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
    --primary: #1F2937;
    --accent: #2563EB;
    --warning: #F59E0B;
    --danger: #EF4444;
    --success: #10b981;
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 24rem),
        radial-gradient(circle at top right, rgba(245, 158, 11, 0.1), transparent 18rem),
        linear-gradient(180deg, #eef4ff 0%, #f8fafc 24%, #f4f7fb 100%);
    overflow: hidden;
    height: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

svg {
    width: 1.2rem;
    height: 1.2rem;
    fill: currentColor;
    display: block;
}

.hidden {
    display: none !important;
}

.page-loader {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background: rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(4px);
    opacity: 1;
    visibility: visible;
    transition: opacity 180ms ease, visibility 180ms ease;
}

.page-loader[hidden] {
    display: none !important;
}

.page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader__card {
    min-width: min(320px, calc(100vw - 2.5rem));
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 20px;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
    padding: 1rem 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.page-loader__spinner {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    border: 2px solid rgba(37, 99, 235, 0.24);
    border-top-color: var(--accent);
    animation: spin 700ms linear infinite;
    flex-shrink: 0;
}

.page-loader__label {
    margin: 0;
    color: var(--primary);
    font-size: 0.92rem;
    font-weight: 600;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.app-shell {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
}

.app-header {
    padding: 1.25rem 1rem 0;
}

.app-header--minimal {
    padding: 0;
}

.top-company-name {
    background: linear-gradient(90deg, #1f2937, #2563eb);
    color: #fff;
    padding: 0.65rem 1rem;
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.brand-row {
    background: linear-gradient(135deg, rgba(31, 41, 55, 0.96), rgba(37, 99, 235, 0.9));
    color: #fff;
    border-radius: calc(var(--radius) + 6px);
    padding: 1.4rem;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.brand-row::after {
    content: "";
    position: absolute;
    inset: auto -2rem -3rem auto;
    width: 9rem;
    height: 9rem;
    background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 68%);
}

.eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    opacity: 0.74;
}

.brand-row h1,
.panel h2,
.health-card h2,
.summary-card h2 {
    margin: 0;
    line-height: 1.1;
}

.header-copy,
.panel__header p,
.health-card p,
.summary-meta span,
.metric-card__meta,
.report-link p,
.chart-card__header span,
.table-loading,
.table-empty {
    color: var(--muted);
}

.header-copy {
    margin: 0.55rem 0 0;
    color: rgba(255, 255, 255, 0.8);
    max-width: 38rem;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1rem;
    padding: 0.65rem 0.9rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
    font-size: 0.85rem;
}

.page-content {
    padding: 1rem;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding-bottom: 7rem;
}

.hero-grid,
.metric-grid,
.chart-grid,
.report-grid {
    display: grid;
    gap: 1rem;
}

.health-card,
.panel,
.summary-card,
.chart-card,
.report-link,
.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.health-card {
    padding: 1.2rem;
    display: grid;
    gap: 1rem;
}

.health-score {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(31, 41, 55, 0.08));
    border-radius: calc(var(--radius) - 6px);
}

.health-score__value {
    font-size: clamp(2.6rem, 10vw, 4.6rem);
    font-weight: 800;
    color: var(--primary);
}

.health-score__total {
    font-size: 1.3rem;
    color: var(--muted);
}

.health-score__label,
.health-score__delta {
    width: 100%;
    margin: 0;
}

.health-score__label {
    color: var(--primary);
    font-weight: 600;
}

.health-score__delta {
    color: var(--accent);
    font-size: 0.92rem;
}

.panel {
    padding: 1rem;
    margin-top: 1rem;
}

.panel__header {
    margin-bottom: 1rem;
}

.metric-card {
    padding: 1rem;
    display: flex;
    gap: 0.9rem;
    align-items: flex-start;
    min-height: 100%;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.metric-card:hover,
.report-link:hover {
    transform: translateY(-2px);
}

.metric-card__icon {
    width: 2.8rem;
    height: 2.8rem;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: rgba(31, 41, 55, 0.08);
    flex-shrink: 0;
}

.metric-card__title {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.metric-card__value {
    margin: 0.25rem 0;
    font-size: 1.8rem;
}

.metric-card--warning .metric-card__icon,
.status-warning {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.14);
}

.metric-card--danger .metric-card__icon,
.status-danger {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.12);
}

.metric-card--neutral .metric-card__icon,
.status-neutral {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.12);
}

.chart-card {
    padding: 1rem;
}

.chart-card__canvas {
    position: relative;
    height: 220px;
    min-height: 220px;
}

.chart-card__canvas canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.chart-card__header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-card__header h3,
.report-link h3 {
    margin: 0;
}

.report-link {
    padding: 1rem;
    display: block;
    position: relative;
    overflow: hidden;
}

.report-link::after {
    content: "Open report";
    display: inline-flex;
    margin-top: 0.85rem;
    color: var(--accent);
    font-weight: 600;
}

.summary-card {
    padding: 1.2rem;
    margin-bottom: 1rem;
}

.summary-meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: capitalize;
    background: rgba(15, 23, 42, 0.08);
    color: var(--primary);
}

.table-shell {
    display: grid;
    gap: 0.7rem;
}

.table-main {
    display: grid;
    gap: 0.7rem;
}

.table-wrap {
    width: 100%;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 14px;
    border: 1px solid rgba(37, 99, 235, 0.20);
    background: rgba(219, 234, 254, 0.35);
}

.audit-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.5rem;
    font-size: 0.84rem;
    table-layout: fixed;
}

.audit-table thead {
    display: none;
}

.audit-table th.is-sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
}

.audit-table th.is-sortable::after {
    content: "↕";
    margin-left: 0.35rem;
    font-size: 0.72rem;
    color: #64748b;
}

.audit-table th.is-sortable[data-sort-direction="asc"]::after {
    content: "↑";
    color: #1d4ed8;
}

.audit-table th.is-sortable[data-sort-direction="desc"]::after {
    content: "↓";
    color: #1d4ed8;
}

.audit-table tbody,
.audit-table tr,
.audit-table td {
    display: block;
    width: 100%;
}

.audit-table tr {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    padding: 0.2rem 0;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
    cursor: pointer;
}

.audit-table td {
    padding: 0.45rem 0.72rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.audit-table .cell-text {
    display: inline-block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-table .col-reference-id .cell-text {
    max-width: 18rem;
}

.audit-table .col-entity .cell-text {
    max-width: 7rem;
}

.audit-table .col-date .cell-text {
    max-width: 13ch;
}

.audit-table .col-amount {
    justify-content: space-between;
}

.audit-table .col-amount .cell-text {
    margin-left: auto;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.audit-table .col-action {
    justify-content: space-between;
}

.action-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
    padding: 0.22rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.action-pill__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    font-size: 0.68rem;
    line-height: 1;
    background: rgba(255, 255, 255, 0.75);
}

.action-pill--danger {
    color: #991b1b;
    background: rgba(254, 226, 226, 0.95);
}

.action-pill--warning {
    color: #92400e;
    background: rgba(254, 243, 199, 0.95);
}

.action-pill--neutral {
    color: #1f2937;
    background: rgba(226, 232, 240, 0.95);
}

.audit-table td:last-child {
    border-bottom: 0;
}

.audit-table td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.detail-panel {
    background: rgba(255, 247, 237, 0.78);
    border: 1px solid rgba(245, 158, 11, 0.24);
    border-radius: 14px;
    padding: 0.75rem;
    max-height: none;
    overflow: visible;
}

.detail-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.55rem;
}

.detail-panel__header h3 {
    margin: 0;
    font-size: 0.95rem;
}

.detail-panel__actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.detail-grid {
    display: grid;
    gap: 0.45rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-item {
    background: rgba(255, 255, 255, 0.85);
    border-radius: 10px;
    padding: 0.55rem 0.62rem;
    border: 1px solid rgba(148, 163, 184, 0.16);
}

.detail-item strong,
.audit-table .cell-status {
    text-transform: capitalize;
    font-size: 0.84rem;
    line-height: 1.25;
}

.detail-item .eyebrow {
    font-size: 0.64rem;
    margin-bottom: 0.18rem;
}

@media (max-width: 520px) {
    .detail-grid {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}

.detail-toggle-btn {
    border: 0;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font: inherit;
    font-size: 0.78rem;
    padding: 0.4rem 0.62rem;
    cursor: pointer;
}

.report-filter-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.4rem;
    margin-bottom: 0.8rem;
}

.report-filter-tab {
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(255, 255, 255, 0.82);
    color: var(--text);
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    font: inherit;
    font-size: 0.78rem;
    white-space: nowrap;
    cursor: pointer;
}

.report-filter-tab.is-active {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

.mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.75rem 0.8rem calc(0.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(90deg, rgba(31, 41, 55, 0.98), rgba(37, 99, 235, 0.95));
    border-top: 0;
    backdrop-filter: blur(12px);
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    z-index: 20;
}

.mobile-nav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.65rem 0.35rem;
    border-radius: 16px;
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.72rem;
    min-width: 5.8rem;
    flex: 0 0 auto;
}

.mobile-nav__link span {
    white-space: nowrap;
}

.mobile-nav__link.is-active {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.error-box {
    padding: 1rem;
    border-radius: 18px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.14);
    color: var(--danger);
}

@media (min-width: 700px) {
    .app-header,
    .page-content {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    .brand-row {
        padding: 1.7rem;
    }

    .health-card {
        grid-template-columns: 1.2fr 0.8fr;
        align-items: center;
    }

    .metric-grid,
    .report-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-card__canvas {
        height: 260px;
        min-height: 260px;
    }

    .summary-meta {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .audit-table {
        border-spacing: 0;
    }

    .audit-table thead {
        display: table-header-group;
    }

    .audit-table tbody {
        display: table-row-group;
    }

    .audit-table tr {
        display: table-row;
        border: 0;
        padding: 0;
        background: transparent;
        box-shadow: none;
    }

    .audit-table th,
    .audit-table td {
        display: table-cell;
        padding: 0.68rem 0.62rem;
        border-bottom: 1px solid rgba(148, 163, 184, 0.14);
        background: var(--surface-strong);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
        line-height: 1.2;
        font-size: 0.8rem;
    }

    .audit-table th:nth-child(1),
    .audit-table td:nth-child(1) {
        width: 28%;
    }

    .audit-table th:nth-child(2),
    .audit-table td:nth-child(2) {
        width: 11%;
    }

    .audit-table th:nth-child(3),
    .audit-table td:nth-child(3) {
        width: 13%;
        text-align: right;
    }

    .audit-table th:nth-child(4),
    .audit-table td:nth-child(4) {
        width: 12%;
    }

    .audit-table th:nth-child(5),
    .audit-table td:nth-child(5) {
        width: 10%;
    }

    .audit-table th:nth-child(6),
    .audit-table td:nth-child(6) {
        width: 11%;
        text-align: center;
        padding-right: 1rem;
    }

    .audit-table .col-reference-id .cell-text {
        max-width: none;
    }

    .audit-table .col-entity .cell-text {
        max-width: 8rem;
    }

    .audit-table .col-date .cell-text {
        max-width: 13ch;
    }

    .audit-table .col-risk-level .cell-status {
        max-width: 12ch;
    }

    .audit-table .col-amount .cell-text {
        width: 100%;
    }

    .audit-table .col-action {
        text-align: center;
        padding-right: 1rem;
    }

    .audit-table .col-action .action-pill {
        margin-left: auto;
        margin-right: 0.35rem;
    }

    .audit-table td::before {
        display: none;
    }

    .table-main {
        grid-template-columns: minmax(0, 1.45fr) minmax(290px, 0.95fr);
        align-items: start;
    }

    [data-table-shell="product-usage-table"] .audit-table th:nth-child(1),
    [data-table-shell="product-usage-table"] .audit-table td:nth-child(1) {
        width: 40%;
    }

    [data-table-shell="product-usage-table"] .audit-table th:nth-child(2),
    [data-table-shell="product-usage-table"] .audit-table td:nth-child(2),
    [data-table-shell="product-usage-table"] .audit-table th:nth-child(3),
    [data-table-shell="product-usage-table"] .audit-table td:nth-child(3),
    [data-table-shell="product-usage-table"] .audit-table th:nth-child(4),
    [data-table-shell="product-usage-table"] .audit-table td:nth-child(4) {
        width: 20%;
    }
}

@media (min-width: 1024px) {
    .app-shell {
        max-width: 1320px;
        margin: 0 auto;
        height: 100dvh;
    }

    .metric-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .report-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .page-content {
        padding-bottom: 1rem;
    }

    .mobile-nav {
        position: static;
        margin: 0 1.5rem 1.5rem;
        border: 1px solid rgba(148, 163, 184, 0.18);
        border-radius: 24px;
        display: grid;
        grid-template-columns: repeat(9, minmax(0, 1fr));
        overflow: visible;
        gap: 0.35rem;
        padding: 0.55rem;
    }

    .mobile-nav__link {
        min-width: 0;
        flex: initial;
    }
}

.health-score.health-status--healthy {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(31, 41, 55, 0.08));
}

.health-score.health-status--warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(31, 41, 55, 0.08));
}

.health-score.health-status--danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(31, 41, 55, 0.08));
}

.chart-grid--owner {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

.dashboard-tabs {
    display: grid;
    gap: 0.55rem;
}

.dashboard-tabs__nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
}

.dashboard-tab-btn {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.94);
    color: #1f2937;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.5rem 0.55rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dashboard-tab-btn.is-active {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.30);
    color: #1d4ed8;
}

.dashboard-tabs__content {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.7rem;
    min-height: min(64vh, 680px);
    overflow: auto;
}

.dashboard-tab-panel {
    display: none;
}

.dashboard-tab-panel.is-active {
    display: block;
}

.dashboard-tab-panel .panel {
    margin-top: 0;
}

.summary-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
}

.summary-kpi {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.85rem;
    background: rgba(255, 255, 255, 0.9);
}

.summary-kpi p {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.summary-kpi h3 {
    margin: 0.45rem 0 0;
    font-size: 1.3rem;
}

.report-chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.report-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.38rem 0.68rem;
    border: 1px solid rgba(37, 99, 235, 0.25);
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
    font-size: 0.78rem;
    font-weight: 600;
}

.table-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.table-toolbar {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.table-search {
    display: grid;
    gap: 0.3rem;
    min-width: 240px;
}

.table-search span {
    font-size: 0.76rem;
    font-weight: 700;
    color: #334155;
}

.table-search input {
    width: 100%;
    min-height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    padding: 0.65rem 0.8rem;
    font: inherit;
    background: rgba(255, 255, 255, 0.96);
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.table-action-btn {
    appearance: none;
    min-width: 42px;
    min-height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(255, 255, 255, 0.96);
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
    font-size: 1rem;
}

.table-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    border-color: rgba(15, 23, 42, 0.18);
}

.bill-detail-hero__actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.table-range-label {
    margin: 0.5rem 0 0.85rem;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    background: rgba(219, 234, 254, 0.35);
    border: 1px solid rgba(37, 99, 235, 0.18);
    color: #1e3a8a;
    font-size: 0.84rem;
    font-weight: 600;
}

.report-extra-view {
    margin-top: 1rem;
}

.history-table-wrap {
    overflow: auto;
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
}

.history-table {
    width: 100%;
    min-width: 1200px;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    padding: 0.7rem 0.65rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
    vertical-align: top;
    font-size: 0.8rem;
}

.history-table th {
    position: sticky;
    top: 0;
    background: #eff6ff;
    color: #1e3a8a;
    text-align: left;
    white-space: nowrap;
}

.history-table th.is-sortable {
    cursor: pointer;
    user-select: none;
}

.history-table th.is-sortable[data-sort-direction="asc"]::after {
    content: " ▲";
    font-size: 0.68rem;
}

.history-table th.is-sortable[data-sort-direction="desc"]::after {
    content: " ▼";
    font-size: 0.68rem;
}

.billing-calendar-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.billing-calendar-grid[data-view-mode="day"] {
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.billing-calendar-card {
    appearance: none;
    width: 100%;
    aspect-ratio: 1 / 0.88;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 20px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    padding: 14px;
    text-align: left;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.billing-calendar-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    border-color: rgba(15, 23, 42, 0.24);
}

.billing-calendar-card.has-issues {
    border-color: rgba(194, 65, 12, 0.28);
    background: linear-gradient(180deg, #fff7ed 0%, #ffffff 100%);
}

.billing-calendar-card.is-empty {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    cursor: default;
    box-shadow: none;
}

.billing-calendar-card.is-empty:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(15, 23, 42, 0.1);
}

.billing-calendar-card__label {
    font-size: 0.86rem;
    color: #475569;
    line-height: 1.3;
}

.billing-calendar-card__count {
    font-size: 1.9rem;
    line-height: 1;
    color: #0f172a;
    align-self: center;
}

.billing-calendar-card__lines {
    display: grid;
    gap: 6px;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    padding-top: 8px;
}

.billing-calendar-card__line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    color: #475569;
}

.billing-modal-toolbar {
    margin-bottom: 12px;
}

.billing-range-toolbar {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}

.billing-range-toolbar .table-range-label {
    flex: 1 1 420px;
    margin: 0;
}

.billing-offset-search {
    min-width: 150px;
}

.record-modal__table th[data-billing-sort] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.record-modal__table th[data-billing-sort][data-sort-direction="asc"]::after {
    content: " ▲";
    font-size: 0.68rem;
}

.record-modal__table th[data-billing-sort][data-sort-direction="desc"]::after {
    content: " ▼";
    font-size: 0.68rem;
}

.billing-calendar-card__line strong {
    font-weight: 600;
}

.billing-calendar-card__line em {
    font-style: normal;
    font-weight: 700;
    color: #0f172a;
}

@media (max-width: 1023px) {
    .billing-calendar-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .billing-calendar-grid[data-view-mode="day"] {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 699px) {
    .billing-calendar-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .billing-calendar-grid[data-view-mode="day"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .billing-calendar-card {
        aspect-ratio: auto;
        min-height: 130px;
    }
}

.history-product-cell {
    min-width: 220px;
}

.history-product-cell strong,
.history-product-cell small {
    display: block;
}

.history-product-cell small {
    color: var(--muted);
    margin-top: 0.15rem;
}

.history-cell-stack {
    display: grid;
    gap: 0.35rem;
}

.history-price-entry {
    display: grid;
    gap: 0.12rem;
    padding: 0.4rem 0.45rem;
    border-radius: 10px;
    background: rgba(219, 234, 254, 0.32);
    border: 1px solid rgba(37, 99, 235, 0.14);
    width: 100%;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.history-price-entry--neutral {
    background: rgba(219, 234, 254, 0.32) !important;
    border-color: rgba(37, 99, 235, 0.14) !important;
}

.history-price-entry--down {
    background: rgba(255, 237, 213, 0.92) !important;
    border-color: rgba(245, 158, 11, 0.54) !important;
}

.history-price-entry--up {
    background: rgba(254, 226, 226, 0.96) !important;
    border-color: rgba(239, 68, 68, 0.58) !important;
}

.history-price-entry[data-tone="down"] strong {
    color: #9a3412;
}

.history-price-entry[data-tone="up"] strong {
    color: #991b1b;
}

.history-price-entry strong {
    color: #0f172a;
}

.history-price-entry span {
    color: var(--muted);
    font-size: 0.72rem;
}

.history-empty {
    color: var(--muted);
}

.history-entry-note {
    display: block;
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.3;
}

.history-supplier-row {
    cursor: pointer;
}

.history-supplier-row.is-active td {
    background: rgba(219, 234, 254, 0.4);
}

.table-toolbar__date-range {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
    align-items: stretch;
    margin-right: auto;
    width: 100%;
    padding: 1rem 1.1rem;
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: 14px;
    background: rgba(219, 234, 254, 0.35);
}

.table-toolbar__date-range .table-filter {
    width: 100%;
}

.table-toolbar__date-range .table-filter input {
    width: 100%;
    min-height: 44px;
}

.table-toolbar__date-range .table-page-btn {
    width: 100%;
    min-height: 44px;
    grid-column: 1 / -1;
}

[data-table-shell="product-usage-table"] .filter-open-btn {
    margin-left: 0;
}

[data-table-shell="product-usage-table"] .table-search {
    margin-left: auto;
}

[data-table-shell="product-usage-table"] .audit-table {
    table-layout: auto;
}

[data-table-shell="product-usage-table"] .audit-table .col-avg-purchase-price,
[data-table-shell="product-usage-table"] .audit-table .col-avg-sales-price,
[data-table-shell="product-usage-table"] .audit-table .col-total-margin-value {
    text-align: right;
}

[data-table-shell="product-usage-table"] .audit-table .col-avg-purchase-price .cell-text,
[data-table-shell="product-usage-table"] .audit-table .col-avg-sales-price .cell-text,
[data-table-shell="product-usage-table"] .audit-table .col-total-margin-value .cell-text {
    width: 100%;
    display: inline-block;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

[data-table-shell="product-usage-table"] .audit-table .col-item-name .cell-text {
    max-width: 22rem;
}

@media (max-width: 699px) {
    .table-toolbar__date-range {
        grid-template-columns: 1fr;
    }

    .table-toolbar__date-range .table-page-btn {
        grid-column: auto;
    }
}

.filter-open-btn {
    border: 0;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font: inherit;
    font-size: 0.78rem;
    padding: 0.42rem 0.62rem;
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    cursor: pointer;
}

.filter-overlay {
    position: fixed;
    inset: 0;
    z-index: 125;
    display: grid;
    place-items: center;
    padding: 0.85rem;
}

.filter-overlay__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.filter-overlay__panel {
    position: relative;
    width: min(540px, 100%);
    background: #fff;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.26);
    padding: 0.75rem;
}

.filter-overlay__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.55rem;
}

.filter-overlay__header h4 {
    margin: 0;
    font-size: 0.9rem;
}

.filter-overlay__close {
    border: 0;
    border-radius: 8px;
    background: #1f2937;
    color: #fff;
    font: inherit;
    font-size: 0.74rem;
    padding: 0.35rem 0.58rem;
    cursor: pointer;
}

.filter-overlay__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.65rem;
}

.table-filter {
    display: grid;
    gap: 0.35rem;
}

.table-filter span {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.table-filter input {
    border: 1px solid rgba(148, 163, 184, 0.34);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    font: inherit;
    background: rgba(255, 255, 255, 0.94);
}

.table-filter select {
    border: 1px solid rgba(148, 163, 184, 0.34);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    font: inherit;
    background: rgba(255, 255, 255, 0.94);
}

.table-date-parts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
}

.table-reset,
.table-page-btn {
    border: 0;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.6rem 0.8rem;
    cursor: pointer;
}

.table-reset {
    align-self: end;
    background: rgba(148, 163, 184, 0.22);
    color: #111827;
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    gap: 0.75rem;
}

.table-page-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.table-page-meta {
    color: var(--muted);
    font-size: 0.9rem;
}

#criticalAlertsTable .clickable-row {
    cursor: pointer;
}

#criticalAlertsTable th:nth-child(1),
#criticalAlertsTable td:nth-child(1) {
    width: 29%;
}

#criticalAlertsTable th:nth-child(2),
#criticalAlertsTable td:nth-child(2) {
    width: 14%;
}

#criticalAlertsTable th:nth-child(3),
#criticalAlertsTable td:nth-child(3) {
    width: 15%;
}

#criticalAlertsTable th:nth-child(4),
#criticalAlertsTable td:nth-child(4) {
    width: 13%;
}

#criticalAlertsTable th:nth-child(5),
#criticalAlertsTable td:nth-child(5) {
    width: 12%;
}

#criticalAlertsTable th:nth-child(6),
#criticalAlertsTable td:nth-child(6) {
    width: 17%;
}

#criticalAlertsTable td:nth-child(2),
#criticalAlertsTable td:nth-child(6) {
    white-space: nowrap;
}

.record-modal {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: grid;
    place-items: center;
    padding: 0.9rem;
}

.record-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.record-modal__card {
    position: relative;
    width: min(980px, 100%);
    max-height: min(88vh, 900px);
    overflow: auto;
    background: #fff;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
    padding: 0.85rem;
}

.record-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
}

.record-modal__header h3 {
    margin: 0;
    font-size: 1rem;
}

.record-modal__close {
    border: 0;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font: inherit;
    font-size: 0.8rem;
    padding: 0.42rem 0.72rem;
    cursor: pointer;
}

.record-modal__reason {
    margin: 0 0 0.6rem;
    padding: 0.52rem 0.62rem;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.24);
    background: rgba(239, 68, 68, 0.08);
    color: #991b1b;
    font-size: 0.83rem;
    line-height: 1.35;
}

.record-modal__checks {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.record-check {
    border-radius: 10px;
    padding: 0.5rem 0.62rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(248, 250, 252, 0.94);
}

.record-check strong {
    display: block;
    font-size: 0.82rem;
    margin-bottom: 0.15rem;
}

.record-check p {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.32;
}

.record-check.is-danger {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.09);
    color: #991b1b;
}

.record-check.is-warning {
    border-color: rgba(245, 158, 11, 0.38);
    background: rgba(245, 158, 11, 0.1);
    color: #92400e;
}

.record-modal__section {
    margin-top: 0.72rem;
}

.record-modal__section h4 {
    margin: 0 0 0.45rem;
    font-size: 0.86rem;
    color: #111827;
}

.record-modal__grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 0.45rem;
}

.record-modal__table-wrap {
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    overflow: auto;
    background: rgba(255, 255, 255, 0.96);
}

.record-modal__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.record-modal__table th,
.record-modal__table td {
    text-align: left;
    padding: 0.45rem 0.55rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    white-space: nowrap;
}

.record-modal__table .item-code {
    display: inline-block;
    margin-left: 0.3rem;
    color: var(--muted);
    font-size: 0.68rem;
}

.record-modal__actions {
    margin: 0;
    padding-left: 1.05rem;
}

.record-modal__actions li {
    margin-bottom: 0.28rem;
    font-size: 0.8rem;
    line-height: 1.34;
}

.history-bill-link,
.bill-detail-back {
    color: #1d4ed8;
    font-weight: 700;
    text-decoration: none;
}

.history-bill-link:hover,
.bill-detail-back:hover {
    text-decoration: underline;
}

.bill-detail-page .panel {
    padding: 0.9rem;
}

.bill-detail-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.bill-detail-hero h2 {
    margin: 0.15rem 0;
}

.bill-detail-subtitle {
    margin: 0;
    color: var(--muted);
}

.auth-page {
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(135deg, #eff6ff 0%, #fff7ed 100%);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.auth-shell--wide {
    align-items: start;
}

.auth-card {
    width: min(460px, 100%);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 20px;
    padding: 1.2rem;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.12);
}

.auth-card--wide {
    width: min(920px, 100%);
}

.auth-card__intro h1 {
    margin: 0.2rem 0 0.35rem;
}

.auth-card__intro p:last-child {
    margin-top: 0;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 0.85rem;
}

.auth-form label,
.branch-switcher label,
.finance-switcher label {
    display: grid;
    gap: 0.3rem;
}

.auth-form span,
.branch-switcher span,
.finance-switcher span {
    font-size: 0.76rem;
    font-weight: 700;
    color: #334155;
}

.auth-form input,
.branch-switcher select,
.finance-switcher select {
    width: 100%;
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    padding: 0.7rem 0.8rem;
    font: inherit;
    background: #fff;
}

.company-grid {
    display: grid;
    gap: 0.9rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    margin: 1rem 0;
}

.company-card {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    padding: 1rem;
    background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(239,246,255,0.88) 100%);
}

.company-card h2 {
    margin: 0.15rem 0 0.35rem;
    font-size: 1rem;
}

.company-card p:last-child {
    margin: 0;
    color: var(--muted);
}

.top-context-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    margin-top: 0.55rem;
    flex-wrap: wrap;
}

.top-context-text {
    display: grid;
    gap: 0.15rem;
}

.top-context-text strong {
    font-size: 0.84rem;
}

.top-context-text span {
    color: var(--muted);
    font-size: 0.76rem;
}

.branch-switcher {
    min-width: 220px;
}

.finance-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    min-width: 340px;
}

.top-logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 0.95rem;
    border-radius: 12px;
    text-decoration: none;
    color: #fff;
    background: #0f172a;
    font-weight: 700;
}

.top-company-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 0.95rem;
    border-radius: 12px;
    text-decoration: none;
    color: #0f172a;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.32);
    font-weight: 700;
}

.table-guide-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 0.55rem;
}

.panel--quick-tools {
    padding: 0.6rem;
}

.quick-tools {
    display: grid;
    gap: 0.45rem;
    width: 100%;
}

.quick-tool__icon {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

.summary-card--compact {
    margin: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.summary-card--compact h2 {
    font-size: 1rem;
}

.quick-tools__nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
}

.quick-tool-tab {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #1f2937;
    font: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.46rem 0.56rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.32rem;
    cursor: pointer;
    min-width: 0;
}

.quick-tool-tab span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quick-tool-tab.is-active {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.30);
    color: #1d4ed8;
}

.quick-tools__content {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.55rem;
    min-height: 108px;
}

.quick-tool-panel {
    display: none;
}

.quick-tool-panel.is-active {
    display: block;
}

.quick-tool-panel .table-guide-grid,
.quick-tool-panel .report-chip-grid,
.quick-tool-panel .summary-kpi-grid,
.quick-tool-panel .summary-card--compact {
    padding: 0;
}

.table-guide-item {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.58rem 0.66rem;
    background: rgba(255, 255, 255, 0.86);
}

.table-guide-item strong {
    display: block;
    font-size: 0.82rem;
    margin-bottom: 0.2rem;
}

.table-guide-item p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.35;
}

@media (min-width: 700px) {
    .chart-grid--owner {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .summary-kpi-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .table-tools {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: end;
    }

    .table-guide-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .quick-tools {
        gap: 0.5rem;
    }

    .quick-tools__nav {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .record-modal__checks {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .record-modal__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .bill-detail-hero {
        align-items: center;
    }
}
