/* =========================================================================
   Curtain House ERP — UI theme on top of Bootstrap 5.3
   Brand: Curtain House red + ink; neutral warm-grey workspace.
   ========================================================================= */
:root {
    --ch-red: #d92f3a;
    --ch-red-600: #bf2430;
    --ch-red-50: #fdecee;
    --ch-ink: #16181d;
    --ch-ink-2: #3b3f48;
    --ch-muted: #6b7280;
    --ch-line: #e7e5e4;
    --ch-line-2: #f0eeec;
    --ch-bg: #f6f5f3;
    --ch-card: #ffffff;
    --ch-green: #15803d;
    --ch-green-50: #e9f7ee;
    --ch-amber: #b45309;
    --ch-amber-50: #fdf4e3;
    --ch-blue: #1d4ed8;
    --ch-blue-50: #eaf0fe;
    --ch-sidebar-w: 248px;
    --ch-sidebar-w-collapsed: 72px;
    --ch-radius: 12px;
    --ch-shadow: 0 1px 2px rgba(22, 24, 29, .04), 0 1px 1px rgba(22, 24, 29, .03);

    --bs-primary: var(--ch-red);
    --bs-primary-rgb: 217, 47, 58;
    --bs-link-color: var(--ch-red-600);
    --bs-link-hover-color: var(--ch-red);
    --bs-link-color-rgb: 191, 36, 48;
    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --bs-body-color: var(--ch-ink);
    --bs-body-bg: var(--ch-bg);
    --bs-body-font-size: .9rem;
    --bs-secondary-bg: #f3f2f0;
    --bs-tertiary-bg: #f8f7f5;
    --bs-border-color: var(--ch-line);
    --bs-border-radius: 8px;
    --bs-focus-ring-color: rgba(217, 47, 58, .2);
}

body { font-size: .9rem; -webkit-font-smoothing: antialiased; }
.tabular, .table td.num, .table th.num, .money { font-variant-numeric: tabular-nums; }
a { text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
.btn:hover, .nav-item:hover, .dropdown-item:hover, .page-link:hover, .stat:hover { text-decoration: none; }

/* ---------- Buttons & forms ---------- */
.btn { font-weight: 500; border-radius: 8px; font-size: .86rem; }
.btn-lg { font-size: 1rem; }
.btn-primary { --bs-btn-bg: var(--ch-red); --bs-btn-border-color: var(--ch-red); --bs-btn-hover-bg: var(--ch-red-600);
    --bs-btn-hover-border-color: var(--ch-red-600); --bs-btn-active-bg: #a51f29; --bs-btn-active-border-color: #a51f29;
    --bs-btn-disabled-bg: var(--ch-red); --bs-btn-disabled-border-color: var(--ch-red); }
.btn-outline-primary { --bs-btn-color: var(--ch-red-600); --bs-btn-border-color: #efb3b8; --bs-btn-hover-bg: var(--ch-red);
    --bs-btn-hover-border-color: var(--ch-red); --bs-btn-active-bg: var(--ch-red-600); }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--ch-line); --bs-btn-hover-bg: #f3f2f0; --bs-btn-hover-border-color: #dcd9d6; }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--ch-ink-2); }
