/* Modern UI layer — loaded after app.css, so it restyles every page without touching their markup. */
:root {
  --app-primary: #4361ee;
  --app-primary-rgb: 67, 97, 238;
  --app-primary-hover: #3651d4;
  --app-accent: #7c3aed;
  --app-grad: linear-gradient(135deg, #4361ee 0%, #7c3aed 100%);
  --app-bg: #f4f6fb;
  --app-surface: #ffffff;
  --app-border: #e8ecf4;
  --app-radius: 14px;
  --app-sidebar-bg: #0c1224;
  --app-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .05);
  --app-shadow-lg: 0 10px 40px rgba(16, 24, 40, .14);
  --ok: #059669; --ok-bg: rgba(16, 185, 129, .12);
  --warn: #b45309; --warn-bg: rgba(245, 158, 11, .16);
  --bad: #dc2626; --bad-bg: rgba(239, 68, 68, .12);
  --info: #2563eb; --info-bg: rgba(59, 130, 246, .12);
  --neutral: #475569; --neutral-bg: rgba(100, 116, 139, .14);
  --bs-body-font-family: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --bs-border-radius: 10px;
}
[data-bs-theme="dark"] {
  --app-bg: #080d1c; --app-surface: #111a30; --app-border: #1e2a47; --app-sidebar-bg: #060a16;
  --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa; --neutral: #cbd5e1;
}
html { scroll-behavior: smooth; }
body.app {
  background:
    radial-gradient(900px 420px at 85% -80px, rgba(124, 58, 237, .08), transparent 60%),
    radial-gradient(700px 380px at 10% -60px, rgba(67, 97, 238, .08), transparent 60%),
    var(--app-bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sidebar ---------- */
.app-sidebar { background: linear-gradient(180deg, #0e1530 0%, var(--app-sidebar-bg) 55%); border-right: 1px solid rgba(255, 255, 255, .04); }
.app-brand { padding: 1.15rem 1.15rem 1rem; }
.app-brand .logo { background: var(--app-grad); border-radius: 10px; box-shadow: 0 6px 18px rgba(67, 97, 238, .45); }
.app-nav .section { cursor: pointer; display: flex; align-items: center; justify-content: space-between; user-select: none; transition: color .15s; }
.app-nav .section:hover { color: #cbd5e1; }
.app-nav .section::after { content: "\F282"; font-family: "bootstrap-icons"; font-size: .6rem; transition: transform .2s; opacity: .6; }
.app-nav .section.collapsed::after { transform: rotate(-90deg); }
.app-nav a { border-radius: 10px; position: relative; transition: background .15s, color .15s, transform .15s; }
.app-nav a:hover { transform: translateX(2px); }
.app-nav a.active { background: linear-gradient(90deg, rgba(67, 97, 238, .35), rgba(124, 58, 237, .12)); box-shadow: none; color: #fff; }
.app-nav a.active::before { content: ""; position: absolute; left: -.6rem; top: 20%; bottom: 20%; width: 3px; border-radius: 3px; background: #8ea2ff; box-shadow: 0 0 12px #6d83ff; }
.app-nav a.active i { color: #a5b4ff; opacity: 1; }
.app-nav a.hidden-group { display: none; }

/* ---------- Top bar (glass) ---------- */
.app-topbar { background: color-mix(in srgb, var(--app-surface) 78%, transparent); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); border-bottom: 1px solid var(--app-border); }
.app-search input { background: color-mix(in srgb, var(--app-bg) 80%, var(--app-surface)); border-radius: 12px; height: 40px; transition: box-shadow .2s, background .2s; cursor: pointer; }
.app-search input:focus { background: var(--app-surface); }
.app-topbar .icon-btn { border-radius: 12px; transition: transform .15s, border-color .15s, color .15s; }
.app-topbar .icon-btn:hover { transform: translateY(-1px); }
.app-avatar { background: var(--app-grad); color: #fff; box-shadow: 0 4px 12px rgba(67, 97, 238, .35); }
.btn-primary { background-image: var(--app-grad); border: 0; box-shadow: 0 4px 12px rgba(67, 97, 238, .28); transition: transform .15s, box-shadow .15s, filter .15s; position: relative; overflow: hidden; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(67, 97, 238, .38); filter: brightness(1.06); }
.btn-primary:active { transform: translateY(0); }

/* ---------- Page entrance + progress bar ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: -200% 0; } }
.app-content > * { animation: fadeUp .45s cubic-bezier(.2, .7, .2, 1) both; }
.app-content > *:nth-child(2) { animation-delay: .05s; } .app-content > *:nth-child(3) { animation-delay: .1s; }
.app-content > *:nth-child(4) { animation-delay: .15s; } .app-content > *:nth-child(5) { animation-delay: .2s; }
.app-content > *:nth-child(n+6) { animation-delay: .25s; }
#navProgress { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 2000; background: var(--app-grad); box-shadow: 0 0 10px rgba(124, 58, 237, .7); transition: width .4s ease, opacity .3s; opacity: 0; }
#navProgress.on { opacity: 1; width: 78%; transition: width 6s cubic-bezier(.1, .8, .2, 1); }
#navProgress.done { width: 100%; opacity: 0; transition: width .2s, opacity .4s .2s; }
@media (prefers-reduced-motion: reduce) { .app-content > *, .kpi, .card { animation: none !important; transition: none !important; } }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; margin: 0; }
.page-head p { margin: .15rem 0 0; color: var(--app-muted); font-size: .9rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.app-content > .d-flex:first-child > h5.mb-0, .app-content > h5.mb-3 { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; }
.app-content > .d-flex.justify-content-between:first-child { margin-bottom: 1.1rem !important; }

/* ---------- Cards, tables ---------- */
.card { border-radius: var(--app-radius); box-shadow: var(--app-shadow); border-color: var(--app-border); transition: box-shadow .2s, transform .2s, border-color .2s; }
.card.hoverable:hover, .report-tile:hover, .kpi:hover { transform: translateY(-3px); box-shadow: var(--app-shadow-lg); }
.card > .table:first-child, .card > .table-responsive:first-child { border-radius: var(--app-radius); overflow: hidden; }
.table > thead th { background: color-mix(in srgb, var(--app-bg) 55%, var(--app-surface)); position: sticky; top: 0; z-index: 2; }
.table > tbody > tr { transition: background .12s; }
.table > tbody > tr:hover > * { background: rgba(var(--app-primary-rgb), .05); }
.table td, .table th { padding-top: .8rem; padding-bottom: .8rem; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--app-primary); }
.table th.sortable::after { content: "\F127"; font-family: "bootstrap-icons"; font-size: .62rem; margin-left: .35rem; opacity: 0; }
.table th.sortable:hover::after { opacity: .5; }
.table th.sort-asc::after { content: "\F235"; opacity: 1; color: var(--app-primary); }
.table th.sort-desc::after { content: "\F229"; opacity: 1; color: var(--app-primary); }
.table td a:not(.btn) { font-weight: 600; text-decoration: none; }
.table td a:not(.btn):hover { text-decoration: underline; }
.table .btn-sm { --bs-btn-padding-y: .22rem; --bs-btn-padding-x: .55rem; font-size: .78rem; border-radius: 8px; }
.table .btn-outline-dark, .table .btn-outline-secondary { --bs-btn-border-color: var(--app-border); --bs-btn-color: var(--app-text); --bs-btn-hover-bg: rgba(var(--app-primary-rgb), .1); --bs-btn-hover-color: var(--app-primary); --bs-btn-hover-border-color: rgba(var(--app-primary-rgb), .4); background: var(--app-surface); }
.table .btn-outline-danger { --bs-btn-border-color: var(--app-border); }
.table .btn i { margin-right: .25rem; }
.table-empty { text-align: center; color: var(--app-muted); padding: 2.5rem 1rem !important; }

/* ---------- Status chips ---------- */
.badge { border-radius: 999px; padding: .38em .75em; font-weight: 650; letter-spacing: .01em; font-size: .72rem; display: inline-flex; align-items: center; gap: .35em; }
.badge.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.st-success { background: var(--ok-bg) !important; color: var(--ok) !important; }
.badge.st-warn { background: var(--warn-bg) !important; color: var(--warn) !important; }
.badge.st-danger { background: var(--bad-bg) !important; color: var(--bad) !important; }
.badge.st-info { background: var(--info-bg) !important; color: var(--info) !important; }
.badge.st-neutral { background: var(--neutral-bg) !important; color: var(--neutral) !important; }

/* ---------- List toolbar (added by app.js) ---------- */
.list-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.list-toolbar .lt-search { position: relative; flex: 0 1 300px; min-width: 190px; }
.list-toolbar .lt-search i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--app-muted); font-size: .9rem; }
.list-toolbar .lt-search input { padding-left: 2.1rem; height: 38px; border-radius: 10px; background: var(--app-surface); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { border: 1px solid var(--app-border); background: var(--app-surface); color: var(--app-muted); border-radius: 999px; padding: .28rem .8rem; font-size: .78rem; font-weight: 650; cursor: pointer; transition: all .15s; }
.chip:hover { border-color: rgba(var(--app-primary-rgb), .5); color: var(--app-primary); }
.chip.on { background: var(--app-grad); border-color: transparent; color: #fff; box-shadow: 0 4px 12px rgba(67, 97, 238, .3); }
.chip small { opacity: .75; margin-left: .3rem; font-weight: 600; }
.lt-meta { margin-left: auto; color: var(--app-muted); font-size: .8rem; display: flex; align-items: center; gap: .75rem; }
.lt-meta button { border: 1px solid var(--app-border); background: var(--app-surface); color: var(--app-text); border-radius: 9px; padding: .3rem .65rem; font-size: .78rem; font-weight: 600; }
.lt-meta button:hover { border-color: var(--app-primary); color: var(--app-primary); }

/* ---------- KPI / stat cards ---------- */
.kpi-grid { gap: 1rem; margin-bottom: 1.25rem; }
.kpi { position: relative; overflow: hidden; border-radius: var(--app-radius); }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--kpi-c, var(--app-grad)); }
.kpi .value { font-size: 1.55rem; letter-spacing: -.02em; }
.kpi .ico { position: absolute; right: 1rem; top: 1rem; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 1.1rem; background: var(--kpi-bg, rgba(var(--app-primary-rgb), .1)); color: var(--kpi-fg, var(--app-primary)); }
.kpi.k-green { --kpi-c: #10b981; --kpi-bg: var(--ok-bg); --kpi-fg: var(--ok); }
.kpi.k-amber { --kpi-c: #f59e0b; --kpi-bg: var(--warn-bg); --kpi-fg: var(--warn); }
.kpi.k-red { --kpi-c: #ef4444; --kpi-bg: var(--bad-bg); --kpi-fg: var(--bad); }
.kpi.k-blue { --kpi-c: #3b82f6; --kpi-bg: var(--info-bg); --kpi-fg: var(--info); }
.kpi.k-violet { --kpi-c: #8b5cf6; --kpi-bg: rgba(139, 92, 246, .13); --kpi-fg: #7c3aed; }

/* ---------- Forms ---------- */
.form-control, .form-select { border-radius: 10px; min-height: 40px; background-color: color-mix(in srgb, var(--app-bg) 35%, var(--app-surface)); transition: box-shadow .15s, border-color .15s, background .15s; }
.form-control:focus, .form-select:focus { background: var(--app-surface); }
.form-label { text-transform: none; letter-spacing: 0; }
.card-body h6, .card-header h6 { font-weight: 700; }
.input-group-text { border-radius: 10px; background: color-mix(in srgb, var(--app-bg) 50%, var(--app-surface)); border-color: var(--app-border); }
.btn { transition: transform .12s, box-shadow .15s, background .15s, border-color .15s; }
.btn:active { transform: scale(.97); }
.btn-outline-secondary, .btn-outline-dark { --bs-btn-border-color: var(--app-border); }
.ripple { position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .45); transform: scale(0); animation: rip .6s ease-out; pointer-events: none; }
@keyframes rip { to { transform: scale(4); opacity: 0; } }
.empty-state { padding: 3rem 1rem; }
.empty-state i { font-size: 2.6rem; background: var(--app-grad); -webkit-background-clip: text; background-clip: text; color: transparent; opacity: 1; }

/* ---------- Toasts (flash messages) ---------- */
#toasts { position: fixed; right: 1.25rem; top: 4.6rem; z-index: 2100; display: flex; flex-direction: column; gap: .6rem; width: min(380px, calc(100vw - 2rem)); }
.toast-x { display: flex; gap: .7rem; align-items: flex-start; padding: .85rem 1rem; border-radius: 14px; background: var(--app-surface); border: 1px solid var(--app-border); box-shadow: var(--app-shadow-lg); animation: pop .3s cubic-bezier(.2, .8, .2, 1) both; position: relative; overflow: hidden; }
.toast-x i.t { font-size: 1.25rem; margin-top: .05rem; }
.toast-x.success i.t { color: var(--ok); } .toast-x.danger i.t { color: var(--bad); } .toast-x.warning i.t { color: var(--warn); } .toast-x.info i.t { color: var(--info); }
.toast-x .m { flex: 1; font-size: .875rem; }
.toast-x button { border: 0; background: none; color: var(--app-muted); font-size: 1rem; line-height: 1; }
.toast-x::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: currentColor; opacity: .55; transform-origin: left; animation: life 6s linear forwards; }
.toast-x.success::after { color: var(--ok); } .toast-x.danger::after { color: var(--bad); animation-duration: 12s; } .toast-x.warning::after { color: var(--warn); } .toast-x.info::after { color: var(--info); }
@keyframes life { to { transform: scaleX(0); } }
.toast-x.out { opacity: 0; transform: translateX(20px); transition: all .25s; }

/* ---------- Command palette (Ctrl+K) ---------- */
#cmdk { position: fixed; inset: 0; z-index: 2200; display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; background: rgba(8, 13, 28, .5); backdrop-filter: blur(6px); }
#cmdk.open { display: flex; animation: fadeUp .15s ease both; }
#cmdk .box { width: min(640px, 92vw); background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); overflow: hidden; animation: pop .2s cubic-bezier(.2, .8, .2, 1) both; }
#cmdk .q { display: flex; align-items: center; gap: .7rem; padding: .95rem 1.1rem; border-bottom: 1px solid var(--app-border); }
#cmdk .q i { color: var(--app-muted); font-size: 1.1rem; }
#cmdk .q input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--app-text); font-size: 1.05rem; }
#cmdk .list { max-height: 52vh; overflow-y: auto; padding: .4rem; }
#cmdk .grp { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--app-muted); font-weight: 700; padding: .6rem .7rem .3rem; }
#cmdk .it { display: flex; align-items: center; gap: .75rem; padding: .55rem .7rem; border-radius: 10px; color: var(--app-text); text-decoration: none; cursor: pointer; }
#cmdk .it i { width: 1.4rem; text-align: center; color: var(--app-muted); }
#cmdk .it.sel { background: rgba(var(--app-primary-rgb), .1); color: var(--app-primary); }
#cmdk .it.sel i { color: var(--app-primary); }
#cmdk .it small { margin-left: auto; color: var(--app-muted); }
#cmdk .foot { display: flex; gap: 1rem; padding: .55rem 1rem; border-top: 1px solid var(--app-border); font-size: .74rem; color: var(--app-muted); }
#cmdk kbd { background: var(--app-bg); border: 1px solid var(--app-border); color: var(--app-muted); font-size: .68rem; }

/* ---------- Dashboard extras ---------- */
.chart-card .card-header { padding: 1rem 1.2rem; }
.seg { border-radius: 12px; box-shadow: var(--app-shadow); }
.seg a { border-radius: 9px; transition: all .15s; }
.seg a.active { background: var(--app-grad); color: #fff; box-shadow: 0 4px 12px rgba(67, 97, 238, .3); }
.list-group-item { transition: background .12s; }
.list-group-item:hover { background: rgba(var(--app-primary-rgb), .04); }
.dropdown-menu { border-radius: 14px; padding: .4rem; animation: pop .15s ease both; }
.dropdown-item { border-radius: 9px; }
.dropdown-item:hover { background: rgba(var(--app-primary-rgb), .09); }
.alert { border-radius: 12px; border: 0; }
.nav-tabs .nav-link.active, .nav-pills .nav-link.active { background-image: var(--app-grad); }

/* ---------- Auth screens ---------- */
.auth-split { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-hero { position: relative; overflow: hidden; color: #fff; padding: 3rem 3.5rem; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(140deg, #0b1230 0%, #1b2a6b 55%, #4b2a9a 100%); }
.auth-hero::before, .auth-hero::after { content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; animation: float 14s ease-in-out infinite; }
.auth-hero::before { width: 420px; height: 420px; background: #4361ee; top: -120px; right: -100px; }
.auth-hero::after { width: 360px; height: 360px; background: #a855f7; bottom: -140px; left: -80px; animation-delay: -6s; }
@keyframes float { 50% { transform: translate(30px, -26px) scale(1.08); } }
.auth-hero > * { position: relative; z-index: 1; }
.auth-hero .brand { display: flex; align-items: center; gap: .7rem; font-weight: 750; font-size: 1.15rem; }
.auth-hero .brand .mark { color: #fff; width: 38px; height: 38px; border-radius: 11px; background: rgba(255, 255, 255, .16); backdrop-filter: blur(6px); display: grid; place-items: center; font-size: .9rem; border: 1px solid rgba(255, 255, 255, .25); }
.auth-hero h2 { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; max-width: 460px; }
.auth-hero .lead { color: rgba(255, 255, 255, .72); max-width: 430px; margin-top: .9rem; }
.auth-points { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: .8rem; }
.auth-points li { display: flex; align-items: center; gap: .75rem; color: rgba(255, 255, 255, .88); font-size: .95rem; animation: fadeUp .6s both; }
.auth-points li:nth-child(2) { animation-delay: .12s; } .auth-points li:nth-child(3) { animation-delay: .24s; } .auth-points li:nth-child(4) { animation-delay: .36s; }
.auth-points i { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .18); }
.auth-hero .fine { font-size: .78rem; color: rgba(255, 255, 255, .5); }
.auth-pane { display: grid; place-items: center; padding: 2rem 1.25rem; background: var(--app-bg); }
.auth-card { width: 100%; max-width: 410px; animation: fadeUp .5s both; }
.auth-card .card { padding: 1.6rem !important; box-shadow: var(--app-shadow-lg); }
.auth-card h5 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.auth-brand-sm { display: none; }
@media (max-width: 900px) { .auth-split { grid-template-columns: 1fr; } .auth-hero { display: none; } .auth-brand-sm { display: flex; align-items: center; gap: .6rem; font-weight: 750; margin-bottom: 1.2rem; } }

/* ---------- polish ---------- */
.report-tile { border-radius: var(--app-radius); }
.report-tile i { width: 40px !important; height: 40px; display: grid; place-items: center; border-radius: 12px; font-size: 1.15rem !important; background: rgba(var(--app-primary-rgb), .1) !important; color: var(--app-primary) !important; flex: none; transition: transform .2s; }
.report-tile:hover i { transform: scale(1.1) rotate(-4deg); background: var(--app-grad) !important; color: #fff !important; }
.form-select:not(.form-select-sm) { min-width: 7.5rem; }
.btn-success { background-image: linear-gradient(135deg, #10b981, #059669); border: 0; box-shadow: 0 4px 12px rgba(16, 185, 129, .28); }
.btn-success:hover { filter: brightness(1.07); transform: translateY(-1px); }
@media (max-width: 767.98px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: .65rem; }
  .kpi { padding: .85rem .9rem; } .kpi .value { font-size: 1.15rem; } .kpi .ico { width: 30px; height: 30px; right: .6rem; top: .6rem; font-size: .9rem; }
  .card:has(> table.table) { overflow-x: auto; } .card > table.table { min-width: 640px; }
  .app-content > .d-flex:first-child > h5.mb-0, .app-content > h5.mb-3, .page-head h1 { font-size: 1.35rem; }
  .list-toolbar .lt-search { flex: 1 1 100%; } .lt-meta { margin-left: 0; width: 100%; justify-content: space-between; }
  #toasts { top: 4.2rem; right: .75rem; }
}
