:root {
    --sidebar-width: 248px;
    --brand: #2563eb;
    --brand-dark: #1e40af;
    --brand-light: #60a5fa;
    --ink: #0f172a;
    --muted: #64748b;
    --bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);

    /* Bootstrap overrides — arccomp blue */
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
    --bs-link-color: #2563eb;
    --bs-link-hover-color: #1e40af;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

/* Sidebar — slate black */
.sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .6rem;
    font-size: 1.25rem; font-weight: 700; color: #fff;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand i { color: var(--brand-light); font-size: 1.5rem; }
.sidebar-nav { padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.sidebar .nav-link {
    display: flex; align-items: center; gap: .75rem;
    color: #cbd5e1; padding: .6rem .85rem; border-radius: .5rem;
    font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.sidebar .nav-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar .nav-link.active { background: var(--brand); color: #fff; }

/* Main column */
.main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: #0f172a; color: #e2e8f0;
    padding: .85rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    position: sticky; top: 0; z-index: 1030;
}
.page-title { font-size: 1.25rem; font-weight: 600; margin: 0; flex: 1; color: #fff; }
.topbar .btn-light {
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .15);
    color: #e2e8f0;
}
.topbar .btn-light:hover {
    background: rgba(255, 255, 255, .14);
    border-color: rgba(255, 255, 255, .25);
    color: #fff;
}
.content { padding: 1.5rem; }

/* Cards & tables */
.card { border: none; box-shadow: var(--card-shadow); border-radius: .75rem; overflow: hidden; }
.card-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
    border-bottom: none;
    font-weight: 600;
    color: #fff;
    padding: .85rem 1.25rem;
}
.card-header .btn-outline-primary,
.card-header .btn-outline-secondary {
    --bs-btn-color: #fff;
    --bs-btn-border-color: rgba(255, 255, 255, .55);
    --bs-btn-hover-bg: rgba(255, 255, 255, .12);
    --bs-btn-hover-border-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: rgba(255, 255, 255, .2);
    --bs-btn-active-border-color: #fff;
    --bs-btn-active-color: #fff;
}
.card-header .btn-primary {
    --bs-btn-bg: #fff;
    --bs-btn-border-color: #fff;
    --bs-btn-color: var(--brand-dark);
    --bs-btn-hover-bg: #f8fafc;
    --bs-btn-hover-border-color: #f8fafc;
    --bs-btn-hover-color: var(--brand-dark);
}
.table > :not(caption) > * > * { padding: .7rem .9rem; }
.table thead th {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
    color: #475569;
    border-bottom-width: 1px;
    background: #e2e8f0;
}
.table-hover > tbody > tr:hover > * { background-color: #f8fafc; }

.company-edit-link {
    color: var(--brand-dark, #1e3a8a);
    text-decoration: none;
    font-weight: 500;
}
.company-edit-link:hover {
    text-decoration: underline;
}

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 0.65rem; }
.stat-grid-balanced {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
@media (max-width: 1199.98px) {
    .stat-grid-balanced { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 575.98px) {
    .stat-grid-balanced { grid-template-columns: 1fr; }
}
.stat-grid-balanced-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 991.98px) {
    .stat-grid-balanced-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.stat-card { background: #fff; border-radius: .6rem; padding: 0.75rem 0.9rem; box-shadow: var(--card-shadow); }
.stat-card .stat-label { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; line-height: 1.25; }
.stat-card .stat-value { font-size: 1.25rem; font-weight: 700; margin-top: .15rem; color: var(--ink); line-height: 1.2; }
.stat-card .stat-value-text { font-size: 1rem; }
.stat-card .stat-icon { float: right; font-size: 1.15rem; color: var(--brand); opacity: .2; margin-top: .1rem; }
.stat-card .stat-note { font-size: .68rem; color: var(--muted); margin-top: .2rem; line-height: 1.2; }

.dashboard-panes > [class*="col-"] {
    display: flex;
    flex-direction: column;
}
.dashboard-pane-card {
    display: flex;
    flex-direction: column;
    min-height: 22rem;
}
.dashboard-pane-card > .card-header {
    flex-shrink: 0;
}
.dashboard-pane-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 22rem;
    overflow-y: auto;
}
.billing-summary-strip + .dashboard-pane-scroll {
    max-height: calc(22rem - 3.5rem);
}

.billing-summary-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border, #e2e8f0);
}
.billing-mini-stat {
    display: flex;
    flex-direction: column;
    min-width: 7rem;
}
.billing-mini-stat .billing-mini-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
}
.billing-mini-stat .billing-mini-value {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}
.billing-mini-stat .billing-mini-sub {
    font-size: .72rem;
    color: var(--muted);
}

.child-records-card {
    border-top: 3px solid var(--brand, #2563eb);
}
.child-records-card > .card-header {
    background: #f8fafc;
}

.dashboard-quick-import .card-header {
    background: #f8fafc;
}

.recurring-billing-table-compact .billing-client-cell,
.recurring-billing-table-compact td:not(.billing-actions-col):not(.billing-due-col):not(.billing-amount-col) {
    overflow: hidden;
    text-overflow: ellipsis;
}
.recurring-billing-table-compact .billing-service-line {
    font-size: 0.82rem;
    line-height: 1.25;
}
.recurring-billing-table-compact .billing-details-line {
    display: none;
}
.recurring-billing-table .billing-due-col {
    width: 5.75rem;
    white-space: nowrap;
}
.recurring-billing-table .billing-amount-col {
    width: 4.5rem;
    white-space: nowrap;
}
.recurring-billing-table .billing-actions-col {
    width: auto;
    min-width: 3.5rem;
    padding-left: 0.25rem;
    padding-right: 0.35rem;
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -4px 0 6px -4px rgba(15, 23, 42, 0.12);
}
.recurring-billing-table .table-hover > tbody > tr:hover > .billing-actions-col {
    background: #f8fafc;
}

.text-muted-2 { color: var(--muted); }
.table-actions { white-space: nowrap; }

/* Buttons — arccomp blue */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: #1d4ed8;
    --bs-btn-active-border-color: #1d4ed8;
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
}

/* Auth screen — blue gradient */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e3a8a, #2563eb); padding: 1rem;
}
.auth-card {
    width: 100%; max-width: 400px; background: #fff; border-radius: 1rem;
    box-shadow: 0 20px 45px rgba(0, 0, 0, .25); padding: 2.25rem;
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand i { font-size: 2.5rem; color: var(--brand); }

/* Sortable table headers */
.sort-link {
    display: inline-flex;
    align-items: center;
    color: inherit;
    text-decoration: none;
    font-weight: inherit;
    white-space: nowrap;
}
.sort-link:hover { color: var(--brand); }
.sort-icon-muted { opacity: .35; font-size: .85em; }
th .sort-link.justify-content-end { width: 100%; }
.table thead th .sort-link { color: #334155; }
.table thead th .sort-link:hover { color: var(--brand-dark); }

/* Pagination */
.page-link { color: var(--brand); }
.page-link:hover { color: var(--brand-dark); }
.active > .page-link { background-color: var(--brand); border-color: var(--brand); }

/* Contract Detail — compact toolbar + filters */
.filter-toolbar {
    background: #fff;
    border-radius: .75rem;
    box-shadow: var(--card-shadow);
    padding: .55rem .7rem;
    margin-bottom: .75rem;
}
.filter-toolbar-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .4rem .75rem;
    margin-bottom: .45rem;
    padding-bottom: .45rem;
    border-bottom: 1px solid #e2e8f0;
}
.filter-toolbar-top .toolbar-summary {
    font-size: .875rem;
    color: #64748b;
    min-width: 0;
}
.filter-toolbar-top .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
}
.filter-toolbar-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .5rem;
}
.filter-section {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: .3rem;
    flex: 0 1 auto;
    min-width: 0;
    padding-right: .5rem;
    margin-right: .15rem;
    border-right: 1px solid #e2e8f0;
}
.filter-section:last-child {
    border-right: none;
    padding-right: 0;
    margin-right: 0;
}
.filter-section-label {
    font-size: .68rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    line-height: 1;
}
.filter-section .form-control,
.filter-section .form-select {
    font-size: .8125rem;
    padding: .2rem .4rem;
    min-height: calc(1.5em + .4rem + 2px);
    min-width: 0;
}
.filter-section .filter-company-input { width: 9.5rem; }
.filter-section .filter-search-input { width: 8.5rem; }
.filter-section .filter-type-select { width: 7.5rem; }
.filter-section .filter-date-input { width: 6.85rem; }
.filter-section .filter-hours-input { width: 2.65rem; text-align: center; }
.filter-section .filter-hours-exact { width: 2.85rem; }
.filter-range-sep {
    color: #94a3b8;
    font-size: .75rem;
    line-height: 1;
    padding: 0 .05rem;
}
.filter-section-actions {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-left: auto;
}
.filter-section-actions .btn {
    font-size: .8125rem;
    padding: .2rem .5rem;
}

