/* =====================================================================
   Finance Xicloud — admin theme on top of Bootstrap 5.3
   Mobile first. Colours are tokens so light/dark share one stylesheet.
   ===================================================================== */

:root,
[data-bs-theme="light"] {
    --app-bg: #f4f6fb;
    --app-surface: #ffffff;
    --app-surface-2: #f8fafc;
    --app-border: #e3e8f0;
    --app-text: #1b2333;
    --app-muted: #6b7588;
    --app-primary: #2f6fed;
    --app-primary-soft: #e8efff;
    --app-sidebar: #111a2e;
    --app-sidebar-text: #b9c3d6;
    --app-sidebar-active: #2f6fed;
    --app-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
    --bs-body-font-family: "Prompt", system-ui, -apple-system, "Segoe UI", sans-serif;
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-primary: #2f6fed;
    --bs-primary-rgb: 47, 111, 237;
    --bs-link-color-rgb: 47, 111, 237;
}

[data-bs-theme="dark"] {
    --app-bg: #0d1322;
    --app-surface: #151d30;
    --app-surface-2: #1a2338;
    --app-border: #27324a;
    --app-text: #e4e8f1;
    --app-muted: #97a2b8;
    --app-primary: #6c9cff;
    --app-primary-soft: #1d2b4d;
    --app-sidebar: #080d19;
    --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
}

body {
    background: var(--app-bg);
    color: var(--app-text);
    font-weight: 300;
    -webkit-font-smoothing: antialiased;
}

strong, b, .fw-semibold, h1, h2, h3, h4, h5, .h1, .h2, .h3, .h4, .h5 { font-weight: 500; }

.min-w-0 { min-width: 0; }
.text-muted, .form-text { color: var(--app-muted) !important; }
.skip-link { position: absolute; z-index: 2000; top: 8px; left: 8px; background: var(--app-surface); padding: 8px 12px; border-radius: 8px; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; display: flex; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 16px; flex: 1; }

.app-sidebar {
    --bs-offcanvas-width: 264px;
    --bs-offcanvas-bg: var(--app-sidebar);
    background: var(--app-sidebar);
    color: var(--app-sidebar-text);
    display: flex;
    flex-direction: column;
}

