:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #dbeafe;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --success: #15803d;
    --success-soft: #dcfce7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --btn-primary-bg: #dbeafe;
    --btn-primary-border: #93c5fd;
    --btn-primary-text: #1d4ed8;
    --btn-primary-hover-bg: #bfdbfe;
    --btn-success-bg: #dcfce7;
    --btn-success-border: #86efac;
    --btn-success-text: #15803d;
    --btn-success-hover-bg: #bbf7d0;
    --btn-danger-bg: #fee2e2;
    --btn-danger-border: #fca5a5;
    --btn-danger-text: #b91c1c;
    --btn-danger-hover-bg: #fecaca;
    --btn-warning-bg: #fef3c7;
    --btn-warning-border: #fcd34d;
    --btn-warning-text: #b45309;
    --btn-warning-hover-bg: #fde68a;
    --btn-secondary-bg: #f1f5f9;
    --btn-secondary-border: #cbd5e1;
    --btn-secondary-text: #475569;
    --btn-secondary-hover-bg: #e2e8f0;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    --radius: 6px;
    --sidebar-w-expanded: 200px;
    --sidebar-w-collapsed: 56px;
    --sidebar-w: var(--sidebar-w-expanded);
    --ui-scale: 0.9;
}

html {
    zoom: var(--ui-scale);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    font-size: 13px;
    min-height: calc(100vh / var(--ui-scale));
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* App shell + sidebar */
.app-shell {
    display: flex;
    min-height: calc(100vh / var(--ui-scale));
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 120;
    width: var(--sidebar-w);
    height: calc(100vh / var(--ui-scale));
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    transition: width .2s ease, transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .75rem .65rem;
    border-bottom: 1px solid var(--border);
    min-height: 46px;
    flex-shrink: 0;
}

.sidebar-brand-mark {
    font-weight: 800;
    font-size: .95rem;
    color: var(--primary);
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .15s ease;
}

.sidebar-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    margin-left: auto;
    flex-shrink: 0;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    transition: background .15s, color .15s;
}

.sidebar-collapse-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-collapse-icon {
    display: block;
    transition: transform .2s ease;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .5rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .45rem .65rem;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: .8rem;
    font-weight: 500;
    white-space: nowrap;
}

.sidebar-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
}

.sidebar-link-label {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity .15s ease;
}

.sidebar-link:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.app-content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    transition: margin-left .2s ease;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh / var(--ui-scale));
}

/* Desktop collapsed icon rail */
@media (min-width: 769px) {
    html.sidebar-collapsed {
        --sidebar-w: var(--sidebar-w-collapsed);
    }

    html.sidebar-collapsed .sidebar-brand {
        justify-content: center;
        padding: .5rem .35rem;
    }

    html.sidebar-collapsed .sidebar-brand-mark {
        display: none;
    }

    html.sidebar-collapsed .sidebar-brand-text,
    html.sidebar-collapsed .sidebar-link-label {
        opacity: 0;
        width: 0;
        overflow: hidden;
        pointer-events: none;
    }

    html.sidebar-collapsed .sidebar-collapse-btn {
        margin: 0 auto;
    }

    html.sidebar-collapsed .sidebar-collapse-icon {
        transform: rotate(180deg);
    }

    html.sidebar-collapsed .sidebar-nav {
        padding: .5rem .35rem;
    }

    html.sidebar-collapsed .sidebar-link {
        justify-content: center;
        padding: .5rem;
        gap: 0;
    }
}

.mobile-topbar {
    display: none;
    align-items: center;
    gap: .65rem;
    height: 46px;
    padding: 0 .75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 110;
}

.mobile-topbar-title {
    font-weight: 700;
    font-size: .88rem;
    color: var(--text);
}

.mobile-topbar-title span { color: var(--primary); }

.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 115;
}

body.sidebar-open .sidebar-backdrop { display: block; }
body.sidebar-open .sidebar { transform: translateX(0); }