.btn-ghost:hover { background: #efedea; }
.btn-icon { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0;
    border-radius: 8px; color: var(--ch-ink-2); background: transparent; border: 0; }
.btn-icon:hover { background: #efedea; }
.form-label { font-weight: 500; font-size: .82rem; color: var(--ch-ink-2); margin-bottom: .3rem; }
.form-label .req { color: var(--ch-red); margin-left: 2px; }
.form-control, .form-select { background-color: #fff; border-radius: 8px; border-color: #dedad6; font-size: .9rem; padding: .5rem .7rem; }
.form-select { padding-right: 2.25rem; }
.form-select-sm { padding-right: 2rem; }
.form-control:focus, .form-select:focus { border-color: #e98d94; box-shadow: 0 0 0 .2rem rgba(217, 47, 58, .12); }
.form-text { font-size: .78rem; }
.form-check-input:checked { background-color: var(--ch-red); border-color: var(--ch-red); }
.form-switch .form-check-input:focus { border-color: #e98d94; }
.input-group-text { background: #f7f6f4; border-color: #dedad6; color: var(--ch-muted); }
.form-section-title { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ch-muted);
    font-weight: 600; margin: 0 0 .75rem; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--ch-sidebar-w); background: #fff; border-right: 1px solid var(--ch-line); display: flex;
    flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 1040; transition: width .2s ease, transform .2s ease; }
.app-main { flex: 1; min-width: 0; margin-left: var(--ch-sidebar-w); display: flex; flex-direction: column;
    transition: margin-left .2s ease; }
.sidebar-brand { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 18px;
    border-bottom: 1px solid var(--ch-line-2); }
.brand-link { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { height: 46px; width: auto; }
.brand-mark { width: 34px; height: 34px; display: none; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-label { font-size: .68rem; letter-spacing: .09em; text-transform: uppercase; color: #9a948e; font-weight: 600;
    padding: 14px 12px 6px; white-space: nowrap; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; color: var(--ch-ink-2);
    font-weight: 500; white-space: nowrap; position: relative; margin-bottom: 2px; }
.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; color: #8a847e; }
.nav-item:hover { background: #f6f4f2; color: var(--ch-ink); }
.nav-item.active { background: var(--ch-red-50); color: var(--ch-red-600); }
.nav-item.active i { color: var(--ch-red); }
.nav-item.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
    background: var(--ch-red); }
.sidebar-user { border-top: 1px solid var(--ch-line-2); padding: 12px 16px; display: flex; gap: 10px; align-items: center; }
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-user-text strong { font-size: .82rem; }
.sidebar-user-text small { color: var(--ch-muted); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ch-ink); color: #fff; display: inline-flex;
    align-items: center; justify-content: center; font-size: .74rem; font-weight: 600; letter-spacing: .02em; flex: none; }
.avatar-sm { width: 30px; height: 30px; }

/* Collapsed (desktop) */
.sidebar-collapsed .sidebar { width: var(--ch-sidebar-w-collapsed); }
.sidebar-collapsed .app-main { margin-left: var(--ch-sidebar-w-collapsed); }
.sidebar-collapsed .brand-logo, .sidebar-collapsed .nav-item span, .sidebar-collapsed .nav-label,
.sidebar-collapsed .sidebar-user-text { display: none; }
.sidebar-collapsed .brand-mark { display: block; }
.sidebar-collapsed .sidebar-brand { padding: 0; justify-content: center; flex-direction: column; gap: 4px; height: 92px; }
.sidebar-collapsed .sidebar-collapse i { transform: rotate(180deg); }
.sidebar-collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar-collapsed .nav-list { border-top: 1px solid var(--ch-line-2); padding-top: 6px; margin-top: 6px; }
.sidebar-collapsed .sidebar-user { justify-content: center; padding: 12px 0; }

.sidebar-backdrop { display: none; }

/* Topbar */
.topbar { height: 64px; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--ch-line);
    display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 1030; }
.topbar-toggle { display: none; }
.topbar-title { flex: 1; min-width: 0; }
.page-title { font-size: 1.12rem; font-weight: 650; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb { font-size: .74rem; --bs-breadcrumb-divider-color: #b5afa9; --bs-breadcrumb-item-active-color: var(--ch-muted); }
.breadcrumb a { color: var(--ch-muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; background: transparent; border: 0; padding: 4px 6px; border-radius: 10px; color: var(--ch-ink); }
.user-chip:hover { background: #f3f2f0; }
.user-chip-text { flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-chip-text strong { font-size: .82rem; }
.user-chip-text small { font-size: .72rem; color: var(--ch-muted); }

.content { padding: 24px; flex: 1; }
.app-footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 24px; font-size: .74rem; color: #9a948e; }

.flash-stack { margin-bottom: 16px; }
.flash-stack .alert { border: 0; border-left: 4px solid; border-radius: 8px; box-shadow: var(--ch-shadow); }
.alert-success { border-left-color: var(--ch-green) !important; background: var(--ch-green-50); color: #14532d; }
.alert-danger { border-left-color: var(--ch-red) !important; background: var(--ch-red-50); color: #7f1d1d; }
.alert-warning { border-left-color: #d97706 !important; background: var(--ch-amber-50); color: #78350f; }
.alert-info { border-left-color: var(--ch-blue) !important; background: var(--ch-blue-50); color: #1e3a8a; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--ch-line); border-radius: var(--ch-radius); box-shadow: var(--ch-shadow); background: var(--ch-card); }
.card-header { background: transparent; border-bottom: 1px solid var(--ch-line-2); padding: 14px 18px; display: flex;
    align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: .95rem; font-weight: 600; margin: 0; }
.card-subtitle { font-size: .78rem; color: var(--ch-muted); margin: 2px 0 0; }
.card-body { padding: 18px; }
.card-footer { background: #fbfaf9; border-top: 1px solid var(--ch-line-2); padding: 12px 18px; }

/* Stat tiles */
.stat { display: flex; flex-direction: row; gap: 14px; align-items: center; padding: 16px 18px; color: inherit; height: 100%; text-align: left; }
.stat > div { min-width: 0; }
a.stat:hover { background: #fcfbfa; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex: none; }
.stat-icon.red { background: var(--ch-red-50); color: var(--ch-red); }
.stat-icon.green { background: var(--ch-green-50); color: var(--ch-green); }
.stat-icon.blue { background: var(--ch-blue-50); color: var(--ch-blue); }
.stat-icon.amber { background: var(--ch-amber-50); color: var(--ch-amber); }
.stat-icon.ink { background: #eeedeb; color: var(--ch-ink); }
.stat-label { font-size: .76rem; color: var(--ch-muted); font-weight: 500; margin: 0; }
.stat-value { white-space: nowrap; font-size: clamp(1.05rem, 1.45vw, 1.35rem); font-weight: 650; letter-spacing: -.02em; margin: 0; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .74rem; color: var(--ch-muted); }

.segmented { display: inline-flex; background: #efedea; padding: 3px; border-radius: 9px; gap: 2px; }
.segmented a { padding: 5px 12px; border-radius: 7px; font-size: .8rem; font-weight: 500; color: var(--ch-ink-2); }
.segmented a.active { background: #fff; color: var(--ch-ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented a:hover { text-decoration: none; }

/* ---------- Tables ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 18px;
    border-bottom: 1px solid var(--ch-line-2); }
.toolbar-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search-box { position: relative; min-width: 240px; }
.search-box i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #9a948e; }
.search-box .form-control { padding-left: 34px; }
.table { --bs-table-bg: transparent; --bs-table-hover-bg: #faf8f6; margin: 0; font-size: .86rem; }
.table > thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ch-muted); font-weight: 600;
    background: #fbfaf9; border-bottom: 1px solid var(--ch-line); padding: 10px 14px; white-space: nowrap; }
.table > thead th a { color: inherit; display: inline-flex; gap: 6px; align-items: center; }
.table > thead th a:hover { color: var(--ch-ink); text-decoration: none; }
.table > thead th .sort-idle { opacity: .35; }
.table > tbody td { padding: 11px 14px; border-color: var(--ch-line-2); vertical-align: middle; }
.table .num { text-align: right; white-space: nowrap; }
.table tr[data-href] { cursor: pointer; }
.table .cell-main { font-weight: 550; color: var(--ch-ink); }
.table .cell-fill { width: 100%; max-width: 0; }
.table .cell-fill > .cell-main, .table .cell-fill > .cell-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .cell-sub { font-size: .76rem; color: var(--ch-muted); }
.table-lines > tbody td { padding: 9px 12px; }
.table-lines tfoot td, .table-lines tfoot th { border: 0; padding: 6px 12px; }
.doc-no { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; font-weight: 600; color: var(--ch-ink); }
.empty-state { text-align: center; padding: 48px 16px; color: var(--ch-muted); }
.empty-state i { font-size: 2rem; color: #c9c4bf; display: block; margin-bottom: 8px; }
.list-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px 18px;
    border-top: 1px solid var(--ch-line-2); font-size: .8rem; color: var(--ch-muted); }
.pagination { --bs-pagination-active-bg: var(--ch-ink); --bs-pagination-active-border-color: var(--ch-ink); --bs-pagination-color: var(--ch-ink-2);
    --bs-pagination-font-size: .8rem; --bs-pagination-padding-x: .65rem; --bs-pagination-focus-box-shadow: none; margin: 0; }
.row-actions { white-space: nowrap; text-align: right; }

/* Badges */
.badge-soft { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-soft::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--ch-green-50); color: var(--ch-green); }
.badge-amber { background: var(--ch-amber-50); color: var(--ch-amber); }
.badge-red { background: var(--ch-red-50); color: var(--ch-red-600); }
.badge-blue { background: var(--ch-blue-50); color: var(--ch-blue); }
.badge-grey { background: #eeedeb; color: #57534e; }

/* ---------- Detail pages ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 24px; }
.meta-grid dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ch-muted); font-weight: 600; margin-bottom: 2px; }
.meta-grid dd { margin: 0; font-weight: 500; word-break: break-word; }
.doc-paper { background: #fff; }
.doc-title { text-align: center; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; margin: 6px 0 18px; font-size: 1rem; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.section-head h3 { font-size: .9rem; font-weight: 600; margin: 0; text-decoration: underline; text-underline-offset: 3px; }
.totals { margin-left: auto; max-width: 360px; }
.totals .row-t { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .row-t.grand { border-top: 2px solid var(--ch-ink); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 1.02rem; }
.totals .row-t.balance { color: var(--ch-red-600); font-weight: 650; }

/* ---------- Line-item editor ---------- */
.line-editor .section-card { border: 1px solid var(--ch-line); border-radius: 10px; margin-bottom: 14px; background: #fff; }
.line-editor .section-card-head { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: #fbfaf9;
    border-bottom: 1px solid var(--ch-line-2); border-radius: 10px 10px 0 0; }
.line-editor .section-card-head .form-control { font-weight: 600; }
.line-editor .section-badge { font-size: .7rem; font-weight: 700; color: var(--ch-muted); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.line-table { width: 100%; }
.line-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ch-muted); font-weight: 600; padding: 8px 6px; }
.line-table td { padding: 5px 6px; vertical-align: top; }
.line-table td.col-handle { width: 28px; color: #b5afa9; padding-top: 12px; text-align: center; font-size: .78rem; }
.line-table td.col-amount { text-align: right; padding-top: 12px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.line-table .form-control, .line-table .form-select { padding: .4rem .55rem; font-size: .86rem; }
.line-table .col-qty { width: 110px; } .line-table .col-unit { width: 110px; } .line-table .col-price { width: 140px; }
.line-table .col-amt { width: 130px; } .line-table .col-act { width: 74px; white-space: nowrap; }
.line-table .btn-icon { width: 30px; height: 30px; }
.line-table tr.row-removing { opacity: .4; }
.section-total { display: flex; justify-content: flex-end; gap: 16px; padding: 8px 14px 12px; font-size: .86rem; }
.section-total strong { font-variant-numeric: tabular-nums; min-width: 120px; text-align: right; }
.grand-bar { position: sticky; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--ch-line);
    margin: 0 -18px -18px; padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    border-radius: 0 0 var(--ch-radius) var(--ch-radius); z-index: 5; }
.grand-bar .grand-figure { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.grand-bar .grand-figure small { font-size: .74rem; color: var(--ch-muted); font-weight: 500; margin-right: 8px; text-transform: uppercase; letter-spacing: .06em; }

/* Autocomplete / searchable select */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 1060; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--ch-line);
    border-radius: 8px; box-shadow: 0 10px 30px rgba(22,24,29,.12); max-height: 260px; overflow-y: auto; padding: 4px; }
.ac-item { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: .86rem; display: flex; justify-content: space-between; gap: 10px; }
.ac-item small { color: var(--ch-muted); white-space: nowrap; }
.ac-item.active, .ac-item:hover { background: var(--ch-red-50); color: var(--ch-red-600); }
.ac-item mark { background: none; padding: 0; font-weight: 700; color: inherit; }
.ac-empty { padding: 8px 10px; color: var(--ch-muted); font-size: .84rem; }
.ss-wrap { position: relative; }
.ss-wrap select.ss-native { position: absolute; opacity: 0; pointer-events: none; height: 0; width: 0; }
.ss-toggle { text-align: left; display: flex; justify-content: space-between; align-items: center; cursor: pointer; background-color: #fff; }
.ss-toggle .ss-placeholder { color: #9a948e; }
.ss-toggle .ss-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-panel { position: absolute; z-index: 1060; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--ch-line);
    border-radius: 8px; box-shadow: 0 10px 30px rgba(22,24,29,.12); padding: 6px; }
.ss-panel .form-control { margin-bottom: 4px; }
.ss-options { max-height: 260px; overflow-y: auto; }

/* Dashboard */
.chart-wrap { position: relative; height: 300px; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--ch-line-2); font-size: .84rem; }
.activity li:last-child { border-bottom: 0; }
.activity .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ch-red); margin-top: 6px; flex: none; }
.activity time { color: var(--ch-muted); font-size: .74rem; white-space: nowrap; }
.quick-links { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-links a { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--ch-line); border-radius: 10px;
    color: var(--ch-ink); font-weight: 500; font-size: .84rem; background: #fff; }
.quick-links a:hover { border-color: #efb3b8; background: var(--ch-red-50); text-decoration: none; }
.quick-links i { color: var(--ch-red); font-size: 1.05rem; }

/* Log viewer */
.log-row { font-size: .82rem; }
.log-row summary { list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; padding: 9px 14px; }
.log-row summary::-webkit-details-marker { display: none; }
.log-row[open] summary { background: #fbfaf9; }
.log-row .log-meta { padding: 8px 14px 12px 104px; color: var(--ch-muted); font-size: .78rem; display: grid; gap: 2px; background: #fbfaf9; }
.log-row + .log-row { border-top: 1px solid var(--ch-line-2); }
.log-time { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--ch-muted); min-width: 64px; }
.lvl { font-size: .66rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; min-width: 46px; text-align: center; letter-spacing: .04em; }
.lvl-1 { background: #7f1d1d; color: #fff; } .lvl-2 { background: var(--ch-red-50); color: var(--ch-red-600); }
.lvl-3 { background: var(--ch-amber-50); color: var(--ch-amber); } .lvl-4 { background: var(--ch-blue-50); color: var(--ch-blue); }

/* Confirm modal */
.confirm-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--ch-red-50); color: var(--ch-red); display: flex;
    align-items: center; justify-content: center; font-size: 1.3rem; margin-bottom: 12px; }
.modal-content { border: 0; border-radius: 14px; }

/* Settings tabs */
.nav-tabs-clean { border-bottom: 1px solid var(--ch-line); gap: 4px; }
.nav-tabs-clean .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--ch-muted); font-weight: 500; padding: 10px 14px; }
.nav-tabs-clean .nav-link.active { color: var(--ch-ink); border-bottom-color: var(--ch-red); background: transparent; }
.letterhead-preview { max-width: 100%; border: 1px dashed var(--ch-line); border-radius: 8px; padding: 8px; background: #fff; }

/* ---------- Auth ---------- */
.auth-page { background: #fff; }
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-aside { position: relative; overflow: hidden; background: var(--ch-ink); color: #fff; display: flex; align-items: flex-end; padding: 56px; }
.auth-aside-inner { position: relative; z-index: 2; max-width: 440px; }
.auth-aside h2 { font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; margin: 18px 0 10px; }
.auth-aside p { color: #b9b4ae; margin: 0; }
.auth-logo-light { height: 54px; background: #fff; padding: 8px 12px; border-radius: 10px; }
.auth-drape { position: absolute; inset: 0; z-index: 1; opacity: .9;
    background:
      repeating-linear-gradient(90deg, rgba(217,47,58,.0) 0 38px, rgba(217,47,58,.22) 38px 40px, rgba(0,0,0,.0) 40px 80px),
      radial-gradient(ellipse at 20% -10%, rgba(217,47,58,.55), transparent 55%),
      linear-gradient(180deg, rgba(22,24,29,0) 40%, rgba(22,24,29,.95) 100%); }
.auth-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { height: 52px; margin-bottom: 26px; }
.auth-card h1 { font-size: 1.4rem; font-weight: 650; letter-spacing: -.01em; margin-bottom: 4px; }
.auth-card .lead { font-size: .88rem; color: var(--ch-muted); margin-bottom: 22px; }
.auth-foot { margin-top: 32px; font-size: .75rem; color: #9a948e; }
.pw-toggle { cursor: pointer; }

/* ---------- Error page ---------- */
.error-box { max-width: 520px; margin: 40px auto; text-align: center; }
.error-code { font-size: 3.6rem; font-weight: 750; color: var(--ch-red); letter-spacing: -.04em; line-height: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); width: 272px; box-shadow: 0 0 40px rgba(0,0,0,.18); }
    .app-main, .sidebar-collapsed .app-main { margin-left: 0; }
    .sidebar-open .sidebar { transform: none; }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(22,24,29,.4); z-index: 1035; }
    .topbar-toggle { display: inline-flex; }
    .topbar { padding: 0 14px; }
    .content { padding: 16px; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}
@media (max-width: 767.98px) {
    .search-box { min-width: 0; flex: 1 1 100%; }
    .line-table thead { display: none; }
    .line-table, .line-table tbody, .line-table tr, .line-table td { display: block; width: 100% !important; }
    .line-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border-bottom: 1px solid var(--ch-line-2); }
    .line-table td { padding: 0; }
    .line-table td.col-handle { display: none; }
    .line-table td.col-desc { grid-column: 1 / -1; }
    .line-table td.col-amount { text-align: left; padding: 6px 0 0; }
    .line-table td.col-act-cell { text-align: right; }
    .topbar .breadcrumb { display: none; }
    .grand-bar { flex-direction: column; align-items: stretch; }
    .grand-bar > div { width: 100%; justify-content: space-between; }
    .grand-bar .btn { flex: 1; }
    .section-total, [data-action="add-row"] { white-space: nowrap; }
    .detail-actions { width: 100%; }
    .detail-actions > .btn, .detail-actions > form { flex: 1 1 auto; }
    .detail-actions > form .btn { width: 100%; }
    .table-responsive-stack thead { display: none; }
    .table-responsive-stack tbody tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--ch-line-2); }
    .table-responsive-stack tbody td { display: flex; justify-content: space-between; border: 0; padding: 3px 0; text-align: right; gap: 12px; }
    .table-responsive-stack tbody td::before { content: attr(data-label); font-weight: 600; color: var(--ch-muted); font-size: .74rem;
        text-transform: uppercase; letter-spacing: .04em; text-align: left; }
    .table-responsive-stack tbody td.row-actions::before { content: ""; }
}

@media print {
    .sidebar, .topbar, .app-footer, .detail-actions, .flash-stack, .no-print { display: none !important; }
    .app-main { margin: 0 !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}
