/* ============================================================
   Vista XDash — Liquid Glass UI
   ============================================================ */

:root {
  --fs-scale: 1;
  --accent: #e2231a;
  --radius-lg: 1.75rem;
  --radius-md: 1.25rem;
  --radius-sm: 0.9rem;
  --topbar-h: 4.25rem;
  --bottnav-h: 4.6rem;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* ---------- Theme tokens ---------- */
body[data-theme="dark"] {
  --text: #f2f4ff;
  --text-2: rgba(235, 238, 255, 0.62);
  --text-3: rgba(235, 238, 255, 0.40);
  --glass: rgba(255, 255, 255, 0.075);
  --glass-strong: rgba(22, 26, 58, 0.62);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-highlight: rgba(255, 255, 255, 0.28);
  --glass-inset: rgba(255, 255, 255, 0.06);
  --shadow: 0 1rem 2.5rem rgba(2, 4, 20, 0.45);
  --overlay: linear-gradient(180deg, rgba(8, 10, 32, 0.58) 0%, rgba(8, 10, 32, 0.42) 45%, rgba(8, 10, 32, 0.66) 100%);
  --chart-grid: rgba(255, 255, 255, 0.10);
  --chart-label: rgba(235, 238, 255, 0.55);
  --pos: #4ade80;
  --neg: #fb7185;
  --input-bg: rgba(255, 255, 255, 0.08);
  --nav-active-bg: rgba(255, 255, 255, 0.16);
  --logo-chip: rgba(255, 255, 255, 0.85);
}

body[data-theme="light"] {
  --text: #1b2240;
  --text-2: rgba(27, 34, 64, 0.62);
  --text-3: rgba(27, 34, 64, 0.42);
  --glass: rgba(255, 255, 255, 0.52);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.75);
  --glass-highlight: rgba(255, 255, 255, 0.95);
  --glass-inset: rgba(255, 255, 255, 0.35);
  --shadow: 0 1rem 2.5rem rgba(40, 50, 120, 0.18);
  --overlay: linear-gradient(180deg, rgba(238, 241, 255, 0.78) 0%, rgba(238, 241, 255, 0.62) 45%, rgba(238, 241, 255, 0.82) 100%);
  --chart-grid: rgba(27, 34, 64, 0.10);
  --chart-label: rgba(27, 34, 64, 0.55);
  --pos: #0d9466;
  --neg: #d63a5e;
  --input-bg: rgba(255, 255, 255, 0.65);
  --nav-active-bg: rgba(255, 255, 255, 0.9);
  --logo-chip: rgba(255, 255, 255, 0.9);
}

/* ---------- Base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: calc(16px * var(--fs-scale)); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: #0b1026;
  transition: color .35s ease;
  -webkit-font-smoothing: antialiased;
}

/* Fixed photographic backdrop + theme overlay */
.bg {
  position: fixed; inset: 0; z-index: -2;
  background: url('../images/background.jpg') center / cover no-repeat;
  transform: scale(1.03);
}
.bg::after {
  content: ''; position: absolute; inset: 0;
  background: var(--overlay);
  transition: background .45s ease;
}

img { user-select: none; -webkit-user-drag: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---------- Glass primitives ---------- */
.glass {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight), inset 0 -1px 0 var(--glass-inset);
  transition: background .35s ease, border-color .35s ease;
}