/* Legacy single-row filter bar (other pages) */
.filter-bar {
    background: #fff;
    border-radius: .75rem;
    box-shadow: var(--card-shadow);
    padding: .5rem .65rem;
}
.filter-grid {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: .4rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.filter-grid .input-group {
    flex: 0 0 auto;
    min-width: 0;
}
.filter-grid .input-group-text {
    font-size: .75rem;
    font-weight: 600;
    background: #f1f5f9;
    color: #475569;
    padding: .25rem .5rem;
    white-space: nowrap;
}
.filter-grid .form-control {
    font-size: .8125rem;
    padding: .25rem .45rem;
    min-height: calc(1.5em + .5rem + 2px);
}
.filter-grid .filter-company { width: 10.5rem; }
.filter-grid .filter-search { width: 12rem; }
.filter-grid .filter-contract { width: 9.5rem; }
.filter-grid .filter-dates .form-control { width: 7.1rem; }
.filter-grid .filter-hours .form-control { width: 3rem; text-align: center; }
.filter-grid .filter-hours .form-control-hours-exact { width: 3.25rem; }
.filter-grid .filter-actions {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex: 0 0 auto;
    margin-left: .15rem;
}
.filter-grid .btn { font-size: .8125rem; padding: .25rem .55rem; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
}
