:root {
  --bg: #08050f;
  --bg-2: #0d0717;
  --panel: rgba(21, 14, 34, .88);
  --panel-2: rgba(27, 18, 45, .92);
  --panel-3: #171024;
  --border: rgba(185, 130, 255, .13);
  --border-strong: rgba(185, 130, 255, .28);
  --text: #f5f1ff;
  --muted: #9d94af;
  --purple: #9b5cff;
  --purple-2: #6d35d5;
  --purple-soft: rgba(155, 92, 255, .14);
  --pink: #d75cff;
  --blue: #6f8cff;
  --orange: #ff9b59;
  --green: #4ad7a7;
  --danger: #ff647c;
  --shadow: 0 24px 80px rgba(0, 0, 0, .34);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(118, 54, 214, .17), transparent 34%),
    radial-gradient(circle at 95% 20%, rgba(215, 92, 255, .10), transparent 28%),
    linear-gradient(180deg, #0a0612 0%, #08050f 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
body.auth-locked { overflow: hidden; }
body.auth-locked .app-shell { display: none; }

.ambient { position: fixed; border-radius: 50%; filter: blur(100px); pointer-events: none; opacity: .18; z-index: 0; }
.ambient-one { width: 360px; height: 360px; background: #8246ff; top: -120px; right: 15%; }
.ambient-two { width: 300px; height: 300px; background: #cf54ff; bottom: 5%; left: -140px; }

.auth-screen { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 50% 12%, rgba(155,92,255,.18), transparent 38%), rgba(8,5,15,.74); backdrop-filter: blur(16px); }
body:not(.auth-locked) .auth-screen { display: none; }
.auth-card { width: min(420px, 100%); padding: 34px; border-radius: 30px; background: linear-gradient(155deg, rgba(27,18,45,.96), rgba(13,7,23,.96)); border: 1px solid var(--border-strong); box-shadow: var(--shadow); text-align: center; }
.auth-mark { width: 62px; height: 62px; margin: 0 auto 18px; border-radius: 20px; display: grid; place-items: center; font-size: 26px; font-weight: 900; background: linear-gradient(135deg, var(--purple), #5e2fc4); box-shadow: 0 18px 44px rgba(155,92,255,.34); }
.auth-card h1 { margin: 8px 0 8px; font-size: clamp(28px, 8vw, 40px); letter-spacing: -.045em; }
.auth-hint { margin: 0 0 22px; color: var(--muted); }
.pin-input { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: .45em; padding-left: calc(16px + .45em); }
.auth-submit { width: 100%; justify-content: center; margin-top: 12px; }
.auth-error { margin: 14px 0 0; color: #ff9aac; font-weight: 700; }

.app-shell { position: relative; z-index: 1; display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: rgba(9, 6, 15, .88); border-right: 1px solid var(--border); backdrop-filter: blur(18px); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-weight: 900; background: linear-gradient(135deg, var(--purple), #5e2fc4); box-shadow: 0 10px 30px rgba(155,92,255,.3); }
.brand-title { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.nav-list { display: grid; gap: 7px; }
.nav-item { border: 0; color: #b7adca; background: transparent; padding: 13px 14px; border-radius: 14px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; text-align: left; transition: .2s ease; }
.nav-item span { font-size: 18px; color: #8d82a3; }
.nav-item b { font-weight: 650; }
.nav-item:hover { background: rgba(155,92,255,.07); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(155,92,255,.18), rgba(155,92,255,.07)); color: #fff; box-shadow: inset 3px 0 0 var(--purple); }
.nav-item.active span { color: #c7a6ff; }
.nav-badge { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 20px; display: grid; place-items: center; background: rgba(255,155,89,.14); color: #ffb77f; font-size: 11px; font-style: normal; }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--border); }
.mini-profile { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--purple-soft); color: #d9c3ff; border: 1px solid var(--border-strong); }
.mini-profile strong { display: block; font-size: 14px; }
.mini-profile small { display: block; margin-top: 2px; color: var(--muted); }

.main { min-width: 0; padding: 28px 34px 50px; max-width: 1700px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(26px, 3vw, 36px); letter-spacing: -.04em; }
.eyebrow, .panel-kicker, .hero-kicker { margin: 0; text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; color: #a28bbf; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.date-pill, .soft-pill { border: 1px solid var(--border); background: rgba(255,255,255,.025); color: #b7adca; border-radius: 13px; padding: 10px 13px; font-size: 13px; }
.menu-btn { display: none; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); color: white; background: var(--panel-3); }

.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-card { position: relative; overflow: hidden; min-height: 220px; border: 1px solid rgba(183,131,255,.23); border-radius: 28px; padding: 34px; background: linear-gradient(125deg, rgba(94,39,169,.92), rgba(48,24,81,.96) 62%, rgba(24,15,39,.96)); box-shadow: var(--shadow); display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; }
.hero-card:after { content: ""; position: absolute; width: 380px; height: 380px; border-radius: 50%; right: -90px; top: -180px; background: radial-gradient(circle, rgba(230,184,255,.27), transparent 66%); }
.hero-card h2 { margin: 8px 0 10px; font-size: clamp(44px, 7vw, 72px); letter-spacing: -.055em; }
.hero-card p { margin: 0; color: #d0c4e4; max-width: 620px; }
.hero-side { position: relative; z-index: 1; min-width: 210px; padding: 18px 20px; border-radius: 18px; background: rgba(9,6,15,.25); border: 1px solid rgba(255,255,255,.10); backdrop-filter: blur(10px); }
.hero-side span, .hero-side small { color: #cbbcdf; display: block; }
.hero-side strong { display: block; font-size: 24px; margin: 6px 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.kpi-card { padding: 20px; display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 15px 40px rgba(0,0,0,.16); }
.kpi-card.warning { border-color: rgba(255,155,89,.18); }
.kpi-icon { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 15px; display: grid; place-items: center; font-size: 20px; font-weight: 800; border: 1px solid transparent; }
.kpi-icon.purple { background: rgba(155,92,255,.13); color: #caa9ff; border-color: rgba(155,92,255,.18); }
.kpi-icon.blue { background: rgba(111,140,255,.13); color: #a8b9ff; border-color: rgba(111,140,255,.18); }
.kpi-icon.pink { background: rgba(215,92,255,.13); color: #eda8ff; border-color: rgba(215,92,255,.18); }
.kpi-icon.orange { background: rgba(255,155,89,.12); color: #ffb680; border-color: rgba(255,155,89,.18); }
.kpi-card span { display: block; color: var(--muted); font-size: 12px; }
.kpi-card strong { display: block; margin: 3px 0; font-size: 24px; letter-spacing: -.03em; }
.kpi-card small { color: #776d89; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .7fr); gap: 18px; margin-bottom: 18px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.18); backdrop-filter: blur(14px); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel h3 { margin: 4px 0 0; font-size: 19px; letter-spacing: -.025em; }
.soft-pill { padding: 7px 10px; font-size: 11px; }

.bar-chart { min-height: 260px; display: flex; align-items: stretch; gap: 14px; padding: 20px 4px 2px; border-bottom: 1px solid var(--border); }
.bar-chart.large { min-height: 360px; gap: 10px; }
.bar-item { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; position: relative; }
.bar-value { color: #cdbbe5; font-size: 11px; opacity: 0; transform: translateY(4px); transition: .18s; white-space: nowrap; }
.bar-item:hover .bar-value { opacity: 1; transform: none; }
.bar { width: min(42px, 65%); min-height: 5px; border-radius: 10px 10px 3px 3px; background: linear-gradient(180deg, #b57bff, #733cd9); box-shadow: 0 10px 30px rgba(155,92,255,.2); }
.bar-label { color: #776e87; font-size: 11px; white-space: nowrap; }

.distribution { display: grid; gap: 14px; }
.dist-row { display: grid; gap: 7px; }
.dist-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.dist-top span { color: #d9d0e8; }
.dist-top b { color: #9d93ad; font-weight: 650; }
.progress { height: 8px; background: #100b1a; border-radius: 20px; overflow: hidden; border: 1px solid rgba(255,255,255,.03); }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7b42df, #b36cff); }

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { padding: 11px 12px; color: #6f667e; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; text-align: left; font-weight: 800; border-bottom: 1px solid var(--border); }
td { padding: 14px 12px; border-bottom: 1px solid rgba(185,130,255,.075); color: #d9d0e5; font-size: 13px; }
tbody tr:hover { background: rgba(155,92,255,.035); }
.amount { color: white; font-weight: 800; }
.status { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 9px; border-radius: 20px; font-size: 11px; font-weight: 750; }
.status.done { background: rgba(74,215,167,.11); color: #72e3bd; border: 1px solid rgba(74,215,167,.16); }
.status.owed { background: rgba(255,155,89,.11); color: #ffb57e; border: 1px solid rgba(255,155,89,.16); }
.text-btn { background: none; border: 0; color: #b990ff; font-weight: 700; padding: 8px; }
.text-btn:hover { color: white; }
.empty-state { padding: 42px 20px; text-align: center; color: #7e748e; }

.ghost-btn, .primary-btn, .danger-btn { min-height: 42px; border-radius: 13px; padding: 0 15px; font-weight: 750; transition: .18s ease; }
.ghost-btn { color: #d4c8e7; background: rgba(255,255,255,.035); border: 1px solid var(--border); }
.ghost-btn:hover { border-color: var(--border-strong); background: rgba(155,92,255,.08); }
.primary-btn { color: white; border: 1px solid rgba(255,255,255,.08); background: linear-gradient(135deg, #9b5cff, #6932cd); box-shadow: 0 10px 30px rgba(117,55,218,.22); }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(117,55,218,.32); }
.primary-btn.small { min-height: 38px; font-size: 12px; }
.danger-btn { color: #ffd9df; border: 1px solid rgba(255,100,124,.2); background: rgba(255,100,124,.10); }
.danger-btn:hover { background: rgba(255,100,124,.16); }

.wrap-head { align-items: flex-start; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.input { width: 100%; min-height: 46px; outline: none; color: #eee8f8; background: #100a1b; border: 1px solid var(--border); border-radius: 13px; padding: 0 13px; transition: .18s; }
.input:focus { border-color: rgba(155,92,255,.56); box-shadow: 0 0 0 3px rgba(155,92,255,.09); }
.input.compact { width: auto; min-width: 150px; min-height: 39px; font-size: 12px; }
select.input { color-scheme: dark; }
.textarea { padding-top: 12px; resize: vertical; }

.form-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .6fr); gap: 18px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin-bottom: 22px; background: #0e0917; border: 1px solid var(--border); border-radius: 14px; }
.segment { min-height: 42px; border: 0; border-radius: 10px; color: #8f849f; background: transparent; font-weight: 750; }
.segment.active { color: white; background: linear-gradient(135deg, rgba(155,92,255,.3), rgba(105,50,205,.22)); box-shadow: inset 0 0 0 1px rgba(180,130,255,.16); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 15px; }
.field { display: grid; gap: 8px; margin-bottom: 15px; }
.field > span { color: #9f95ad; font-size: 12px; font-weight: 700; }
.calc-card { display: grid; grid-template-columns: 1fr auto 1fr auto 1.2fr; align-items: center; gap: 13px; border: 1px solid var(--border); background: linear-gradient(90deg, rgba(155,92,255,.07), rgba(255,255,255,.02)); border-radius: 16px; padding: 17px; margin: 4px 0 20px; }
.calc-card div span { display: block; color: #81768f; font-size: 11px; margin-bottom: 3px; }
.calc-card div strong { font-size: 18px; }
.calc-plus, .calc-equals { color: #655b72; font-weight: 900; }
.calc-total strong { color: #d2b6ff; font-size: 24px !important; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.tips-panel { height: fit-content; }
.formula-box { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.formula-box b { font-size: 13px; }
.formula-box span { color: #b89ce3; font-weight: 750; }
.example-box { margin: 18px 0; padding: 16px; border-radius: 14px; background: var(--purple-soft); color: #b9abc8; line-height: 1.55; }
.example-box strong { color: white; }
.muted { color: var(--muted); line-height: 1.55; }

.owed-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.owed-list { display: grid; gap: 10px; }
.owed-card { display: grid; grid-template-columns: minmax(120px,.65fr) minmax(120px,.75fr) minmax(190px,1.1fr) minmax(140px,.8fr); align-items: center; gap: 16px; padding: 16px; border-radius: 16px; border: 1px solid var(--border); background: rgba(255,255,255,.018); }
.owed-date strong { display: block; }
.owed-date span, .owed-meta span { color: #7d728d; font-size: 11px; }
.owed-meta strong { display: block; margin-top: 3px; font-size: 13px; }
.owed-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; border: 1px solid var(--border); background: rgba(255,255,255,.025); color: #c8badd; }
.icon-btn:hover { background: rgba(155,92,255,.09); }
.icon-btn.danger { color: #ff91a2; border-color: rgba(255,100,124,.14); }

.stats-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(300px,.55fr); gap: 18px; margin-bottom: 18px; }
.summary-line { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.summary-line span { color: #8e849d; }
.summary-line strong { font-size: 16px; }
.ranking { display: grid; gap: 12px; }
.rank-row { display: grid; grid-template-columns: 32px minmax(130px,.6fr) 1fr 80px; align-items: center; gap: 12px; }
.rank-index { width: 28px; height: 28px; border-radius: 8px; background: var(--purple-soft); color: #c5a5ff; display: grid; place-items: center; font-size: 11px; font-weight: 800; }
.rank-bar { height: 8px; border-radius: 30px; background: #100b19; overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#7a43df,#b873ff); }
.rank-count { text-align: right; color: #90849f; font-size: 12px; }

.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 10px; border-radius: 11px; border: 1px solid var(--border); background: rgba(155,92,255,.06); color: #c9bbdc; font-size: 12px; }
.chip button { width: 22px; height: 22px; border-radius: 7px; border: 0; background: rgba(255,100,124,.08); color: #ff8da0; }
.inline-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.danger-panel { border-color: rgba(255,100,124,.12); }

.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); padding: 13px 16px; border-radius: 13px; background: #1c1230; border: 1px solid rgba(185,130,255,.22); box-shadow: 0 18px 50px rgba(0,0,0,.4); color: white; opacity: 0; transform: translateY(16px); pointer-events: none; transition: .22s; }
.toast.show { opacity: 1; transform: none; }
.modal-backdrop { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 20px; background: rgba(4,2,8,.72); backdrop-filter: blur(6px); }
.modal { width: min(430px,100%); padding: 26px; border-radius: 22px; background: #130c20; border: 1px solid var(--border-strong); box-shadow: var(--shadow); text-align: center; }
.modal-icon { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; margin: 0 auto 14px; background: rgba(255,100,124,.1); color: #ff8fa1; font-weight: 900; }
.modal h3 { margin: 0 0 8px; }
.modal p { color: var(--muted); }
.modal-actions { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }


.owed-meta small { display: block; margin-top: 5px; color: #b8a5cd; font-size: 12px; }
.owed-actions { grid-column: 1/-1; display: flex; justify-content: flex-end; gap: 8px; }
.owed-note { grid-column: 1/-1; font-size: 12px; padding-top: 2px; }
@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dashboard-grid, .stats-grid { grid-template-columns: 1fr; }
  .distribution-panel { min-height: auto; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -290px; z-index: 90; width: 270px; transition: .24s ease; box-shadow: 18px 0 60px rgba(0,0,0,.45); }
  .sidebar.open { left: 0; }
  .main { padding: 20px 18px 40px; }
  .menu-btn { display: grid; place-items: center; }
  .topbar { justify-content: flex-start; }
  .top-actions { margin-left: auto; }
  .form-layout, .settings-grid { grid-template-columns: 1fr; }
  .owed-card { grid-template-columns: 1fr 1fr; }
  .owed-actions { justify-content: flex-start; grid-column: 1/-1; }
}

@media (max-width: 650px) {
  .main { padding: 16px 12px 34px; }
  .topbar { align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
  .topbar h1 { font-size: 27px; }
  .top-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .date-pill { display: none; }
  .top-actions .ghost-btn { width: 100%; }
  .hero-card { min-height: auto; padding: 24px; flex-direction: column; align-items: stretch; }
  .hero-card h2 { font-size: 50px; }
  .hero-side { min-width: 0; }
  .kpi-grid, .owed-kpis { grid-template-columns: 1fr; }
  .dashboard-grid { gap: 12px; }
  .panel { padding: 17px; border-radius: 18px; }
  .panel-head { align-items: flex-start; }
  .soft-pill { display: none; }
  .filter-row { width: 100%; justify-content: stretch; }
  .filter-row .input.compact { width: 100%; }
  .wrap-head { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .calc-card { grid-template-columns: 1fr auto 1fr; }
  .calc-equals { display: none; }
  .calc-total { grid-column: 1/-1; padding-top: 12px; border-top: 1px solid var(--border); }
  .owed-card { grid-template-columns: 1fr; }
  .rank-row { grid-template-columns: 30px 1fr 58px; }
  .rank-bar { grid-column: 2/4; }
  .bar-chart { min-height: 220px; gap: 7px; }
  .bar { width: 65%; }
  .bar-label { font-size: 10px; }
}