/* ---------- Login ---------- */
#login-view {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 24rem;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem 2.25rem;
  text-align: center;
  animation: rise .5s cubic-bezier(.2,.9,.3,1.2);
}
.login-logo-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--logo-chip);
  border-radius: 1.4rem;
  padding: 0.9rem 1.4rem;
  margin-bottom: 1.4rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 0.5rem 1.5rem rgba(0,0,0,.18);
}
.login-logo-wrap img { height: 3.4rem; display: block; }
.login-card h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; }
.login-card .sub { color: var(--text-2); font-size: .85rem; margin: .35rem 0 1.6rem; }
.field {
  display: flex; align-items: center; gap: .7rem;
  background: var(--input-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  margin-bottom: .85rem;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.field:focus-within { border-color: rgba(140, 160, 255, .8); box-shadow: 0 0 0 3px rgba(110, 130, 255, .18); }
.field svg { width: 1.1rem; height: 1.1rem; opacity: .55; flex: none; }
.field input {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  color: var(--text); font-size: 1rem;
}
.field input::placeholder { color: var(--text-3); }
.btn-primary {
  width: 100%;
  padding: .95rem;
  margin-top: .4rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #ef3b32, var(--accent) 55%, #b8140c);
  color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: .02em;
  box-shadow: 0 0.6rem 1.4rem rgba(226, 35, 26, .38), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .15s ease, filter .2s ease;
}
.btn-primary:active { transform: scale(.97); filter: brightness(.92); }
.login-err {
  color: #ff8d96; font-size: .82rem; min-height: 1.2rem; margin-top: .8rem;
  opacity: 0; transition: opacity .25s ease;
}
.login-err.show { opacity: 1; }
.shake { animation: shake .4s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 50%{transform:translateX(8px)} 75%{transform:translateX(-5px)} }
@keyframes rise { from { opacity: 0; transform: translateY(1.5rem) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- App shell ---------- */
#app { display: none; }
#app.active { display: block; }
#login-view.hidden { display: none; }

/* Top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) 1rem 0;
  display: flex; align-items: center; gap: .9rem;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 0 var(--glass-highlight) inset;
  transition: background .35s ease;
}
.topbar-logo {
  background: var(--logo-chip);
  border-radius: .8rem;
  padding: .35rem .6rem;
  display: flex; align-items: center;
}
.topbar-logo img { height: 1.9rem; display: block; }
.topbar-spacer { flex: 1; }
.topbar-user { text-align: right; line-height: 1.25; }
.topbar-user .name { font-weight: 700; font-size: .95rem; }
.topbar-user .role { font-size: .72rem; color: var(--text-2); }
.icon-btn {
  width: 2.6rem; height: 2.6rem; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  transition: transform .15s ease, background .25s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 1.25rem; height: 1.25rem; }

/* Main scroll area */
.main {
  padding: calc(var(--topbar-h) + var(--safe-t) + 1rem) 1rem calc(var(--bottnav-h) + var(--safe-b) + 1.5rem);
  max-width: 75rem;
  margin: 0 auto;
}

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

.greeting { margin: .2rem .2rem 1.1rem; }
.greeting h2 { font-size: 1.45rem; font-weight: 800; letter-spacing: -.01em; }
.greeting p { color: var(--text-2); font-size: .85rem; margin-top: .15rem; }

.section-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-2);
  margin: 1.4rem .25rem .7rem;
}

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .8rem;
}
.kpi {
  padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: .3rem;
  min-height: 6.1rem;
}
.kpi .k-label {
  font-size: .72rem; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .06em;
  display: flex; align-items: center; gap: .45rem;
}
.kpi .k-label svg { width: .95rem; height: .95rem; opacity: .8; }
.kpi .k-value {
  font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em;
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.kpi .k-sub { font-size: .73rem; color: var(--text-3); }
.kpi .k-sub .up { color: var(--pos); font-weight: 700; }
.kpi .k-sub .down { color: var(--neg); font-weight: 700; }

/* Money mask + eye */
.money { font-variant-numeric: tabular-nums; }
.eye-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--glass-border);
  flex: none;
}
.eye-btn svg { width: 1rem; height: 1rem; opacity: .75; }
.eye-btn:active { transform: scale(.9); }

/* ---------- Cards / charts ---------- */
.card { padding: 1.15rem 1.15rem 1rem; margin-top: .9rem; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: .6rem;
  margin-bottom: .35rem;
}
.card-head h3 { font-size: .98rem; font-weight: 700; }
.card-head .meta { font-size: .72rem; color: var(--text-3); white-space: nowrap; }
.card-head .with-eye { display: flex; align-items: center; gap: .5rem; }
.chart { width: 100%; height: 16.5rem; }
.chart.tall { height: 19rem; }

