:root {
    --sidebar-width: 220px;
    --primary-color: #1e3a5f;
    --primary-hover: #2d4a6f;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e5e7eb;
    --nav-text: #4b5563;
    --nav-text-hover: #1f2937;
    --nav-active-bg: #edf2f7;
    --nav-active-text: #1e3a5f;
    --submenu-bg: #f8fafc;
    --submenu-border: #e2e8f0;

    /* design tokens */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --shadow-card: 0 2px 12px rgba(30, 58, 95, 0.06);
    --shadow-card-hover: 0 8px 28px rgba(30, 58, 95, 0.1);
    --color-bg: #f5f6fa;
    --color-muted: #6b7280;

    /* Bootstrap 5 primary override */
    --bs-primary: #1e3a5f;
    --bs-primary-rgb: 30, 58, 95;
    --bs-link-color: #1e3a5f;
    --bs-link-hover-color: #2d4a6f;
    --bs-focus-ring-color: rgba(30, 58, 95, 0.25);
}

html { scroll-behavior: smooth; }

body {
    font-size: 14px;
    font-family: system-ui, -apple-system, "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 全局细滚动条（.nav-menu 有专属 4px 规则，优先级更高） */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }

.price-masked { filter: blur(6px); user-select: none; pointer-events: none; }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 24px rgba(0,0,0,0.04);
}

.main-content {
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    height: 50px;
    overflow: hidden;
}
.sidebar-brand { display: flex; align-items: center; overflow: hidden; white-space: nowrap; }
.sidebar-brand img { height: 28px; width: auto; display: block; flex-shrink: 0; }

.nav-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.375rem;
    min-height: 0;
}
.nav-menu::-webkit-scrollbar { width: 4px; }
.nav-menu::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 2px; }
.nav-menu::-webkit-scrollbar-track { background: transparent; }

.nav-menu .nav-link {
    color: var(--nav-text);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 9px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    position: relative;
    transition: all 0.2s ease;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
}
.nav-menu .nav-link:hover {
    background: #f3f4f6;
    color: var(--nav-text-hover);
}
.nav-menu .nav-link.active {
    background: var(--nav-active-bg);
    color: var(--nav-active-text);
    font-weight: 600;
}
.nav-menu .nav-link i.nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.nav-menu .nav-link .nav-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--primary-color);
    border-radius: 0 3px 3px 0;
    transition: height 0.25s ease;
}
.nav-menu .nav-link.active .nav-indicator,
.nav-menu .nav-link:hover .nav-indicator { height: 50%; }

.nav-menu .nav-link .chevron {
    font-size: 10px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: auto;
    flex-shrink: 0;
    color: #9ca3af;
}
.nav-menu .nav-link .chevron.expanded { transform: rotate(90deg); }

.nav-submenu {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
    opacity: 0;
}
.nav-submenu.expanded {
    grid-template-rows: 1fr;
    opacity: 1;
}
.nav-initializing .nav-submenu,
.nav-initializing .nav-link,
.nav-initializing .nav-indicator,
.nav-initializing .chevron,
.nav-initializing .sidebar,
.nav-initializing .main-content { transition: none !important; }
.nav-submenu-inner { overflow: hidden; }

.nav-menu .submenu {
    padding: 3px 0;
    background: var(--submenu-bg);
    border-radius: 8px;
    margin: 2px 0 4px 9px;
    position: relative;
}
.nav-menu .submenu::before {
    content: '';
    position: absolute;
    left: 18px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--submenu-border);
    border-radius: 1px;
}

.nav-menu .submenu .nav-link {
    color: #6b7280;
    padding: 6px 10px 6px 29px;
    font-size: 12px;
    font-weight: 400;
    gap: 10px;
    border-radius: var(--radius-sm);
    margin: 1px 4px;
    position: relative;
}
.nav-menu .submenu .nav-link:hover {
    color: var(--nav-active-text);
    background: #f1f5f9;
}
.nav-menu .submenu .nav-link.active {
    color: var(--nav-active-text);
    font-weight: 500;
    background: #e2e8f0;
}
.nav-menu .submenu .nav-link i {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
    color: #9ca3af;
    flex-shrink: 0;
}
.nav-menu .submenu .nav-link.active i { color: var(--nav-active-text); }

.nav-menu .submenu .nav-link::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d1d5db;
    transition: all 0.2s;
}
.nav-menu .submenu .nav-link:hover::before,
.nav-menu .submenu .nav-link.active::before {
    background: var(--primary-color);
    width: 8px;
    height: 8px;
    left: 13px;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--primary-color);
    background: #f1f5f9;
    border: none;
    cursor: pointer;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* Topbar */
