/* ==========================================================================
   ContractorApp — application styles (on top of Bootstrap 5)
   ========================================================================== */

:root {
    --sidebar-width: 250px;
    --sidebar-bg: #1a3a5c;
    --sidebar-text: #c8d8e8;
    --sidebar-muted: rgba(200, 216, 232, 0.5);
    --sidebar-hover: #2a5080;
    --sidebar-active: #3a6090;
    --sidebar-active-border: #7ec8f7;
    --accent: #1a3a5c;
    --accent-hover: rgba(26,58,92,0.15);
    --page-bg: #f4f6f9;
    --card-border: #e2e8f0;
    --text-muted: #64748b;
    --radius: 0.5rem;
    --bs-border-radius: 0.375rem;
}

html, body { height: 100%; }

body {
    background: var(--page-bg);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.925rem;
    color: #101828;
    overflow-x: hidden;
}

.min-w-0 { min-width: 0; }
.text-muted { color: var(--text-muted) !important; }
a { color: #1a3a5c; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.2rem 1.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand:hover { color: #fff; }
.sidebar-brand i { color: #fff; font-size: 1.35rem; }

.sidebar-portal-tag {
    margin-left: auto;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #7ec8f7;
    border: 1px solid rgba(126, 200, 247, 0.4);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
}

.sidebar-tenant {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    font-size: 0.8rem;
    color: var(--sidebar-text);
}

.tenant-mark {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #7ec8f7;
    color: #1a3a5c;
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
}

.sidebar-nav { flex: 1; padding: 0.5rem 0 1rem; overflow-y: auto; }

.sidebar-heading {
    padding: 0.75rem 1.5rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-muted);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover { background-color: var(--sidebar-hover); color: #fff; }
.sidebar-link.active { background-color: var(--sidebar-active); color: #fff; border-left-color: var(--sidebar-active-border); }
.sidebar-link.active i { color: #fff; }
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; }

.sidebar-backdrop { display: none; }

.main-area { flex: 1; margin-left: var(--sidebar-width); min-width: 0; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 56px;
    min-height: 56px;
    padding: 0 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--card-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.topbar .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1a3a5c;
    margin: 0;
}

.topbar-search { position: relative; flex: 1; max-width: 420px; margin: 0; }

.topbar-search i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.topbar-search .form-control { padding-left: 2.25rem; background: var(--page-bg); border-color: transparent; }
.topbar-search .form-control:focus { background: #fff; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

.btn-icon { border: none; background: transparent; font-size: 1.25rem; color: #344054; padding: 0.35rem 0.55rem; min-width: 40px; min-height: 40px; }

.user-menu-toggle { display: flex; align-items: center; gap: 0.6rem; border: none; padding: 0.2rem 0.4rem; text-align: left; }
.user-menu-toggle:hover { background: var(--page-bg); }
.user-menu-text { flex-direction: column; line-height: 1.2; }

.avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #1a3a5c;
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.avatar-sm {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #e0e7ff;
    color: #3730a3;
    display: inline-grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.content { padding: 1.5rem; max-width: 1680px; }

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; line-height: 1.25; }
.page-subtitle { color: var(--text-muted); margin: 0.3rem 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.breadcrumb a { text-decoration: none; }

/* ---------- Cards ---------- */
.card { border: none; border-color: var(--card-border); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background-color: #fff;
    border-bottom: 1px solid #e9ecef;
    padding: 0.85rem 1.25rem;
    font-weight: 600;
}

.card-title { font-size: 0.975rem; font-weight: 600; margin: 0; }
.card-link { font-size: 0.85rem; text-decoration: none; white-space: nowrap; }

.stat-tile { padding: 1rem 1.15rem; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.stat-tile-link:hover { border-color: #c7ccd5; color: inherit; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.15rem; line-height: 1.2; word-break: break-word; overflow-wrap: anywhere; }
.stat-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.5rem; }

.kpi-icon {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 0.45rem;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
}

.kpi-icon-primary { background: #dbeafe; color: #1a3a5c; }
.kpi-icon-success { background: #dcfce7; color: #15803d; }
.kpi-icon-warning { background: #fef3c7; color: #b45309; }
.kpi-icon-info { background: #cffafe; color: #0e7490; }
.kpi-icon-danger { background: #fee2e2; color: #b91c1c; }
.kpi-icon-secondary { background: #f2f4f7; color: #475467; }

/* ---------- Tables ---------- */
.table { margin-bottom: 0; }

.table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    background: #f9fafb;
    white-space: nowrap;
}

.table td, .table th { padding: 0.7rem 1.1rem; }
.table > :not(caption) > * > * { border-bottom-color: #eef0f3; }
.table-card .table tbody tr:last-child td { border-bottom: 0; }
/* Allow dropdown menus to overflow table-responsive containers (desktop only) */
@media (min-width: 768px) {
    .table-card .table-responsive { overflow: visible !important; }
}

.table-card-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.1rem;
    border-top: 1px solid var(--card-border);
}

.table-card-footer .pagination { margin: 0; }
.table-card-footer nav > div:first-child { display: none !important; }
.table-card-footer nav > div:last-child > div:first-child { display: none; }

.row-title { font-weight: 600; color: #374151; text-decoration: none; }
.row-title:hover { color: #1a3a5c; text-decoration: underline; }
.cell-sub { font-size: 0.8rem; color: var(--text-muted); }

.list-group-item { padding: 0.75rem 1.25rem; border-color: #eef0f3; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: 0.35em 0.6em; border-radius: 0.3rem; }
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-info { background: #dbeafe; color: #1e40af; }
.badge-soft-primary { background: #e0e7ff; color: #3730a3; }
.badge-soft-secondary { background: #f2f4f7; color: #344054; }

/* ---------- Toolbar / filters ---------- */
.toolbar-card { padding: 0.75rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.toolbar .form-select, .toolbar .form-control[type="date"] { width: auto; max-width: 200px; flex: 0 1 auto; }
.toolbar-search { position: relative; flex: 1 1 240px; }
.toolbar-search i { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.toolbar-search .form-control { padding-left: 2.25rem; }
.toolbar-dates { display: flex; align-items: center; gap: 0.35rem; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 2.75rem 1rem; }
.empty-state i { font-size: 2.2rem; color: #98a2b3; }
.empty-state h2 { font-size: 1.05rem; font-weight: 600; margin-top: 0.75rem; }
.empty-state p { color: var(--text-muted); max-width: 420px; margin: 0.25rem auto 1rem; }
.empty-inline { padding: 1.25rem; color: var(--text-muted); font-size: 0.875rem; text-align: center; }

/* ---------- Forms ---------- */
.form-card .card-body { padding: 1.5rem; }

.form-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.form-divider { margin: 1.75rem 0 1.5rem; border: 0; border-top: 1px solid var(--card-border); opacity: 1; }
.form-label { color: #344054; font-weight: 500; margin-bottom: 0.35rem; }
.form-control, .form-select { min-height: 40px; }
.form-select { background-color: #fff; }
.input-group-text { background: #f2f4f7; color: #667085; }
.req { color: #dc2626; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.permission-group { border: 1px solid var(--card-border); border-radius: var(--radius); padding: 0.85rem 1rem; height: 100%; }
.permission-group h3 { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }

/* ---------- Detail views ---------- */
.detail-list {
    display: grid;
    grid-template-columns: minmax(110px, auto) 1fr;
    gap: 0.55rem 1rem;
    margin: 0;
}

.detail-list dt { font-weight: 400; color: var(--text-muted); }
.detail-list dd { margin: 0; font-weight: 500; word-break: break-word; }

.entity-header { display: flex; align-items: center; gap: 1rem; min-width: 0; }

.entity-mark {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: var(--radius);
    background: #eef2ff;
    color: #3730a3;
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    font-weight: 700;
    overflow: hidden;
}

.entity-mark img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Activity feed / deadlines ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed-item { display: flex; gap: 0.75rem; padding: 0.7rem 1.25rem; border-bottom: 1px solid #eef0f3; }
.feed-item:last-child { border-bottom: 0; }
.feed-icon {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #f2f4f7;
    color: #475467;
    display: grid;
    place-items: center;
    font-size: 0.85rem;
}
.feed-text { font-size: 0.875rem; }
.feed-meta { font-size: 0.75rem; color: var(--text-muted); }

.deadline-date {
    flex-shrink: 0;
    width: 46px;
    text-align: center;
    border-radius: 0.4rem;
    background: var(--page-bg);
    padding: 0.3rem 0;
    line-height: 1.1;
}

.deadline-date .day { display: block; font-weight: 700; font-size: 1.05rem; }
.deadline-date .month { font-size: 0.68rem; text-transform: uppercase; color: var(--text-muted); }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 260px; }
.chart-box-sm { height: 220px; }

.period-select { width: auto; min-width: 150px; }

/* ---------- Guest / auth pages ---------- */
.guest-body { background: var(--page-bg); }

.guest-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.guest-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.2rem; color: #101828; text-decoration: none; margin-bottom: 1.25rem; }
.guest-brand i { color: var(--accent); font-size: 1.5rem; }
.guest-card { width: 100%; max-width: 420px; }
.guest-card .card-body { padding: 2rem; }
.guest-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 0.3rem; }
.guest-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.guest-footer { color: var(--text-muted); font-size: 0.8rem; margin-top: 1.5rem; }

.error-shell { text-align: center; }
.error-code { font-size: 3.5rem; font-weight: 800; color: #d0d5dd; line-height: 1; margin-bottom: 0.5rem; }
.error-shell .guest-subtitle { max-width: 460px; }

/* ---------- Responsive ---------- */
@media (max-width: 1199.98px) {
    .content { padding: 1.25rem; }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .main-area { margin-left: 0; }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, 0.45);
        z-index: 1030;
    }
    .topbar { padding: 0.5rem 1rem; }
}

@media (max-width: 767.98px) {
    .content { padding: 1rem; }
    .page-header { align-items: flex-start; }
    .page-title { font-size: 1.25rem; }
    .toolbar .form-select, .toolbar .form-control[type="date"] { max-width: none; flex: 1 1 calc(50% - 0.5rem); }
    .toolbar-dates { flex: 1 1 100%; }
    .toolbar-dates .form-control { flex: 1; max-width: none; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .form-card .card-body { padding: 1.1rem; }
    .table td, .table th { padding: 0.6rem 0.75rem; }
    .chart-box { height: 220px; }
}

@media (max-width: 575.98px) {
    .topbar-search { display: none; }
    .stat-value { font-size: 1.3rem; }
    .guest-card .card-body { padding: 1.5rem; }
    .detail-list { grid-template-columns: 1fr; gap: 0.1rem; }
    .detail-list dd { margin-bottom: 0.5rem; }
}

/* ---------- Dashboard extras ---------- */
.quick-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 0.45rem; }
.status-legend li { padding: 0.2rem 0; }
[data-chart-loading].is-loading { opacity: 0.45; transition: opacity 0.15s; }

/* ---------- Project status bar ---------- */
.status-bar-card .card-body { padding: 1rem 1.25rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1.5rem; }
.status-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.status-step-form { margin: 0; }

.status-step {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 38px;
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--card-border);
    border-radius: 999px;
    background: #fff;
    color: #475467;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

span.status-step { cursor: default; }
button.status-step:hover { border-color: #98a2b3; color: #101828; background: #f9fafb; }
button.status-step:disabled { opacity: 0.6; cursor: wait; }

.status-step.is-current { font-weight: 600; }
.status-step-planning.is-current { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.status-step-active.is-current { background: #dcfce7; border-color: #86efac; color: #166534; }
.status-step-on_hold.is-current { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.status-step-completed.is-current { background: #e0e7ff; border-color: #a5b4fc; color: #3730a3; }
.status-step-cancelled.is-current { background: #f2f4f7; border-color: #d0d5dd; color: #344054; }

@media (max-width: 575.98px) {
    .status-bar { width: 100%; }
    .status-step-form, span.status-step { flex: 1 1 calc(50% - 0.5rem); }
    .status-step { width: 100%; justify-content: center; }
}

/* ── BuildTrack-compatible utility classes ── */

/* Row action buttons */
.btn-action {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.22rem 0.48rem; font-size: 0.8rem; line-height: 1.4;
    border: 1px solid #e2e8f0; border-radius: 6px;
    background: transparent; color: #64748b; cursor: pointer;
    text-decoration: none !important;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-action:hover, .btn-action:focus { background: #f1f5f9; border-color: #cbd5e1; color: #1a3a5c; }
.btn-action-danger { color: #dc2626 !important; border-color: #fecaca !important; }
.btn-action-danger:hover, .btn-action-danger:focus { background: #fef2f2 !important; border-color: #fca5a5 !important; color: #b91c1c !important; }
button.btn-action { background: transparent; }

/* Shared KPI summary cards */
.kpi-card {
    border-radius: 8px !important; border: 1px solid #e2e8f0 !important;
    border-left-width: 3px !important; box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
    transition: box-shadow 0.15s; padding: 0.85rem 1rem;
}
.kpi-card:hover { box-shadow: 0 3px 8px rgba(0,0,0,0.09) !important; }
.kpi-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: #64748b; margin-bottom: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-value {
    font-size: 1.1rem; font-weight: 700; color: #1a3a5c;
    font-variant-numeric: tabular-nums; letter-spacing: -0.01em; line-height: 1.25;
    word-break: break-word; overflow-wrap: anywhere;
}
.kpi-sub {
    font-size: 0.7rem; color: #94a3b8; margin-top: 2px;
}
.kpi-blue  { background: #f0f7ff !important; border-left-color: #3b82f6 !important; }
.kpi-red   { background: #fff5f5 !important; border-left-color: #ef4444 !important; }
.kpi-green { background: #f0fdf4 !important; border-left-color: #22c55e !important; }
.kpi-yellow{ background: #fffbeb !important; border-left-color: #f59e0b !important; }
.kpi-purple{ background: #faf5ff !important; border-left-color: #a855f7 !important; }
/* cs-sm: compact CS-wrapper for filter bars */
.cs-sm .cs-trigger { padding: 0.25rem 0.65rem; font-size: 0.875rem; min-height: calc(1.5em + 0.5rem + 2px); }

/* Module search toolbar inside card-body */
.search-bar { padding: 0.6rem 1rem; border-bottom: 1px solid #e2e8f0; background: #fafafa; }
.search-bar .input-group-text { background: #fff; border-right: none; font-size: 0.85rem; }
.search-bar .form-control { border-left: none; padding-left: 0; font-size: 0.875rem; }
.search-bar .form-control:focus { border-left: none; }

/* Global table refinement — extra padding on first/last cells */
.card .table > thead > tr > th:first-child,
.card .table > tbody > tr > td:first-child,
.card .table > tfoot > tr > td:first-child { padding-left: 1.25rem; }
.card .table > thead > tr > th:last-child,
.card .table > tbody > tr > td:last-child,
.card .table > tfoot > tr > td:last-child { padding-right: 1.25rem; }
.card .table > thead > tr > th { padding-top: 0.65rem; padding-bottom: 0.65rem; border-top: none; border-bottom: 2px solid #e2e8f0 !important; }
.card .table > tbody > tr > td { padding-top: 0.7rem; padding-bottom: 0.7rem; vertical-align: middle; border-bottom: 1px solid #f1f5f9; }
.card .table > tbody > tr:last-child > td { border-bottom: none; }
.card .table-hover > tbody > tr:hover > td { background-color: #f8fafc; }
.card .table > thead > tr > th { background-color: #f8fafc; color: #64748b; font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase; }
.table td a, .table td a:visited { color: #374151; text-decoration: none; }
.table td a:hover, .table td a:focus { color: #1a3a5c; text-decoration: underline; }

/* Force light theme on all form controls regardless of OS dark mode */
.form-select, .form-control, textarea.form-control {
    background-color: #ffffff !important; color: #212529 !important;
    border: 1px solid #ced4da; border-radius: 6px;
}
.form-select:focus, .form-control:focus {
    background-color: #ffffff !important; color: #212529 !important;
    border-color: #1a3a5c; box-shadow: 0 0 0 0.18rem rgba(26,58,92,0.18); outline: none;
}
.form-select:disabled, .form-control:disabled, .form-select[readonly], .form-control[readonly] {
    background-color: #f8f9fa !important; color: #6c757d !important;
}
.form-select option[value=""], .form-select option.placeholder { color: #6c757d; font-style: italic; }
.form-select option { background-color: #ffffff; color: #212529; }
.form-select option.no-data { color: #adb5bd; font-style: italic; }

/* Custom searchable select component */
.cs-wrapper { position: relative; }
.cs-trigger {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.45rem 0.85rem; background: #fff; border: 1px solid #ced4da;
    border-radius: 6px; cursor: pointer; font-size: 0.9rem; color: #212529;
    min-height: 38px; user-select: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.cs-trigger:hover { border-color: #adb5bd; }
.cs-wrapper.open .cs-trigger {
    border-color: #1a3a5c; border-bottom-left-radius: 0; border-bottom-right-radius: 0;
    box-shadow: 0 0 0 0.18rem rgba(26,58,92,0.18);
}
.cs-trigger.is-invalid { border-color: #dc3545 !important; }
.cs-placeholder { color: #6c757d; font-style: italic; }
.cs-arrow { font-size: 0.75rem; color: #6c757d; flex-shrink: 0; transition: transform 0.15s; }
.cs-wrapper.open .cs-arrow { transform: rotate(180deg); }
.cs-panel {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 1050;
    background: #fff; border: 1px solid #1a3a5c; border-top: none;
    border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.cs-wrapper.open .cs-panel { display: block; }
.cs-search-wrap {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 0.75rem; border-bottom: 1px solid #e9ecef;
}
.cs-search-wrap i { color: #9ca3af; font-size: 0.85rem; }
.cs-search { border: none; outline: none; flex: 1; font-size: 0.9rem; background: transparent; color: #212529; }
.cs-search::placeholder { color: #9ca3af; }
.cs-list { max-height: 210px; overflow-y: auto; }
.cs-item { padding: 0.55rem 0.85rem; cursor: pointer; font-size: 0.9rem; color: #212529; transition: background 0.1s; }
.cs-item:hover { background: #f0f4f8; }
.cs-item.selected { background: #e8f0fe; color: #1a3a5c; font-weight: 500; }
.cs-item.no-data { color: #6c757d; font-style: italic; cursor: default; text-align: center; padding: 0.9rem 0.85rem; }
.cs-item.no-data:hover { background: transparent; }
.cs-footer { border-top: 1px solid #e9ecef; padding: 0.3rem 0.4rem; }
.cs-add-btn {
    display: flex; align-items: center; gap: 0.4rem; width: 100%;
    background: none; border: none; padding: 0.45rem 0.5rem;
    font-size: 0.875rem; font-weight: 600; color: #1a3a5c;
    cursor: pointer; border-radius: 4px; text-align: left;
}
.cs-add-btn:hover { background: #f0f4f8; }
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; }

/* =========================================
   Mobile Responsive — overflow & scaling
   ========================================= */

/* Page titles and entity names: never overflow their containers */
.page-title, h1.page-title { word-break: break-word; overflow-wrap: anywhere; }
.row-title { max-width: 100%; }

/* stat-card: shrink value font on small phones */
@media (max-width: 575.98px) {
    .stat-value { font-size: 1rem; }
    .stat-tile { padding: 0.75rem 0.9rem; }
}

/* kpi-card: on very small screens hide the icon so value has full width */
@media (max-width: 480px) {
    .kpi-card .card-body { gap: 0.5rem !important; padding: 0.6rem 0.75rem !important; }
    .kpi-card .kpi-icon { display: none; }
    .kpi-value { font-size: 0.95rem; }
}

/* Balance-due strip: stack label and value on tiny screens */
.balance-due-strip { flex-wrap: wrap; }
@media (max-width: 480px) {
    .balance-due-strip { flex-direction: column; align-items: flex-start !important; gap: 0.5rem !important; }
    .balance-due-strip .fw-bold { font-size: 1.1rem !important; }
}

/* Tables: ensure horizontal scroll on mobile */
@media (max-width: 767.98px) {
    .table-responsive { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
    .table td, .table th { padding: 0.5rem 0.65rem; font-size: 0.82rem; }
    .card .table > thead > tr > th:first-child,
    .card .table > tbody > tr > td:first-child { padding-left: 0.75rem; }
    .card .table > thead > tr > th:last-child,
    .card .table > tbody > tr > td:last-child { padding-right: 0.75rem; }
}

/* Toolbar: full-width selects on mobile */
@media (max-width: 575.98px) {
    .toolbar { gap: 0.4rem; }
    .toolbar .cs-wrapper, .toolbar .cs-sm { width: 100%; flex: 1 1 100%; }
}

/* Topbar: clip long usernames */
.user-menu-toggle .fw-semibold { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Prevent any page-level horizontal scroll */
.main-area { overflow-x: hidden; }
.content { overflow-x: hidden; }