/* Stat rows (lists) */
.rows { display: flex; flex-direction: column; }
.row-item {
  display: flex; align-items: center; gap: .9rem;
  padding: .8rem .2rem;
  border-bottom: 1px solid var(--chart-grid);
}
.row-item:last-child { border-bottom: none; }
.row-badge {
  width: 2.5rem; height: 2.5rem; border-radius: .8rem; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800;
  background: var(--glass); border: 1px solid var(--glass-border);
}
.row-main { flex: 1; min-width: 0; }
.row-main .t { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main .s { font-size: .74rem; color: var(--text-2); }
.row-end { text-align: right; }
.row-end .v { font-weight: 700; font-size: .92rem; font-variant-numeric: tabular-nums; }
.row-end .u { font-size: .7rem; color: var(--text-3); }

.bar-track {
  height: .35rem; border-radius: 1rem; background: var(--chart-grid);
  margin-top: .35rem; overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 1rem; background: linear-gradient(90deg, #6f7bff, #a78bfa); }

/* Pills */
.pill {
  display: inline-block; padding: .18rem .6rem; border-radius: 1rem;
  font-size: .68rem; font-weight: 700;
  background: var(--glass); border: 1px solid var(--glass-border);
  color: var(--text-2);
}

/* ---------- Bottom navigation ---------- */
.bottnav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + .8rem);
  z-index: 40;
  display: flex; gap: .25rem;
  padding: .4rem;
  border-radius: 2.2rem;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  width: 4.1rem; padding: .5rem 0 .45rem;
  border-radius: 1.7rem;
  color: var(--text-2);
  transition: background .25s ease, color .25s ease, transform .15s ease;
}
.nav-btn svg { width: 1.35rem; height: 1.35rem; }
.nav-btn span { font-size: .62rem; font-weight: 700; letter-spacing: .03em; }
.nav-btn.active { background: var(--nav-active-bg); color: var(--text); box-shadow: inset 0 1px 0 var(--glass-highlight); }
.nav-btn:active { transform: scale(.94); }

/* ---------- Settings sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 8, 25, .45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; transform: translate(-50%, 110%);
  bottom: 0; z-index: 61;
  width: 100%; max-width: 30rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.5rem 1.5rem calc(1.8rem + var(--safe-b));
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight);
  transition: transform .38s cubic-bezier(.32,.72,.28,1);
}
.sheet.open { transform: translate(-50%, 0); }
.sheet-grab { width: 2.6rem; height: .3rem; border-radius: 1rem; background: var(--text-3); margin: 0 auto 1.2rem; }
.sheet h3 { font-size: 1.15rem; font-weight: 800; margin-bottom: 1.2rem; }
.set-group { margin-bottom: 1.35rem; }
.set-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-2); margin-bottom: .6rem; }

.seg {
  display: flex; gap: .3rem; padding: .28rem;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  border: 1px solid var(--glass-border);
}
.seg button {
  flex: 1; padding: .6rem; border-radius: .65rem;
  font-weight: 700; font-size: .88rem; color: var(--text-2);
  transition: background .25s ease, color .25s ease;
}
.seg button.active { background: var(--nav-active-bg); color: var(--text); box-shadow: inset 0 1px 0 var(--glass-highlight); }

.slider-row { display: flex; align-items: center; gap: .9rem; }
.slider-row .sz { font-size: .75rem; color: var(--text-3); font-weight: 700; }
.slider-row .sz.big { font-size: 1.15rem; }
input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: .4rem; border-radius: 1rem;
  background: var(--chart-grid);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 .2rem .6rem rgba(0,0,0,.3);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: #fff; border: none;
  box-shadow: 0 .2rem .6rem rgba(0,0,0,.3);
  cursor: pointer;
}
.slider-val { text-align: center; font-size: .78rem; color: var(--text-2); margin-top: .45rem; }
.preview-text {
  margin-top: .7rem; padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--input-bg); border: 1px solid var(--glass-border);
  font-size: .95rem; color: var(--text-2);
}
.btn-logout {
  width: 100%; padding: .9rem;
  border-radius: var(--radius-sm);
  background: rgba(226, 35, 26, .14);
  border: 1px solid rgba(226, 35, 26, .45);
  color: #ff6b62; font-weight: 800; font-size: .95rem;
  display: flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn-logout svg { width: 1.1rem; height: 1.1rem; }
body[data-theme="light"] .btn-logout { color: #c81e15; }

/* ---------- Highcharts glass cleanup ---------- */
.highcharts-background { fill: transparent; }
.highcharts-credits { display: none; }

/* ---------- Tablet / landscape ---------- */
@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .chart { height: 18rem; }
}
@media (min-width: 900px) {
  .main { padding-left: 1.5rem; padding-right: 1.5rem; }
  .duo { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; align-items: stretch; }
  .duo .card { margin-top: .9rem; }
  .trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }
  .trio .card { margin-top: .9rem; }
  .greeting h2 { font-size: 1.7rem; }
  .nav-btn { width: 5rem; }
}
@media (min-width: 1200px) {
  .kpi-grid { gap: 1rem; }
}