/* Page layout — fluid */
.app-main {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: .65rem 1rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Table list pages: stretch panel to bottom of viewport */
.app-main > .ims-page-wrap:has(> .table-panel) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-panel.portal-main-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-panel .loading-target {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-panel.portal-main-panel .table-scroll {
    flex: 1;
    min-height: 0;
    max-height: none;
}

.alerts-fluid { margin-bottom: .5rem; }

.alert-list {
    margin: .5rem 0 0;
    padding-left: 1.25rem;
}

.ims-page-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.ims-page-body {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

/* Blue page toolbar (all pages) */
.page-toolbar,
.page-toolbar-form {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .65rem .85rem;
    background: #0b4f8a;
    border-radius: var(--radius);
    color: #fff;
}

.page-toolbar-title { display: flex; flex-direction: column; gap: .1rem; }

.page-toolbar-label {
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .01em;
}

.page-toolbar-sub {
    font-size: .72rem;
    opacity: .85;
}

.page-toolbar-actions {
    display: flex;
    align-items: flex-end;
    gap: .65rem;
    flex-wrap: wrap;
}

.page-toolbar .filter-status { color: rgba(255,255,255,.9); font-size: .72rem; }

.toolbar-filter label {
    display: block;
    font-size: .62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    opacity: .9;
    margin-bottom: .2rem;
}

.toolbar-filter select,
.toolbar-input {
    min-width: 160px;
    padding: .35rem .5rem;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 4px;
    background: rgba(255,255,255,.12);
    color: #fff;
    font-size: .78rem;
}

.toolbar-filter select option,
.toolbar-input option { color: var(--text); background: #fff; }

/* Filter bar below toolbar */
.page-filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem .75rem;
}

.page-filter-bar .filter-actions {
    margin-top: .45rem;
    padding-top: .45rem;
}

.page-filter-bar .filter-status { margin-left: auto; }

/* Compact single-line filter bar */
.page-filter-bar-compact {
    padding: .4rem .55rem;
}

.filter-row-compact {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
    min-height: 32px;
}

.filter-ctl {
    flex: 0 0 auto;
    height: 30px;
    padding: 0 .45rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: .78rem;
    background: var(--surface);
    color: var(--text);
    min-width: 0;
}

.filter-ctl:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

select.filter-ctl {
    max-width: 118px;
    padding-right: 1.4rem;
}

.filter-ctl-wide {
    max-width: 160px;
}

.filter-ctl-supplier {
    width: 118px;
    flex: 0 1 118px;
}

.filter-ctl-invoice {
    width: 175px;
    flex: 1 1 175px;
    max-width: 240px;
    resize: none;
    overflow: hidden;
    line-height: 1.25;
    padding-top: .35rem;
    padding-bottom: .35rem;
    min-height: 30px;
    max-height: 48px;
    font-family: inherit;
}

.filter-chips {
    display: flex;
    align-items: center;
    gap: .25rem;
    flex-shrink: 0;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .12rem .38rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface-2);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    line-height: 1.2;
}

.filter-chip:has(input:checked) {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(29, 78, 216, 0.08);
}

.filter-chip input {
    width: 12px;
    height: 12px;
    margin: 0;
    flex-shrink: 0;
}

.filter-clear-btn {
    flex-shrink: 0;
    padding: .18rem .42rem !important;
    font-size: .72rem !important;
    line-height: 1.2;
}

.page-filter-bar-compact .filter-status {
    flex-shrink: 0;
    font-size: .72rem;
    white-space: nowrap;
    margin-left: auto;
}

/* Compact inline form rows (export, import, etc.) */
.form-row-compact {
    margin-bottom: .35rem;
}

.filter-ctl-file {
    flex: 1 1 220px;
    max-width: 360px;
    min-width: 160px;
    height: auto;
    min-height: 30px;
    padding: .28rem .45rem;
    font-size: .74rem;
}

.form-hint-inline {
    margin: .25rem 0 0;
    font-size: .72rem;
    color: var(--text-muted);
}

.form-hint-top { margin-top: 0; margin-bottom: .65rem; }

.portal-panel-body {
    padding: .75rem;
}

.portal-panel-head-compact {
    padding: .45rem .75rem;
    align-items: center;
}

.portal-panel-foot-top {
    border-top: none;
    border-bottom: 1px solid var(--border);
}

.action-status-strip-5 {
    grid-template-columns: repeat(5, 1fr);
}

.page-header {
    margin-bottom: .5rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.page-header p {
    margin: .15rem 0 0;
    color: var(--text-muted);
    font-size: .78rem;
}

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: .5rem;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .4rem .65rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-size: .68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.panel-body { padding: .6rem .65rem; }

/* Alerts */
.alerts { margin-bottom: .5rem; }

.alert {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
    padding: .45rem .65rem;
    border-radius: 6px;
    margin-bottom: .35rem;
    font-size: .8rem;
    border: 1px solid transparent;
}

.alert-success { background: var(--success-soft); color: var(--success); border-color: #bbf7d0; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: #fde68a; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }

.alert-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    opacity: .6;
    padding: 0;
    color: inherit;
}

.alert-close:hover { opacity: 1; }

/* Filters */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .45rem;
    align-items: end;
}

.filter-field label {
    display: block;
    font-size: .65rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .15rem;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.filter-field input,
.filter-field select,
.filter-field textarea {
    width: 100%;
    padding: .35rem .5rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: .8rem;
    background: var(--surface);
    color: var(--text);
}

.filter-field-search {
    grid-column: span 2;
}

.search-multi-input {
    min-height: 2.4rem;
    resize: vertical;
    line-height: 1.35;
    font-family: inherit;
}

.filter-field input:focus,
.filter-field select:focus,
.filter-field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.filter-check {
    display: flex;
    align-items: center;
    gap: .35rem;
    min-height: 30px;
    font-size: .75rem;
    color: var(--text);
    cursor: pointer;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
    margin-top: .45rem;
    padding-top: .45rem;
    border-top: 1px solid var(--border);
}

.filter-status {
    font-size: .8rem;
    color: var(--text-muted);
    margin-left: auto;
}

.filter-status.loading { color: var(--primary); font-weight: 600; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    padding: .35rem .65rem;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: none;
    transition: background .15s, border-color .15s, color .15s;
}

a.btn:hover { text-decoration: none; }

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
    background: var(--btn-primary-bg);
    border-color: var(--btn-primary-border);
    color: var(--btn-primary-text);
}

.btn-primary:hover:not(:disabled) {
    background: var(--btn-primary-hover-bg);
    border-color: var(--btn-primary-border);
    color: var(--btn-primary-text);
}

.btn-success {
    background: var(--btn-success-bg);
    border-color: var(--btn-success-border);
    color: var(--btn-success-text);
}

.btn-success:hover:not(:disabled) {
    background: var(--btn-success-hover-bg);
    border-color: var(--btn-success-border);
    color: var(--btn-success-text);
}

.btn-danger {
    background: var(--btn-danger-bg);
    border-color: var(--btn-danger-border);
    color: var(--btn-danger-text);
}

.btn-danger:hover:not(:disabled) {
    background: var(--btn-danger-hover-bg);
    border-color: var(--btn-danger-border);
    color: var(--btn-danger-text);
}

.btn-warning {
    background: var(--btn-warning-bg);
    border-color: var(--btn-warning-border);
    color: var(--btn-warning-text);
}

.btn-warning:hover:not(:disabled) {
    background: var(--btn-warning-hover-bg);
    border-color: var(--btn-warning-border);
    color: var(--btn-warning-text);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    border-color: var(--btn-secondary-border);
    color: var(--btn-secondary-text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--btn-secondary-hover-bg);
    border-color: var(--btn-secondary-border);
    color: var(--btn-secondary-text);
}

.btn-outline {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text-muted);
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--btn-primary-border);
    color: var(--btn-primary-text);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.btn-sm { padding: .2rem .4rem; font-size: .68rem; border-radius: 4px; }

.btn-group { display: inline-flex; gap: .25rem; flex-wrap: wrap; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    padding: .4rem .65rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.toolbar-label {
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.toolbar-count {
    font-size: .72rem;
    color: var(--primary);
    font-weight: 600;
    background: var(--primary-soft);
    padding: .1rem .4rem;
    border-radius: 999px;
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: .4rem;
    margin-bottom: .5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .45rem .55rem;
    box-shadow: none;
}

.stat-card .label {
    font-size: .62rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    line-height: 1.2;
}

.stat-card .value {
    font-size: .95rem;
    font-weight: 700;
    margin-top: .15rem;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.stat-card.money .value { font-size: .85rem; color: var(--primary); }

/* Tables */
.table-panel { padding: 0; }

.table-scroll {
    width: 100%;
    overflow: auto;
    max-height: calc(100vh / var(--ui-scale) - 200px);
    min-height: 160px;
}

.table-scroll-short { max-height: 280px; }

.data-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .75rem;
    -webkit-overflow-scrolling: touch;
}

.data-table th,
.data-table td {
    padding: .3rem .45rem;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    background: var(--surface);
}

.data-table th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table tbody tr:hover td { background: #f8fafc; }

.data-table .sticky-col {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 34px;
    box-shadow: 2px 0 4px rgba(0,0,0,.04);
}

.data-table .sticky-col-2 {
    position: sticky;
    left: 34px;
    z-index: 3;
    min-width: 130px;
    box-shadow: 2px 0 4px rgba(0,0,0,.04);
}

.data-table thead .sticky-col,
.data-table thead .sticky-col-2 { z-index: 4; }

.data-table thead .sticky-col,
.data-table thead .sticky-col-2 { z-index: 4; }

/* Excel-like records table */
.excel-table-wrap { border: 1px solid #b4c6b7; }

.excel-table thead th {
    background: linear-gradient(180deg, #e2efda 0%, #d4e4cc 100%);
    border-bottom: 1px solid #a9c4a0;
    border-right: 1px solid #c5d9bc;
    color: #1e3a1e;
    padding: 0;
    vertical-align: bottom;
}

.excel-table thead th.th-static {
    padding: .35rem .45rem;
    font-size: .65rem;
    text-transform: uppercase;
}

.th-sort {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .25rem;
    width: 100%;
    min-height: 2rem;
    padding: .35rem .45rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    cursor: pointer;
    white-space: nowrap;
}

.th-sort.th-sort-num { justify-content: flex-end; }

.th-sort:hover { background: rgba(255, 255, 255, .35); }

.th-sort-label { overflow: hidden; text-overflow: ellipsis; }

.th-sort-icon::before {
    content: '⇅';
    opacity: .35;
    font-size: .7rem;
}

.th-sort.is-sorted-asc .th-sort-icon::before { content: '↑'; opacity: 1; color: var(--primary); }
.th-sort.is-sorted-desc .th-sort-icon::before { content: '↓'; opacity: 1; color: var(--primary); }

.excel-table tbody td {
    border-right: 1px solid var(--border);
}

tr.tax-rule-warning td { background: #fef9c3 !important; }
tr.tax-rule-warning:hover td { background: #fef08a !important; }

.tax-violation-cell { color: var(--danger); font-weight: 700; }

.report-input.input-warning {
    border-color: var(--danger);
    background: #fff1f2;
}

.compact-table { width: 100%; }
.compact-table th, .compact-table td { position: static; }

tr.ineligible-row td { background: #fff7ed !important; }
tr.ineligible-row:hover td { background: #ffedd5 !important; }

.col-num { text-align: right; white-space: nowrap; min-width: 78px; font-variant-numeric: tabular-nums; }
.col-nowrap { white-space: nowrap; }
.amount-negative { color: var(--danger); }
.col-input { min-width: 72px; }
.col-gstin { min-width: 130px; font-family: ui-monospace, monospace; font-size: .7rem; }
.col-supplier { min-width: 140px; }
.col-supplier small { font-size: .65rem; }
.col-invoice { min-width: 100px; }

.col-doc-type { min-width: 110px; white-space: nowrap; font-size: .72rem; }
.col-check { width: 34px; text-align: center; }
.actions-cell { min-width: 185px; white-space: nowrap; }
.empty-cell { text-align: center; color: var(--text-muted); padding: 1rem !important; }

.readonly-cell { background: #f8fafc !important; color: #475569; }

.report-input {
    width: 68px;
    padding: .2rem .3rem;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font-size: .7rem;
    text-align: right;
}

.report-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.12);
}

/* Badges */
.badge {
    display: inline-block;
    padding: .1rem .4rem;
    border-radius: 999px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .01em;
}

.badge-A { background: var(--success-soft); color: var(--success); }
.badge-R { background: var(--danger-soft); color: var(--danger); }
.badge-P { background: var(--warning-soft); color: var(--warning); }
.badge-N { background: #e2e8f0; color: #475569; }

/* Pagination */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: .4rem .65rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.pagination-meta {
    font-size: .72rem;
    color: var(--text-muted);
}

.page-nav { margin: 0; }

.page-list {
    display: flex;
    align-items: center;
    gap: .25rem;
    list-style: none;
    margin: 0;
    padding: 0;
    flex-wrap: wrap;
}

.page-item a,
.page-item span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.65rem;
    height: 1.65rem;
    padding: 0 .4rem;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font-size: .72rem;
    background: var(--surface);
    color: var(--text);
}

.page-item a:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.page-item.active span {
    background: var(--btn-primary-bg);
    border-color: var(--btn-primary-border);
    color: var(--btn-primary-text);
    font-weight: 700;
}

.page-item.disabled span {
    opacity: .45;
    cursor: not-allowed;
}

/* Loading — progress bar, page loader, skeletons */
.page-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 300;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s ease;
}

.page-progress.is-active { opacity: 1; }

.page-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    box-shadow: 0 0 8px rgba(29, 78, 216, 0.45);
    transition: width .25s ease;
}

.page-progress.is-indeterminate .page-progress-bar {
    width: 35%;
    animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

.page-loader {
    position: fixed;
    inset: 0;
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(241, 245, 249, 0.72);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s ease, visibility .15s ease;
}

.page-loader.is-active {
    opacity: 1;
    visibility: visible;
}

.page-loader-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .65rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    min-width: 180px;
}

.page-loader-spinner,
.btn-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.page-loader-text {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
}

body.page-loader-open { overflow: hidden; }

html.is-page-loading .app-main {
    opacity: .55;
    pointer-events: none;
}

html.is-page-loading .page-loader {
    opacity: 1;
    visibility: visible;
}

.loading-target {
    position: relative;
    min-height: 120px;
    transition: opacity .15s ease;
}

.loading-target.is-loading {
    opacity: .45;
    pointer-events: none;
}

.loading-skeleton-overlay {
    position: absolute;
    inset: 0;
    z-index: 12;
    padding: .5rem;
    background: linear-gradient(180deg, rgba(255,255,255,.15), rgba(255,255,255,.92) 18%, rgba(255,255,255,.96));
    overflow: hidden;
}

.skeleton-panel { display: flex; flex-direction: column; gap: .5rem; }

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: .4rem;
}

.skeleton-stat {
    padding: .45rem .55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.skeleton-block {
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.skeleton-rows,
.skeleton-panel-table { display: flex; flex-direction: column; gap: .35rem; }

.skeleton-row,
.skeleton-table-row {
    display: grid;
    gap: .35rem;
    padding: .35rem .45rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    animation: skeleton-fade-in .25s ease both;
}

.skeleton-table-row {
    grid-template-columns: 28px 1.2fr 1fr .7fr .7fr;
    align-items: center;
}

.skeleton-table-head { margin-bottom: .15rem; }

.skeleton-line {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, #e2e8f0 0%, #f8fafc 50%, #e2e8f0 100%);
    background-size: 200% 100%;
    animation: shimmer 1.1s ease-in-out infinite;
}

.skeleton-line-xs { width: 18px; height: 12px; }
.skeleton-line-sm { width: 55%; margin-bottom: .25rem; }
.skeleton-line-md { width: 72%; }
.skeleton-line-lg { width: 45%; height: 14px; }
.skeleton-line-short { width: 38%; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes skeleton-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.filter-status.loading {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.filter-status.loading::before {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.btn.is-loading,
.btn:disabled .btn-spinner { display: inline-block; }

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

/* Forms */
.form-stack { max-width: 520px; }

.form-group { margin-bottom: .65rem; }

.form-group label {
    display: block;
    margin-bottom: .25rem;
    font-weight: 600;
    font-size: .8rem;
}

.form-group input[type=file],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .35rem .5rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: .8rem;
}

.form-hint {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

.field-error { color: var(--danger); font-size: .72rem; margin-top: .2rem; }

.inline-form { display: inline; }
.hidden-form { display: none; }

/* Import / Sync tabs */
.import-tabs {
    display: flex;
    gap: .35rem;
    margin-bottom: .65rem;
}

.import-tab {
    padding: .45rem .85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}

.import-tab.is-active {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-color: var(--btn-primary-border);
    border-bottom-color: var(--surface);
    margin-bottom: -1px;
}

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

.badge-sync-completed,
.badge-sync-imported { background: var(--success-soft); color: var(--success); }
.badge-sync-awaiting_import,
.badge-sync-partial,
.badge-sync-pending { background: var(--warning-soft); color: var(--warning); }
.badge-sync-failed { background: var(--danger-soft); color: var(--danger); }
.badge-sync-running { background: var(--primary-soft); color: var(--primary); }
.badge-sync-skipped { background: var(--surface-2); color: var(--text-muted); }

.sync-detail-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.sync-detail-modal.hidden-form { display: none; }

.sync-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.sync-detail-card {
    position: relative;
    z-index: 1;
    width: min(900px, 100%);
    max-height: 85vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.15);
}

.sync-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem .85rem;
    border-bottom: 1px solid var(--border);
    background: #e8f0f8;
}

.sync-detail-body { padding: .75rem .85rem; }

.sync-run-meta {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .35rem .75rem;
    font-size: .78rem;
}

.sync-run-error { color: var(--danger); grid-column: 1 / -1; }

/* GST sync live progress modal */
.sync-progress-modal {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.sync-progress-modal.hidden-form { display: none; }

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

.sync-progress-card {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.sync-progress-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #e8f0f8;
}

.sync-progress-head-text { flex: 1; min-width: 0; }

.sync-progress-minimize {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sync-progress-minimize:hover {
    background: var(--surface-2);
    color: var(--primary);
}

.sync-progress-head h2 {
    margin: 0;
    font-size: .95rem;
    color: #0b4f8a;
}

.sync-progress-head p {
    margin: .25rem 0 0;
    font-size: .75rem;
    color: var(--text-muted);
}

.sync-progress-body { padding: .85rem 1rem; }

.sync-progress-phase {
    font-size: .8rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: .65rem;
}

.sync-progress-bar-wrap { margin-bottom: .65rem; }

.sync-progress-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

.sync-progress-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.sync-progress-bar.is-sleep .sync-progress-bar-fill {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.sync-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    transition: width .4s ease;
}

.sync-progress-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .4rem;
    margin: .65rem 0;
}

.sync-progress-stats > div {
    text-align: center;
    padding: .4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
}

.sync-stat-val {
    display: block;
    font-size: 1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.sync-stat-lbl {
    display: block;
    font-size: .62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.sync-progress-log {
    max-height: 120px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f8fafc;
    padding: .45rem .55rem;
    font-size: .7rem;
    font-family: ui-monospace, monospace;
    margin-bottom: .5rem;
}

.sync-console-wrap { margin-top: .25rem; }

.sync-console-label {
    font-size: .68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .25rem;
}

.sync-console-log {
    max-height: 200px;
    overflow: auto;
    border: 1px solid #334155;
    border-radius: 4px;
    background: #0f172a;
    color: #e2e8f0;
    padding: .5rem .55rem;
    font-size: .68rem;
    font-family: ui-monospace, monospace;
    line-height: 1.45;
}

.sync-console-log .sync-log-line { color: #e2e8f0; border-bottom-color: #1e293b; }
.sync-log-muted { color: #94a3b8 !important; font-style: italic; }

.sync-log-line {
    padding: .12rem 0;
    color: #334155;
    border-bottom: 1px solid #e2e8f0;
}

.sync-log-line:last-child { border-bottom: none; }

.sync-progress-foot {
    padding: .65rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

/* Minimized floating dock — browse portal while sync runs */
.sync-progress-dock {
    position: fixed;
    bottom: max(1rem, env(safe-area-inset-bottom));
    right: max(1rem, env(safe-area-inset-right));
    z-index: 270;
}

.sync-progress-dock.hidden-form { display: none; }

.sync-dock-main {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .85rem;
    border: 1px solid #93c5fd;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    max-width: min(360px, calc(100vw - 2rem));
    text-align: left;
}

.sync-dock-main:hover {
    border-color: var(--primary);
    box-shadow: 0 10px 28px rgba(29, 78, 216, 0.2);
}

.sync-progress-dock.is-complete .sync-dock-main {
    border-color: #86efac;
}

.sync-progress-dock.is-failed .sync-dock-main {
    border-color: #fca5a5;
}

.sync-dock-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
    animation: sync-pulse 1.4s ease-in-out infinite;
}

.sync-progress-dock.is-complete .sync-dock-pulse,
.sync-progress-dock.is-failed .sync-dock-pulse {
    animation: none;
    background: var(--success);
}

.sync-progress-dock.is-failed .sync-dock-pulse {
    background: var(--danger);
}

@keyframes sync-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .45; transform: scale(.85); }
}

.sync-dock-text {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    min-width: 0;
}

.sync-dock-text strong {
    font-size: .72rem;
    color: #0b4f8a;
    text-transform: uppercase;
    letter-spacing: .03em;
}

#sync-dock-status {
    font-size: .75rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.check-label { display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* Chart */
.chart-bar {
    display: flex;
    height: 14px;
    border-radius: 4px;
    overflow: hidden;
    margin: .35rem 0 .45rem;
    border: 1px solid var(--border);
}

.chart-segment {
    display: block;
    min-width: 2px;
    height: 100%;
    transition: opacity .15s ease;
}

.chart-segment:hover { opacity: .85; }

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: .35rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .55rem;
    font-size: .75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chart-legend-item:last-child { border-bottom: none; }

.chart-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.chart-legend-label {
    color: var(--text);
    font-weight: 500;
}

.chart-legend-meta {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.chart-legend-value {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 3.5rem;
    text-align: right;
}

.chart-legend-pct {
    color: var(--text-muted);
    font-size: .7rem;
    font-variant-numeric: tabular-nums;
    min-width: 2.75rem;
    text-align: right;
}

.panel-header-hint {
    font-size: .65rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.portal-summary-table .table-drill-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.portal-summary-table .table-drill-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.portal-summary-row:hover td { background: #f8fafc; }

.portal-summary-total td {
    background: var(--surface-2) !important;
    border-top: 2px solid var(--border-strong);
}

.col-action {
    width: 72px;
    text-align: right;
    white-space: nowrap;
}

/* ── IMS portal page components ── */

/* Portal tiles */
.portal-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
}

.portal-tile {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.portal-tile:hover { text-decoration: none; color: inherit; }

.portal-tile-active:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-soft);
}

.portal-tile-muted { opacity: .72; }

.portal-tile-banner {
    padding: .45rem .75rem;
    background: #0b4f8a;
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.portal-tile-muted .portal-tile-banner { background: #64748b; }

.portal-tile-content {
    padding: .75rem;
    min-height: 130px;
    display: flex;
    flex-direction: column;
}

.portal-tile-desc {
    margin: 0 0 .5rem;
    font-size: .72rem;
    color: var(--text-muted);
    line-height: 1.35;
    flex: 1;
}

.portal-tile-metric {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
}

.portal-tile-metric-muted { color: var(--text-muted); font-size: 1.2rem; }

.portal-tile-metric-label {
    font-size: .68rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
}

.portal-tile-cta {
    display: inline-block;
    align-self: flex-start;
    padding: .3rem 1.1rem;
    background: var(--btn-primary-bg);
    border: 1px solid var(--btn-primary-border);
    color: var(--btn-primary-text);
    font-size: .72rem;
    font-weight: 700;
    border-radius: 4px;
    letter-spacing: .05em;
}

.portal-tile-cta-muted {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Action status strip */
.action-status-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .45rem;
}

.action-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: .5rem .4rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    text-decoration: none;
    transition: border-color .15s, background .15s;
}

.action-chip:hover { text-decoration: none; }

.action-chip-count {
    font-size: 1.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.action-chip-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
}

.action-chip.is-accepted { border-color: #86efac; }
.action-chip.is-accepted .action-chip-count { color: var(--success); }
.action-chip.is-accepted:hover { background: var(--success-soft); }

.action-chip.is-rejected { border-color: #fca5a5; }
.action-chip.is-rejected .action-chip-count { color: var(--danger); }
.action-chip.is-rejected:hover { background: var(--danger-soft); }

.action-chip.is-pending { border-color: #93c5fd; }
.action-chip.is-pending .action-chip-count { color: #2563eb; }
.action-chip.is-pending:hover { background: #dbeafe; }

.action-chip.is-unreviewed { border-color: var(--border-strong); }
.action-chip.is-unreviewed .action-chip-count { color: #475569; }
.action-chip.is-unreviewed:hover { background: var(--surface-2); }

/* Main portal panel */
.portal-main-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.portal-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    padding: .55rem .75rem;
    background: #e8f0f8;
    border-bottom: 1px solid #c5d9ed;
}

.portal-panel-title {
    margin: 0;
    font-size: .85rem;
    font-weight: 700;
    color: #0b4f8a;
}

.portal-panel-sub {
    margin: .15rem 0 0;
    font-size: .68rem;
    color: var(--text-muted);
}

.portal-table-wrap { max-height: none; }

.portal-panel-foot {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    padding: .5rem .75rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

/* Analytics section */
.dashboard-analytics {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .65rem .75rem;
}

.dashboard-analytics-head { margin-bottom: .5rem; }

.analytics-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .45rem;
    margin-bottom: .65rem;
}

.analytics-kpi {
    padding: .45rem .55rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
}

.analytics-kpi-label {
    display: block;
    font-size: .62rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.analytics-kpi-value {
    display: block;
    font-size: .95rem;
    font-weight: 700;
    margin-top: .15rem;
    font-variant-numeric: tabular-nums;
}

.portal-sub-panel {
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.portal-sub-panel-head {
    padding: .4rem .55rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: .72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.analytics-grid { gap: .65rem; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
}

.section-title {
    margin: 0 0 .4rem;
    font-size: .85rem;
    font-weight: 700;
}

@media (max-width: 768px) {
    html.sidebar-collapsed {
        --sidebar-w: var(--sidebar-w-expanded);
    }

    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-w-expanded);
    }

    .app-content { margin-left: 0; }

    .mobile-topbar {
        display: flex;
        padding-left: max(.75rem, env(safe-area-inset-left));
        padding-right: max(.75rem, env(safe-area-inset-right));
    }

    .sidebar-collapse-btn { display: none; }

    .app-main {
        padding: .55rem max(.65rem, env(safe-area-inset-left)) .65rem max(.65rem, env(safe-area-inset-right));
    }

    .filter-grid { grid-template-columns: 1fr 1fr; }
    .filter-row-compact {
        flex-wrap: wrap;
        row-gap: .4rem;
    }
    .page-filter-bar-compact .filter-status {
        width: 100%;
        margin-left: 0;
        text-align: right;
    }
    .grid-2 { grid-template-columns: 1fr; }
    .analytics-kpi-row { grid-template-columns: 1fr 1fr; }
    .action-status-strip { grid-template-columns: 1fr 1fr; }
    .action-status-strip-5 { grid-template-columns: 1fr 1fr; }
    .portal-tiles { grid-template-columns: 1fr; }
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .page-toolbar-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .page-toolbar-actions .toolbar-filter select,
    .page-toolbar-actions .toolbar-input {
        width: 100%;
        min-width: 0;
    }
    .portal-panel-head {
        flex-wrap: wrap;
    }
    .portal-panel-head .btn-group {
        width: 100%;
        justify-content: flex-start;
    }
    .table-panel.portal-main-panel .table-scroll {
        max-height: none;
    }
    .table-scroll {
        max-height: calc(100vh / var(--ui-scale) - 180px);
    }
    .pagination-bar { flex-direction: column; align-items: stretch; }
    .page-list { justify-content: center; }
    .filter-status { margin-left: 0; }
}

.sync-review-panel { margin-top: .75rem; }

.portal-panel-body-top-border {
    border-top: 1px solid var(--border);
}

.upload-action-row {
    margin-top: .65rem;
}

.upload-summary-table-wrap {
    max-height: 220px;
    margin-bottom: .35rem;
}

.upload-progress-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
}

.upload-progress-meta {
    font-size: .85rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

.upload-status-log {
    max-height: 120px;
    overflow: auto;
    margin: .45rem 0;
    font-size: .72rem;
    color: var(--text-muted);
}

.upload-verdict {
    display: inline-block;
    padding: .1rem .35rem;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 600;
    text-transform: capitalize;
}

.upload-verdict-success { background: var(--success-soft); color: var(--success); }
.upload-verdict-failed { background: var(--danger-soft); color: var(--danger); }
.upload-verdict-pending { background: var(--warning-soft); color: var(--warning); }
.upload-verdict-unknown { background: var(--surface-2); color: var(--text-muted); }

.sync-review-toolbar {
    margin-bottom: .65rem;
}

.sync-review-toolbar.filter-row-compact {
    flex-wrap: wrap;
}

.sync-review-table-wrap { max-height: 360px; }

.sync-review-table .col-check {
    width: 2rem;
    text-align: center;
}

.sync-review-table td:nth-child(2) {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .filter-grid { grid-template-columns: 1fr; }
    .analytics-kpi-row { grid-template-columns: 1fr; }
    .action-status-strip,
    .action-status-strip-5 { grid-template-columns: 1fr; }
    .portal-panel-foot { flex-direction: column; align-items: stretch; }
    .portal-panel-foot .btn { width: 100%; }
    .btn-group { width: 100%; }
    .btn-group .btn { flex: 1; }
}

/* Login page */
.login-page {
    min-height: calc(100vh / var(--ui-scale));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-shell {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
}

.login-brand h1 {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 600;
}

.login-brand p {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.login-alert {
    margin-bottom: 16px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-field span {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.login-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
}

.login-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.login-remember {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.login-submit {
    width: 100%;
    margin-top: 4px;
    padding: 10px 16px;
}

/* Sidebar footer / logout */
.sidebar {
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px 0;
}

.sidebar-logout-form {
    margin: 0;
}

.sidebar-logout-btn {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.sidebar-logout-btn:hover {
    background: var(--surface-2);
}