@media (min-width: 992px) {
    .app-sidebar { width: 248px; flex: 0 0 248px; position: sticky; top: 0; height: 100vh; background: var(--app-sidebar) !important; }
    .app-content { padding: 24px 28px 40px; }
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    background: linear-gradient(135deg, #2f6fed, #7c5cff); color: #fff; font-weight: 600;
}
.brand-title { color: #fff; font-weight: 500; line-height: 1.2; }
.brand-subtitle { font-size: .75rem; opacity: .7; }

.sidebar-nav { display: grid; align-content: start; gap: 2px; padding: 8px 12px; overflow-y: auto; flex: 1; }
.sidebar-nav a, .sidebar-logout {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--app-sidebar-text); text-decoration: none; font-size: .95rem; transition: background .15s, color .15s;
}
.sidebar-nav a i, .sidebar-logout i { font-size: 1.1rem; width: 20px; text-align: center; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav a.active { background: var(--app-sidebar-active); color: #fff; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-logout { width: 100%; background: none; border: 0; }
.sidebar-logout:hover { background: rgba(239, 68, 68, .15); color: #fecaca; }

.app-topbar {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    background: color-mix(in srgb, var(--app-bg) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--app-border);
}
@media (min-width: 992px) { .app-topbar { padding: 14px 28px; } }
.topbar-eyebrow { font-size: .75rem; color: var(--app-muted); }
.topbar-title { font-size: 1.15rem; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip {
    align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
    background: var(--app-surface); border: 1px solid var(--app-border); max-width: 260px; font-size: .9rem;
}
.user-chip small { color: var(--app-muted); white-space: nowrap; }

.btn-icon {
    width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; border-radius: 10px;
    background: var(--app-surface); border: 1px solid var(--app-border); color: var(--app-text);
}
.btn-icon:hover { background: var(--app-surface-2); }

/* ---------- Surfaces ---------- */
.panel {
    background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 14px; box-shadow: var(--app-shadow);
}
.panel-body { padding: 16px; }
@media (min-width: 768px) { .panel-body { padding: 20px; } }
.panel-header {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
    padding: 14px 16px; border-bottom: 1px solid var(--app-border);
}
@media (min-width: 768px) { .panel-header { padding: 16px 20px; } }
.panel-title { font-size: 1rem; margin: 0; display: flex; align-items: center; gap: 8px; }
.panel-title i { color: var(--app-primary); }

.stat {
    background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 14px; padding: 14px 16px;
    height: 100%; box-shadow: var(--app-shadow);
}
.stat-label { color: var(--app-muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 1.35rem; font-weight: 500; margin-top: 4px; line-height: 1.25; word-break: break-word; }
.stat-hint { font-size: .8rem; margin-top: 2px; }

/* Filter chips (contract list) */
.chip-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; padding: 7px 14px; border-radius: 999px;
    background: var(--app-surface); border: 1px solid var(--app-border); color: var(--app-text); text-decoration: none; font-size: .9rem;
}
.chip .count { background: var(--app-surface-2); border-radius: 999px; padding: 0 8px; font-size: .8rem; color: var(--app-muted); }
.chip:hover { border-color: var(--app-primary); color: var(--app-primary); }
.chip.active { background: var(--app-primary); border-color: var(--app-primary); color: #fff; }
.chip.active .count { background: rgba(255, 255, 255, .2); color: #fff; }

/* Contract cards (mobile list) */
.contract-card {
    display: block; text-decoration: none; color: inherit; background: var(--app-surface);
    border: 1px solid var(--app-border); border-left: 4px solid var(--app-border); border-radius: 12px; padding: 12px 14px;
    transition: border-color .15s, transform .15s;
}
.contract-card:hover { border-color: var(--app-primary); color: inherit; }
.contract-card[data-status="overdue"], .contract-card[data-status="bad_debt"] { border-left-color: var(--bs-danger); }
.contract-card[data-status="due_today"], .contract-card[data-status="followup"] { border-left-color: var(--bs-warning); }
.contract-card[data-status="due_soon"] { border-left-color: var(--bs-info); }
.contract-card[data-status="active"] { border-left-color: var(--app-primary); }
.contract-card[data-status="completed"] { border-left-color: var(--bs-success); }

/* Tables */
.table { --bs-table-bg: transparent; --bs-table-color: var(--app-text); margin-bottom: 0; }
.table > thead th {
    font-weight: 400; font-size: .82rem; color: var(--app-muted); background: var(--app-surface-2);
    border-bottom-width: 1px; white-space: nowrap;
}
.table > :not(caption) > * > * { padding: .7rem .8rem; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--app-surface-2); }
.row-link { cursor: pointer; }

.status-badge { font-weight: 400; padding: .4em .75em; }

/* Definition list */
.kv { display: grid; gap: 0; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--app-border); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { font-weight: 300; color: var(--app-muted); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.kv dd { margin: 0; text-align: right; font-weight: 400; word-break: break-word; }

/* Progress */
.progress { height: 8px; background: var(--app-surface-2); }

/* Forms */
.form-control, .form-select { border-radius: 10px; border-color: var(--app-border); background-color: var(--app-surface); }
.form-control:focus, .form-select:focus { border-color: var(--app-primary); box-shadow: 0 0 0 .2rem rgba(47, 111, 237, .15); }
.form-label { font-size: .9rem; margin-bottom: .35rem; }
.btn { border-radius: 10px; font-weight: 400; }
.btn-primary { --bs-btn-bg: #2f6fed; --bs-btn-border-color: #2f6fed; --bs-btn-hover-bg: #245bd0; --bs-btn-hover-border-color: #245bd0; }

.nav-tabs-app { gap: 4px; border-bottom: 1px solid var(--app-border); flex-wrap: nowrap; overflow-x: auto; }
.nav-tabs-app .nav-link {
    border: 0; border-bottom: 2px solid transparent; color: var(--app-muted); white-space: nowrap; padding: 10px 14px; border-radius: 0;
}
.nav-tabs-app .nav-link.active { color: var(--app-primary); border-bottom-color: var(--app-primary); background: none; }

.gallery-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--app-border); }

.modal-content { border-radius: 16px; border: 1px solid var(--app-border); background: var(--app-surface); }

.empty-state { text-align: center; color: var(--app-muted); padding: 40px 16px; }
.empty-state i { font-size: 2rem; display: block; margin-bottom: 8px; opacity: .6; }

/* Loading state for submit buttons */
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::before {
    content: ""; display: inline-block; width: 1em; height: 1em; margin-right: .5em; vertical-align: -.15em;
    border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
    .app-sidebar, .app-topbar, .no-print { display: none !important; }
    .app-content { padding: 0; }
}

/* ---------- Small screens ---------- */
@media (max-width: 575.98px) {
    .stat { padding: 12px; }
    .stat-value { font-size: 1.1rem; }
    .stat-hint { font-size: .75rem; }
    .table { font-size: .875rem; }
    .table > :not(caption) > * > * { padding: .55rem .6rem; white-space: nowrap; }
    .topbar-title { font-size: 1rem; }
}
@media (max-width: 575.98px) {
    .detail-actions > .btn { flex: 1 1 auto; }
}

/* ---------- Dashboard bar chart (no JS library) ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 220px; padding-top: 18px; }
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar-stack { width: 100%; max-width: 38px; min-height: 2px; display: flex; flex-direction: column; border-radius: 6px 6px 2px 2px; overflow: hidden; background: var(--app-surface-2); }
.bar-stack > div { min-height: 2px; }
.bar-value { font-size: .68rem; color: var(--app-muted); margin-bottom: 2px; white-space: nowrap; }
.bar-label { font-size: .72rem; color: var(--app-muted); margin-top: 6px; white-space: nowrap; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.list-group-flush > .list-group-item { background: transparent; border-color: var(--app-border); color: var(--app-text); }
@media (max-width: 575.98px) {
    .bar-chart { gap: 3px; height: 180px; }
    .bar-value { display: none; }
    .display-6 { font-size: 1.6rem; }
}
