:root {
  --bg: #f5f6fb; --bg2: #eef0fa; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e8eaf3;
  --primary: #6366f1; --primary2: #8b5cf6; --primary-soft: #eef2ff;
  --in: #059669; --in-soft: #d1fae5; --out: #e11d48; --out-soft: #ffe4e6; --swap: #0ea5e9; --swap-soft: #e0f2fe;
  --shadow: 0 1px 2px rgba(17,24,39,.04), 0 8px 24px rgba(79,70,229,.07);
  --radius: 18px; --sidebar: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d17; --bg2: #11142a; --card: #151934; --text: #eef0ff; --muted: #9aa1c0; --line: #252a4a;
    --primary-soft: #23275a; --in: #34d399; --in-soft: #0c3a30; --out: #fb7185; --out-soft: #4a1524;
    --swap: #38bdf8; --swap-soft: #0c3248; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light dark; }
body {
  margin: 0; color: var(--text); font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(900px 500px at 100% -10%, rgba(139,92,246,.14), transparent 60%),
              radial-gradient(800px 500px at -10% 110%, rgba(99,102,241,.12), transparent 60%), var(--bg);
  background-attachment: fixed; min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -.01em; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); display: flex; flex-direction: column; padding: 22px 16px;
  background: var(--card); border-right: 1px solid var(--line); z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary2)); box-shadow: 0 6px 16px rgba(99,102,241,.4); }
