:root, [data-theme="dark"] {
  --bg: #0f1419;
  --bg2: #1a222c;
  --bg3: #243040;
  --text: #e7eef7;
  --muted: #8b9bb0;
  --accent: #3dd6c6;
  --accent2: #5b8cff;
  --danger: #ff6b7a;
  --ok: #6bffb0;
  --border: #2c3a4a;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
[data-theme="light"] {
  --bg: #f4f7fb;
  --bg2: #ffffff;
  --bg3: #e8eef6;
  --text: #142033;
  --muted: #5b6b80;
  --accent: #0f9d8a;
  --accent2: #3b6fe0;
  --danger: #d93a4a;
  --ok: #1a9a5c;
  --border: #d5deea;
  --shadow: 0 8px 24px rgba(20,40,80,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
a { color: var(--accent2); }
button, input, select, textarea {
  font: inherit; color: inherit; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
button { cursor: pointer; background: var(--accent); color: #04201c; border: none; font-weight: 600; }
button.secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }

.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--bg2); padding: 28px; border-radius: var(--radius);
  box-shadow: var(--shadow); display: grid; gap: 14px; border: 1px solid var(--border);
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card label { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }

.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--bg2); border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100dvh;
}
.sidebar .brand { font-weight: 700; padding: 8px 10px 16px; letter-spacing: .2px; }
.nav-btn {
  text-align: left; background: transparent; color: var(--text); border: none; padding: 10px 12px;
  border-radius: 10px; font-weight: 500;
}
.nav-btn.active, .nav-btn:hover { background: var(--bg3); }
.main { padding: 18px 18px 90px; max-width: 1100px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.card .val { font-size: 1.35rem; font-weight: 700; }
.list { display: grid; gap: 8px; }
.row {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.row .meta { color: var(--muted); font-size: .85rem; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.fab {
  position: fixed; right: 18px; bottom: 18px; width: 58px; height: 58px; border-radius: 50%;
  font-size: 1.6rem; box-shadow: var(--shadow); z-index: 20;
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: end center;
  z-index: 30; padding: 12px;
}
.modal {
  width: min(520px, 100%); background: var(--bg2); border-radius: 18px 18px 12px 12px;
  padding: 16px; border: 1px solid var(--border); max-height: 90dvh; overflow: auto;
  display: grid; gap: 10px;
}
.modal h2 { margin: 0; font-size: 1.1rem; }
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.bar-wrap { display: grid; gap: 8px; margin-top: 8px; }
.bar {
  display: grid; grid-template-columns: 110px 1fr 70px; gap: 8px; align-items: center; font-size: .9rem;
}
.bar .track { height: 10px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--bg3); font-size: .75rem; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.search { width: 100%; max-width: 320px; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px;
  z-index: 40; box-shadow: var(--shadow);
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row;
    overflow-x: auto; z-index: 15; border-right: none; border-top: 1px solid var(--border);
    padding: 8px;
  }
  .sidebar .brand, .sidebar .side-foot { display: none; }
  .nav-btn { white-space: nowrap; font-size: .85rem; padding: 10px; }
  .main { padding-bottom: 110px; }
}

/* Stronger phone layout (iPhone ~390) */
@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .sidebar {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: auto !important;
    max-height: 64px;
    flex-direction: row !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    z-index: 25;
    background: var(--bg2);
  }
  .main {
    width: 100%;
    min-height: 100dvh;
    padding: 14px 14px 120px;
  }
  .fab { bottom: 78px; right: 14px; }
}