.topbar {
    background: #fff;
    border-bottom: none;
    box-shadow: 0 1px 8px rgba(30, 58, 95, 0.07);
    position: relative;
    z-index: 10;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 50px;
    gap: 1rem;
}
.topbar-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    min-width: 0;
}
.topbar-title i {
    color: var(--primary-color);
    font-size: 1rem;
    flex-shrink: 0;
}
.topbar-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* SPA progress bar */
.spa-progress {
    position: fixed;
    top: 50px;
    left: var(--sidebar-width);
    right: 0;
    height: 2px;
    background: transparent;
    z-index: 999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.spa-progress.active { opacity: 1; }
.spa-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #1e3a5f, #4a6b8f);
    box-shadow: 0 0 10px rgba(30, 58, 95, 0.4);
    transition: width 0.3s ease;
}

.page-content {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ===== Cards (global unify) ===== */
.card {
    border: 1px solid #edf1f4;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    background: #fff;
}
.card > .card-header:first-child { border-radius: var(--radius-md) var(--radius-md) 0 0; }
.card > .list-group:last-child,
.card > .table-responsive:last-child,
.card > .card-body:last-child { border-radius: 0 0 var(--radius-md) var(--radius-md); }
.card-header {
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    padding: 0.875rem 1.25rem;
    font-weight: 600;
    color: #334155;
}
.card-body { padding: 1.25rem; }
.card:hover { z-index: 1; }

/* ===== Buttons & primary override ===== */
.btn-primary {
    --bs-btn-bg: var(--primary-color);
    --bs-btn-border-color: var(--primary-color);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-bg: #253c5a;
    --bs-btn-active-border-color: #253c5a;
    --bs-btn-focus-shadow-rgb: 30, 58, 95;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.btn-primary:hover:not(:disabled):not(.disabled) {
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.22);
}
.btn-outline-primary {
    --bs-btn-color: var(--primary-color);
    --bs-btn-border-color: var(--primary-color);
    --bs-btn-hover-bg: var(--primary-color);
    --bs-btn-hover-border-color: var(--primary-color);
    --bs-btn-active-bg: var(--primary-color);
    --bs-btn-active-border-color: var(--primary-color);
}
.btn-primary-custom {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}
.btn-primary-custom:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}
.btn-outline-purple { border-color: #8e7b9b; color: #8e7b9b; }
.btn-outline-purple:hover { background-color: #8e7b9b; color: #fff; }

/* Focus-visible ring */
*:focus-visible {
    outline: 2px solid rgba(30, 58, 95, 0.25);
    outline-offset: 2px;
}
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid rgba(30, 58, 95, 0.25);
    outline-offset: 2px;
}
.form-check-input:focus-visible,
.page-link:focus-visible { outline-offset: 1px; }

/* ===== Forms ===== */
.form-label { font-weight: 500; font-size: 13px; color: #5a5c69; }
.form-control, .form-select { font-size: 14px; }
.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.18rem rgba(30, 58, 95, 0.15);
}
.form-check-input:checked { background-color: var(--primary-color); border-color: var(--primary-color); }
.form-check-input:focus { box-shadow: 0 0 0 0.18rem rgba(30, 58, 95, 0.15); }

.text-primary-custom { color: var(--primary-color) !important; }

/* ===== Badges (Morandi) ===== */
.badge { font-weight: 500; font-size: 11px; padding: 4px 8px; border-radius: 4px; }
.badge.bg-primary { background-color: #7c8a97 !important; }
.badge.bg-success { background-color: #8a9e7f !important; }
.badge.bg-danger { background-color: #b07a6b !important; }
.badge.bg-warning { background-color: #c9a87c !important; color: #fff !important; }
.badge.bg-info { background-color: #8899a6 !important; }
.badge.bg-secondary { background-color: #9a9ea3 !important; }
.badge.bg-dark { background-color: #5d6065 !important; }
.badge.bg-light { background-color: #eeedeb !important; color: #495057 !important; }
.badge.bg-morandi-purple { background-color: #8e7b9b !important; }
.badge.bg-morandi-teal { background-color: #7b9e9b !important; }

.badge.bg-primary-subtle { background-color: #eef1f4 !important; color: #5c6b7a !important; border: 1px solid #e2e8f0; }
.badge.bg-success-subtle { background-color: #eef3ec !important; color: #5e6f56 !important; border: 1px solid #e2e8e0; }
.badge.bg-warning-subtle { background-color: #f5f1ea !important; color: #7a6b55 !important; border: 1px solid #ebe5da; }
.badge.bg-info-subtle { background-color: #edf1f4 !important; color: #5a6d7c !important; border: 1px solid #e1e8ed; }
.badge.bg-danger-subtle { background-color: #f8edeb !important; color: #8a5a52 !important; border: 1px solid #f1ddd9; }
.badge.bg-secondary-subtle { background-color: #f1f2f3 !important; color: #5d6065 !important; border: 1px solid #e8e9ea; }

/* ===== Page title component ===== */
.page-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #334155;
    white-space: nowrap;
    margin: 0;
}
.page-title-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #edf2f7;
    color: var(--primary-color);
    font-size: 15px;
}
.page-title-text {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* ===== Stat cards ===== */
.stat-card { border: none; border-radius: var(--radius-md); box-shadow: var(--shadow-card); transition: transform .2s, box-shadow .2s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card-hover); }
.stat-card .card-body { padding: 1.25rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.badge-counter { position: absolute; top: 4px; right: 4px; font-size: 10px; padding: 2px 5px; }

/* ===== Tables ===== */
.table-card { background: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-card); }
.table-card .card-header { background: #fff; border-bottom: 1px solid #f0f0f0; padding: 1rem 1.25rem; }

/* ===== Data tables（详情页/表单页明细表，与 cost-table 同一设计语言） ===== */
.table.data-table { table-layout: fixed; width: 100%; margin-bottom: 0; font-size: 12px; }
.table.data-table > thead > tr > th {
    background-color: #f8f9fc;
    font-weight: 600;
    font-size: 12px;
    color: #5a5c69;
    border-bottom: 2px solid #dde5ee;
    padding: 7px 8px;
    vertical-align: middle;
}
.table.data-table > tbody > tr > td {
    padding: 6px 8px;
    vertical-align: middle;
    border-color: #edf1f4;
    color: #3c4b5d;
}
.table.data-table > tfoot > tr > td {
    font-weight: 600;
    border-top: 2px solid #dfe5ec;
    border-bottom: none;
    padding: 6px 8px;
}
/* tfoot 默认灰底；带 table-warning 等语义色的行保留原色 */
.table.data-table > tfoot > tr:not([class*="table-"]) > td { background: #f4f6f9; }
/* 数字/金额列：居中 + 等宽数字，保证纵向整齐 */
.table.data-table td.text-center,
.table.data-table td.text-end { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* 编辑态（单元格内含输入框） */
.table.data-table.data-table-edit > tbody > tr > td { padding: 3px 4px; }
.table.data-table.data-table-edit .form-control { font-size: 12px; }
.table.data-table.data-table-edit input[type="number"] { text-align: center; font-variant-numeric: tabular-nums; }

.list-page { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.list-header { flex-shrink: 0; }
.list-filter { flex-shrink: 0; padding: 10px; border-radius: 8px; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .04); }
.list-body { flex: 1; min-height: 0; overflow-y: auto; }
.list-body > .card > .table-responsive > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8f9fc !important;
    font-weight: 600;
    font-size: 13px;
    color: #5a5c69;
}
.list-body-scroll { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.list-body-scroll > .card { flex: 0 1 auto; max-height: 100%; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.list-body-scroll > .card > .table-responsive { flex: 1; overflow-y: auto; min-height: 0; }
.list-body-scroll > .card > .table-responsive > table { margin-bottom: 0; }
.list-body-scroll > .card > .table-responsive > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8f9fc !important;
    font-weight: 600;
    font-size: 13px;
    color: #5a5c69;
}

/* tabular nums for monetary / numeric columns */
.tabular-nums { font-variant-numeric: tabular-nums; }
.cost-value,
.amount-value,
.money-value { font-variant-numeric: tabular-nums; }

/* ===== Pagination ===== */
.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 16px;
    padding: 5px 14px;
    border-top: 1px solid #edf1f4;
    flex-shrink: 0;
}
.pagination-bar .pagination-info { color: #94a1ae; font-size: 12px; white-space: nowrap; }
.pagination-bar .pagination { margin: 0; gap: 4px; }
.pagination-bar .page-item:not(:first-child) .page-link { margin-left: 0; }
.pagination-bar .page-item .page-link {
    padding: 2px 10px;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    background: #fff;
    color: #5c6b7a;
    font-size: 12px;
    line-height: 1.6;
}
.pagination-bar .page-item .page-link:hover {
    color: var(--primary-color);
    background: #eef2f7;
    border-color: #d7e0ea;
}
.pagination-bar .page-item.active .page-link {
    color: #fff;
    background: var(--primary-color);
    border-color: var(--primary-color);
}
.pagination-bar .page-item.disabled .page-link { color: #b8c0c9; background: #f7f9fb; border-color: #edf1f5; }

/* ===== List summary bar (cost / settlement plan) ===== */
.list-footer-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 5px 12px;
    padding: 6px 14px;
    background: #fbfcfe;
    border-top: 1px solid #edf1f4;
    color: #94a1ae;
    font-size: 12px;
    flex-shrink: 0;
    overflow-x: auto;
}
.list-footer-row .pagination-bar {
    display: contents;
}
.list-footer-row .pagination-info { order: 1; }
.list-footer-row .pagination-bar nav { order: 3; margin-left: auto; }
.list-footer-row .pagination-bar .pagination { gap: 2px; }
.list-footer-row .pagination-bar .page-item .page-link { padding: 1px 7px; }
.list-summary-bar {
    display: contents;
}
.list-summary-bar > * { order: 2; }
.lsb-title {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #94a1ae;
    font-weight: 400;
    white-space: nowrap;
}
.lsb-title i { color: #94a1ae; }
.lsb-title em { color: #94a1ae; font-style: normal; font-weight: 400; }
.lsb-item {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    white-space: nowrap;
}
.lsb-item label {
    margin: 0;
    color: #94a1ae;
    font-size: 12px;
    font-weight: 400;
}
.lsb-item b {
    color: #94a1ae;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.lsb-item i {
    color: #94a1ae;
    font-style: normal;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.lsb-item .is-positive,
.lsb-item .is-negative { color: #94a1ae; }
.lsb-divider { width: 1px; height: 14px; background: #e2e8f0; }
.lsb-alerts {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.lsb-warn,
.lsb-note {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #94a1ae;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
}
@media (max-width: 1500px) {
    .list-footer-row { gap: 4px 8px; }
    .list-footer-row .pagination-bar .page-item .page-link { padding-inline: 6px; }
}
@media (max-width: 768px) {
    .list-footer-row { gap: 5px 10px; padding: 6px 12px; }
}

/* ===== Login ===== */
.login-bg { background: linear-gradient(135deg, #16304f 0%, #2d5a8a 100%); min-height: 100vh; }
.login-card { border: none; border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,0.15); }

/* ===== Timeline (Morandi) ===== */
.approval-timeline { position: relative; padding-left: 30px; }
.approval-timeline::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: #e3e6f0; }
.approval-timeline-item { position: relative; margin-bottom: 1.5rem; }
.approval-timeline-item::before { content: ''; position: absolute; left: -24px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #d1d3e2; }
.approval-timeline-item.approved::before { background: #8a9e7f; border-color: #8a9e7f; }
.approval-timeline-item.rejected::before { background: #b07a6b; border-color: #b07a6b; }
.approval-timeline-item.withdrawn::before { background: #c9a87c; border-color: #c9a87c; }
.approval-timeline-item.processing::before { background: #7c8a97; border-color: #7c8a97; animation: pulse 2s infinite; }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(124,138,151,0.4); }
    70% { box-shadow: 0 0 0 6px rgba(124,138,151,0); }
    100% { box-shadow: 0 0 0 0 rgba(124,138,151,0); }
}

/* ===== Approval nodes (Morandi) ===== */
.approval-node {
    min-width: 140px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    background: #f8fafc;
}
.approval-node-completed {
    background: #eef3ec;
    border-color: #8a9e7f;
}
.approval-node-processing {
    background: #eef2f7;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}
.approval-node-pending {
    background: #f8f9fa;
    border-color: #e2e8f0;
    opacity: 0.7;
}
.approval-node-cc {
    background: #edf1f4;
    border-color: #8899a6;
}
.approval-node-cc-completed {
    background: #eef3ec;
    border-color: #8a9e7f;
}
.approval-node-title { font-weight: 600; font-size: 13px; color: #212529; }
.approval-node-approvers { font-size: 11px; color: #6c757d; margin-top: 4px; }
.approval-node-status { font-size: 11px; margin-top: 6px; padding-top: 4px; border-top: 1px dashed #dee2e6; }
.approval-node-processing .approval-node-approvers { color: var(--primary-color); font-weight: 500; }
.approval-node-cc .approval-node-approvers { color: #5a6d7c; font-weight: 500; }
.approval-node-cc-completed .approval-node-approvers { color: #5e6f56; }

/* ===== Number input ===== */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* ===== List card & empty state ===== */
.list-card {
    border: 1px solid #e8ecf1;
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.list-card:hover { border-color: #cbd5e1; box-shadow: 0 2px 8px rgba(30,58,95,0.04); transform: translateY(-1px); }

.empty-state { text-align: center; color: #94a3b8; padding: 3.5rem 1rem; font-size: 14px; }
.empty-state i {
    font-size: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    color: #b6c2cf;
    background: #f1f4f8;
    border-radius: 50%;
}
table td.empty-state { padding: 3rem 1rem; }
table td.empty-state i { display: inline-flex; }

/* ===== Toast ===== */
.toast-container-top { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 1060; }
.toast-custom { min-width: 280px; max-width: 480px; border: none; border-radius: var(--radius-md); box-shadow: 0 4px 20px rgba(0,0,0,0.12); font-size: 14px; }
.toast-custom .toast-body { padding: 12px 20px; display: flex; align-items: center; gap: 10px; }
.toast-custom.toast-success { background: #d1e7dd; color: #0f5132; }
.toast-custom.toast-error { background: #f8d7da; color: #842029; }
.toast-custom.toast-warning { background: #fff3cd; color: #664d03; }
.toast-custom.toast-info { background: #cff4fc; color: #055160; }

/* ===== File upload ===== */
.file-upload-box { border: 1px dashed #d7dfe8; border-radius: var(--radius-md); padding: 10px 12px; background: #fbfcfe; }
.file-upload-box.is-dragover { background: #f0f5fb; border-color: var(--primary-color); }
.file-upload-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 8px; }
.file-upload-trigger { flex-shrink: 0; }
.file-upload-hint { color: #94a3b8; font-size: 12px; }
.file-upload-input { display: none; }
.file-upload-list { display: flex; flex-direction: column; gap: 6px; }
.file-upload-list:empty { display: none; }
.file-item { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 5px 10px; border: 1px solid #e8edf3; border-radius: var(--radius-sm); background: #fff; font-size: 13px; line-height: 1.5; }
.file-item-icon { flex-shrink: 0; color: var(--primary-color); font-size: 14px; }
.file-item-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.file-item-name { flex: 0 1 auto; min-width: 0; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #334155; }
.file-item-size { color: #94a3b8; font-size: 11px; white-space: nowrap; }
.file-item-status { font-size: 10px; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.file-item-status.pending { background: #fdf8e7; color: #946d2d; border: 1px solid #eed9a8; }
.file-item-status.uploaded { background: #eef3ec; color: #5e6f56; border: 1px solid #e2e8e0; }
.file-item-actions { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; margin-left: 4px; }
.file-item-actions .btn { padding: 1px 6px; font-size: 12px; line-height: 1.4; }
.file-item-empty { color: #94a3b8; font-size: 13px; padding: 4px 0; }

/* legacy attachment list item compat */
.file-upload-list > .border.rounded,
.file-upload-list > .d-flex.justify-content-between {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 5px 10px;
    border: 1px solid #e8edf3 !important;
    border-radius: var(--radius-sm) !important;
    background: #fff;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 6px;
}
.file-upload-list > .border.rounded > div:first-child,
.file-upload-list > .d-flex.justify-content-between > div:first-child { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.file-upload-list > .border.rounded > div:first-child > span,
.file-upload-list > .d-flex.justify-content-between > div:first-child > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; color: #334155; }
.file-upload-list > .border.rounded img,
.file-upload-list > .d-flex.justify-content-between img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.file-upload-list > .border.rounded .text-muted,
.file-upload-list > .d-flex.justify-content-between .text-muted { color: #94a3b8; font-size: 11px; white-space: nowrap; }
.file-upload-list > .border.rounded .badge,
.file-upload-list > .d-flex.justify-content-between .badge { font-size: 10px; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.file-upload-list > .border.rounded .btn,
.file-upload-list > .d-flex.justify-content-between .btn { padding: 1px 6px; font-size: 12px; line-height: 1.4; }

/* ===== No permission ===== */
.no-permission-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; text-align: center; }
.no-permission-page i { font-size: 4rem; color: #dee2e6; margin-bottom: 1rem; }
.no-permission-page h4 { color: #6c757d; margin-bottom: 0.5rem; }
.no-permission-page p { color: #adb5bd; margin-bottom: 1.5rem; }

/* ===== Auto-fit tables ===== */
.table-responsive.table-auto-fit { overflow-x: hidden !important; }
.table-responsive > table.table-auto-fit-target {
    width: var(--table-fit-width) !important;
    zoom: var(--table-fit-scale);
    transform-origin: left top;
}

/* ===== Nav pills / tabs override ===== */
.nav-pills .nav-link.active { background-color: var(--primary-color); }
.nav-tabs .nav-link.active { color: var(--primary-color); border-color: #dee2e6 #dee2e6 #fff; }
.nav-link { color: var(--primary-color); }
.nav-link:hover { color: var(--primary-hover); }

/* ===== Cost pages (estimation / initial / dynamic / settlement) ===== */
.cost-page-header { gap: 10px; min-height: 40px; }
.cost-page-identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cost-page-identity-icon { width: 38px; height: 38px; border-radius: 9px; background: #edf2f7; color: var(--primary-color); display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: 0 0 auto; }
.cost-page-identity-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cost-page-identity-name { font-size: 16px; font-weight: 600; color: #334155; line-height: 1.25; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cost-page-identity-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; color: #7d8b99; }
.cost-page-identity-no { font-weight: 500; letter-spacing: .2px; }
.cost-toolbar { display: flex; align-items: center; gap: 2px; padding: 3px; background: #fff; border: 1px solid #e8edf3; border-radius: 8px; box-shadow: none; }
.cost-toolbar-group, .cost-toolbar .btn-group { display: inline-flex; align-items: center; gap: 2px; }
.cost-toolbar-divider { width: 1px; height: 16px; margin: 0 4px; background: #e6ebf1; flex: 0 0 auto; }
.cost-toolbar .btn,
.cost-toolbar .btn-group .btn { width: 30px; min-width: 30px; height: 30px; min-height: 30px; padding: 0; border: 1px solid transparent; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: #5c6b7a; background: transparent; box-shadow: none; font-size: 14px; transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.cost-toolbar .btn:hover,
.cost-toolbar .btn:focus-visible { color: #1e3a5f; background: #eef2f7; box-shadow: none; }
.cost-toolbar .btn:focus-visible { outline: 2px solid rgba(30, 58, 95, .18); outline-offset: 1px; }
.cost-toolbar .btn.cost-tool-accent:hover,
.cost-toolbar .btn.cost-tool-accent:focus-visible { color: #2f5d80; background: #e9f1f9; }
.cost-toolbar .btn.cost-tool-caution:hover,
.cost-toolbar .btn.cost-tool-caution:focus-visible { color: #8a6d3b; background: #f8f2e4; border-color: #efe3c8; }
.cost-toolbar .btn.cost-initialize-btn { width: auto; min-width: 30px; padding: 0 9px; gap: 4px; font-size: 12px; }
.cost-toolbar .btn.cost-save-btn,
.cost-toolbar .btn.cost-save-btn.btn-primary { width: auto; min-width: 30px; padding: 0 12px; gap: 5px; font-size: 12.5px; font-weight: 600; color: #fff; background: var(--primary-color); border-color: var(--primary-color); box-shadow: none; }
.cost-toolbar .btn.cost-save-btn:hover,
.cost-toolbar .btn.cost-save-btn:focus-visible { color: #fff; background: var(--primary-hover); border-color: var(--primary-hover); }
.cost-toolbar .btn.cost-save-btn.btn-warning,
.cost-toolbar .btn.cost-save-btn.btn-warning:hover,
.cost-toolbar .btn.cost-save-btn.btn-warning:focus-visible { color: #fff; background: #8a6d3b; border-color: #8a6d3b; }
.cost-toolbar .btn.active,
.cost-toolbar .btn.btn-primary.active { color: #1e3a5f; background: #dce8f5; }
.cost-toolbar .btn:disabled, .cost-toolbar .btn.disabled { color: #98a5af; background: transparent; border-color: transparent; box-shadow: none; opacity: .48; }
.cost-toolbar .btn.cost-save-btn:disabled { color: #8e9ba5; background: #edf1f5; border-color: #edf1f5; box-shadow: none; opacity: .72; }

.cost-count-chip { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border: 1px solid #dbe4ec; border-radius: 999px; background: #f5f8fa; color: #708090; font-size: 12px; font-weight: 500; }
.cost-selection-chip { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border: 1px solid #e2e8ee; border-radius: 6px; background: #f7f9fb; color: #657585; font-size: 12px; white-space: nowrap; }
.cost-unsaved-badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500; color: #946d2d; background: #fdf6e4; border: 1px solid #eed9a8; }
.cost-unsaved-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #e5a13d; animation: costUnsavedPulse 1.6s ease-in-out infinite; }
@keyframes costUnsavedPulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) { .cost-unsaved-badge::before { animation: none; } }

.cost-help-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: #6b7d8f; text-decoration: none; }
.cost-help-toggle:hover, .cost-help-toggle:focus { color: #2f5d80; }
.cost-help-chevron { transition: transform .2s ease; }
.cost-help-toggle[aria-expanded="true"] .cost-help-chevron { transform: rotate(180deg); }

.cost-table { table-layout: fixed; width: 100%; margin-bottom: 0; }
.cost-table td { vertical-align: middle; font-variant-numeric: tabular-nums; transition: background-color .12s ease; }
.table.cost-table thead th { background-color: #f8f9fc; font-weight: 600; font-size: 13px; color: #5a5c69; border-bottom: 2px solid #dde5ee; }
.cost-table tbody tr:hover:not(.subtotal-row):not(.summary-row):not(.profit-row):not(.add-row):not(.comparison-group-row) > td:not(.cat-rail) { background-color: #f3f7fc; }
.cost-table td.cat-rail { background: #f8fafc; border-left: 3px solid var(--cat-rail-color, #8fa9c7); }
.cost-table .cat-measure { --cat-rail-color: #7d9cc0; }
.cost-table .cat-material { --cat-rail-color: #57a99a; }
.cost-table .cat-labor { --cat-rail-color: #d99e52; }
.cost-table .cat-other { --cat-rail-color: #9b8bc4; }
.cost-table .subtotal-row td { background: #f4f6f9; font-weight: 600; border-top: 2px solid #dfe5ec; }
.cost-table .summary-row td { background: #f4f6f9; font-weight: 600; border-top: 2px solid #dfe5ec; }
.cost-table .profit-row td { background: #fdf4d7; font-weight: 700; font-size: 15px; border-top: 2px solid #ecdb9a; }
.cost-table .profit-row td:first-child { border-left: 3px solid #d9a82e; }
.cost-table .add-row td { background: #fbfcfe; border-top: 1px dashed #d8dfe8; }
.cost-table .add-row .btn { width: 100%; border-style: dashed; border-color: #c9d4e0; color: #5f7285; background: transparent; transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.cost-table .add-row td:hover { background: #f2f7fd; }
.cost-table .add-row .btn:hover,
.cost-table .add-row .btn:focus-visible { color: #2f5d80; border-color: #8fb4d8; background: #eaf3fb; }
.cost-table .cell-input { border-color: transparent; background-color: transparent; transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease; }
.cost-table .cell-input:hover { border-color: #b8c2d8; background-color: #f8faff; }
.cost-table .cell-input[readonly] { cursor: cell; caret-color: transparent; }
.cost-table .cell-input:focus { border-color: var(--primary-color); background-color: #fff; box-shadow: inset 0 0 0 1px var(--primary-color); position: relative; z-index: 2; }
.cost-table .cell-input.is-editing:focus { cursor: text; caret-color: auto; box-shadow: 0 0 0 .18rem rgba(30, 58, 95, .18); }
.cost-table .cell-input.formula-pending { border-color: #f6c23e; background-color: #fffdf3; }
.cost-table .cell-input.is-invalid { border-color: #dc3545; background-image: none; }
.cost-table .input-group:focus-within .input-group-text { border-color: var(--primary-color); background-color: #eef2f7; }
.cost-table .neg { color: #dc3545; }
.cost-rate-pill { display: inline-block; min-width: 60px; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 13px; line-height: 1.4; color: #1c7c33; background: #fff; border: 1px solid #a9d9b4; }
.cost-rate-pill.is-neg { color: #c0392b; border-color: #e5ada6; }
.cost-auto-badge { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px; font-size: 10.5px; color: #6c7a89; background: #eef1f4; white-space: nowrap; }

.cost-list-filter { padding: 10px; border: none; border-radius: 8px; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .04); }
.cost-list-filter .input-group-text { border-color: #dce3e9; background: #f7f9fb; color: #82909d; }
.cost-list-filter .form-control, .cost-list-filter .form-select { border-color: #dce3e9; }
.cost-list-filter .form-control:focus, .cost-list-filter .form-select:focus { border-color: var(--primary-color); box-shadow: 0 0 0 .15rem rgba(30, 58, 95, .15); }
.cost-list-card { overflow: hidden; border: none; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, .04); }
.cost-list-table { font-size: 13px; table-layout: fixed; width: 100%; }
.table.cost-list-table thead th { height: 40px; padding: 6px 8px; border-bottom: 2px solid #dde5ee; font-weight: 600; font-size: 13px; letter-spacing: .01em; }
.table.cost-list-table thead tr.cost-head-group-row th { height: 24px; padding: 2px 8px; font-size: 12px; letter-spacing: .06em; border-bottom-width: 1px; }
.table.cost-list-table thead tr.cost-head-sub-row th { height: 30px; padding: 3px 8px; }
.list-body-scroll .table.cost-list-table thead tr.cost-head-sub-row > th { top: 24px; }
.cost-list-table thead th.cost-head-base { background: #f8f9fc !important; }
.cost-list-table thead th.cost-head-blue { background: #eef2f8 !important; color: #46638a; }
.cost-list-table thead th.cost-head-teal { background: #ebf5f2 !important; color: #3f6f63; }
.cost-list-table thead th.cost-head-violet { background: #f2f0f8 !important; color: #5f5480; }
.table.cost-list-table tbody td { padding: 6px 10px; border-color: #edf1f4; color: #536271; font-variant-numeric: tabular-nums; }
.cost-list-table tbody tr:hover > td:not(.cost-due-90):not(.cost-due-60):not(.cost-due-30):not(.cost-due-7):not(.cost-due-over) { background: #f3f7fc; }
.cost-list-table th.cost-group-start, .cost-list-table td.cost-group-start { border-left: 1px solid #e2e8ee; }
.cost-project-link { color: #294f70; font-weight: 500; text-decoration-color: rgba(41, 79, 112, .35) !important; }
.cost-project-link:hover { color: #183d5e; }
.cost-project-number { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-value-link { color: #53697c; font-variant-numeric: tabular-nums; text-decoration-color: rgba(83, 105, 124, .28) !important; }
.cost-value-link.cost-value-dynamic { color: #3f687d; }
.cost-profit-variance { font-variant-numeric: tabular-nums; font-weight: 500; }
.cost-profit-variance.is-positive { color: #198754; }
.cost-profit-variance.is-negative { color: #dc3545; }
.cost-lock-pill { display: inline-flex; align-items: center; gap: 4px; min-height: 22px; padding: 0 9px; border: 1px solid #e4e9ee; border-radius: 999px; background: #f4f6f8; color: #6c7a89; font-size: 11px; white-space: nowrap; }
.cost-lock-pill.is-locked { border-color: #ecd9c8; background: #fdf5ec; color: #96622a; }
.cost-lock-pill.is-open { border-color: #d8e3dd; background: #f4f8f6; color: #647f70; }
.cost-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-right: auto; color: #82909d; font-size: 12px; white-space: nowrap; }
.cost-legend-dot { display: inline-block; width: 10px; height: 10px; margin-right: 4px; border: 1px solid rgba(0, 0, 0, .06); border-radius: 3px; vertical-align: -1px; }
.cost-legend-hint { color: #a7b3bf; font-size: 11.5px; }
.cost-legend-hint .bi { margin-right: 3px; font-size: 11px; }
.cost-list-table td.cost-due-90 { background: #eef3f8; }
.cost-list-table td.cost-due-60 { background: #fdf8e7; }
.cost-list-table td.cost-due-30 { background: #fdefdc; }
.cost-list-table td.cost-due-7 { background: #fbe4df; }
.cost-list-table td.cost-due-over { background: #f8d7da; color: #b02a37; font-weight: 600; }
.cost-list-table td.cost-due-over .cost-cell-date { color: #b02a37; font-weight: 600; }
.cost-list-table td.cost-late { color: #b02a37; font-weight: 500; }
.cost-list-table td.cost-late .cost-cell-date { color: #b02a37; }
.cost-list-table td.cost-ontime { color: #198754; }
.cost-list-table td.cost-ontime .cost-cell-date { color: #198754; }
.cost-cell-date { width: 100%; padding: 2px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: center; transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease; }
.cost-cell-date::-webkit-calendar-picker-indicator { display: none; }
.cost-cell-date:hover { border-color: #b8c2d8; }
.cost-cell-date:focus { border-color: var(--primary-color); outline: none; background: #fff; box-shadow: inset 0 0 0 1px var(--primary-color); }
.cost-progress-link { color: #53697c; font-variant-numeric: tabular-nums; text-decoration-color: rgba(83, 105, 124, .28) !important; }
.cost-progress-link:hover { color: #294f70; font-weight: 600; }
.table.cost-list-table.sp-list-table tbody td { padding: 4px 8px; }
.sp-list-table .cost-cell-date { padding: 1px 2px; font-size: 12px; }
.sp-list-table .cost-lock-pill { gap: 3px; padding: 0 7px; }
.cost-flash { animation: costFlash .8s ease-out; }
@keyframes costFlash { 0% { box-shadow: inset 0 0 0 2px rgba(25, 135, 84, .55); } 100% { box-shadow: inset 0 0 0 2px rgba(25, 135, 84, 0); } }

@media (max-width: 1200px) {
    .cost-page-header { align-items: flex-start !important; }
    .cost-toolbar { flex-wrap: wrap; justify-content: flex-end; }
}

/* ===== Responsive ===== */
@media screen and (max-width: 1440px) {
    :root { --sidebar-width: 200px; }
    .page-content { padding: .75rem; }
    .topbar { padding-left: .75rem; padding-right: .75rem; }
}
@media screen and (max-width: 1200px) {
    :root { --sidebar-width: 180px; }
    .page-content { padding: .5rem; }
    .nav-menu .nav-link { padding-left: 8px; padding-right: 8px; }
}
@media screen and (max-width: 991px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { padding-left: .75rem; padding-right: .75rem; }
    .sidebar-toggle { display: inline-flex; }
    .spa-progress { left: 0; }
    .page-content { padding: .75rem; }
}
@media screen and (max-width: 575px) {
    .card-body { padding: 1rem; }
    .page-content { padding: .5rem; }
}

/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