.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; }
.company-switch { display: flex; flex-direction: column; gap: 5px; margin-top: 20px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.company-switch label { margin: 0; font-size: 10px; letter-spacing: .08em; }
.company-switch select { padding: 8px 30px 8px 10px; font-size: 13px; font-weight: 700; border: 0; background-color: var(--card); }
.empty-switch { flex-direction: row; align-items: center; color: var(--primary); font-weight: 700; text-decoration: none; }
.section-head { margin: 28px 4px 14px; }
.section-head h2 { margin: 0; }
.section-head .sub { margin-top: 3px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.side-nav a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.side-nav a.on { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: #fff; box-shadow: 0 8px 18px rgba(99,102,241,.35); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; border-radius: 12px; color: var(--text); }
.me:hover, .me.on { background: var(--primary-soft); text-decoration: none; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.me-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.me-text small { color: var(--muted); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700; font-size: 13px; color: #fff;
  background: linear-gradient(135deg, #f59e0b, #ef4444); }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 0; display: grid; place-items: center; cursor: pointer; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--out-soft); color: var(--out); }
.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.content { width: 100%; max-width: 980px; margin: 0 auto; padding: 34px 28px 60px; flex: 1; }
.site-footer { padding: 16px 20px; color: var(--muted); font-size: 13px; text-align: center; }
.mobilebar, .tabbar { display: none; }

.head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.head .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sub { color: var(--muted); margin-top: 4px; }

/* ---------- Cards & stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { position: relative; overflow: hidden; border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: 0 14px 30px rgba(99,102,241,.28);
  background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.stat:nth-child(3n+2) { background: linear-gradient(135deg, #0ea5e9, #6366f1); box-shadow: 0 14px 30px rgba(14,165,233,.25); }
.stat:nth-child(3n+3) { background: linear-gradient(135deg, #10b981, #0ea5e9); box-shadow: 0 14px 30px rgba(16,185,129,.25); }
.stat::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.12); }
.stat .cur { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .08em; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.2); }
.stat .bal { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin: 10px 0 14px; }
.stat .split { display: flex; gap: 18px; font-size: 13px; opacity: .95; position: relative; z-index: 1; }
.stat .split b { display: block; font-size: 15px; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 11px 18px; font: inherit; font-weight: 600; cursor: pointer;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary2)); box-shadow: 0 8px 18px rgba(99,102,241,.32); transition: transform .12s, box-shadow .12s; }
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 12px 22px rgba(99,102,241,.4); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.swap { background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.btn.block { width: 100%; padding: 14px; }
label { display: block; font-weight: 600; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font: inherit; color: var(--text);
  background: var(--bg); transition: border-color .15s, box-shadow .15s; appearance: none; -webkit-appearance: none; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 38px; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.18); background: var(--card); }
textarea { resize: vertical; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-card { max-width: 600px; }
.company-fixed { min-height: 46px; display: flex; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; min-width: 0; }
.input-group select { width: 112px; flex: none; }
.amount input { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { margin: 0; text-align: center; padding: 11px; border-radius: 10px; cursor: pointer; font-weight: 700; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg input:checked + label.l-in { background: var(--in-soft); color: var(--in); }
.seg input:checked + label.l-out { background: var(--out-soft); color: var(--out); }
.seg input:focus-visible + label { box-shadow: 0 0 0 3px rgba(99,102,241,.35); }
.check { display: flex; align-items: center; gap: 10px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.check label { margin: 0; color: var(--text); font-size: 15px; }
.remember-check { align-items: flex-start; margin: 4px 0 20px; }
.remember-check input { flex: none; margin: 2px 0 0; }
.remember-check label { cursor: pointer; }
.remember-check label span { display: flex; flex-direction: column; gap: 2px; }
.remember-check label small { color: var(--muted); font-size: 12px; font-weight: 400; }
.rate-box { display: grid; gap: 14px; padding: 16px; border-radius: 14px; background: var(--swap-soft); margin-bottom: 16px; }
.rate-hint { font-weight: 700; color: var(--swap); font-size: 14px; }
.swap-arrow { display: grid; place-items: center; color: var(--swap); }

/* ---------- Filters ---------- */
.filters { padding: 0; overflow: hidden; }
.filters > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 20px; font-weight: 700; }
.filters > summary::-webkit-details-marker { display: none; }
.filters .badge-count { background: var(--primary); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 9px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 4px 20px 20px; align-items: end; }
.filter-grid .field { margin: 0; }
.filter-actions { display: flex; gap: 8px; }

/* ---------- Transaction list ---------- */
.day { margin: 22px 4px 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--bg2); }
.ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.ico.in { background: var(--in-soft); color: var(--in); }
.ico.out { background: var(--out-soft); color: var(--out); }
.ico.swap { background: var(--swap-soft); color: var(--swap); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.row-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.chip { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
.chip.swap { background: var(--swap-soft); color: var(--swap); }
.chip.admin { background: var(--primary-soft); color: var(--primary); }
.chip.off { background: var(--out-soft); color: var(--out); }
.chip.on { background: var(--in-soft); color: var(--in); }
.amt { font-weight: 800; font-size: 16px; white-space: nowrap; text-align: right; letter-spacing: -.01em; }
.amt.in, .in { color: var(--in); }
.amt.out, .out { color: var(--out); }
.row-actions { display: flex; gap: 2px; flex: none; }
.row-actions form { margin: 0; }
.act { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.act:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.act.danger:hover { background: var(--out-soft); color: var(--out); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ico { margin: 0 auto 12px; width: 60px; height: 60px; background: var(--primary-soft); color: var(--primary); }

/* ---------- Companies ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.company { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.company h3 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.company h3 a { color: var(--text); }
.company .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.bal-list { display: grid; gap: 6px; margin-top: 4px; }
.bal-line { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 12px; border-radius: 10px; background: var(--bg); font-size: 14px; }
.bal-line b { font-weight: 800; }
.company .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding-top: 6px; }

/* ---------- Misc ---------- */
.alert { padding: 13px 16px; border-radius: 14px; margin-bottom: 18px; font-weight: 500; }
.alert.ok { background: var(--in-soft); color: var(--in); }
.alert.err { background: var(--out-soft); color: var(--out); }
.pager { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 22px; }
.pager a, .pager span { min-width: 38px; text-align: center; padding: 7px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 600; }
.pager span { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: #fff; border-color: transparent; }
.pager a:hover { text-decoration: none; background: var(--primary-soft); }
.summary-line { color: var(--muted); font-size: 13px; margin: 8px 4px 0; }

/* ---------- Auth ---------- */
body.auth { display: flex; flex-direction: column; align-items: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 420px; margin: auto 0; }
.auth-brand { justify-content: center; margin-bottom: 22px; font-size: 24px; }
.auth-card { padding: 28px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-links { margin-top: 16px; text-align: center; color: var(--muted); font-size: 14px; }
.act.approve { color: var(--in); font-size: 20px; font-weight: 800; }
.act.approve:hover { background: var(--in-soft); color: var(--in); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .content { padding: 18px 16px 20px; }
  .app .site-footer { padding-bottom: calc(100px + var(--safe-b)); }
  .mobilebar { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px;
    background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
  .mobilebar .company-switch { flex: 1; min-width: 0; max-width: 180px; margin: 0; padding: 0; border: 0; background: transparent; }
  .mobilebar .company-switch label { display: none; }
  .mobilebar .company-switch select { padding: 7px 28px 7px 9px; font-size: 12px; }
  .mobilebar .company-switch.empty-switch { padding: 8px; background: var(--primary-soft); border-radius: 10px; font-size: 12px; }
  .mobilebar-r { display: flex; align-items: center; gap: 6px; }
  .mobilebar form { margin: 0; }
  .mobilebar .avatar { width: 34px; height: 34px; }
  .tabbar { display: grid; grid-template-columns: repeat(6, 1fr); align-items: center; position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--safe-b)); z-index: 30;
    padding: 8px 6px; border-radius: 24px; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(17,24,39,.18); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 10px; font-weight: 600; padding: 6px 0; border-radius: 14px; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.on { color: var(--primary); }
  .tabbar a.fab { width: 56px; height: 56px; margin: -26px auto 0; border-radius: 50%; justify-content: center; color: #fff; padding: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary2)); box-shadow: 0 10px 24px rgba(99,102,241,.55); border: 4px solid var(--bg); }
  .tabbar a.fab .ic { width: 26px; height: 26px; stroke-width: 2.5; }
  h1 { font-size: 22px; }
  .head .actions .btn { padding: 10px 14px; }
  .stat .bal { font-size: 26px; }
  .row { padding: 12px 14px; gap: 12px; flex-wrap: wrap; }
  .ico { width: 40px; height: 40px; border-radius: 12px; }
  .row-actions { margin-left: auto; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .card.filters { padding: 0; }
  .stats { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; margin: 0 -16px 18px; padding: 4px 16px 18px; scrollbar-width: none; }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 0 0 82%; max-width: 320px; scroll-snap-align: center; padding: 16px; }
  .stat:only-child { flex-basis: 100%; max-width: none; }
  .stat .bal { margin: 8px 0 10px; }
  .auth-card { padding: 22px; }
}
@media (max-width: 480px) {
  .row { display: grid; grid-template-columns: 40px 1fr auto; gap: 4px 12px; }
  .row .row-actions { grid-column: 2 / 4; justify-self: end; margin-top: -8px; }
  .row .act { width: 32px; height: 32px; }
  .head .actions { width: 100%; }
  .head .actions .btn { flex: 1; }
}
