:root {
  --bg: #0a0a0a;
  --card: #141414;
  --card-2: #1c1c1c;
  --card-3: #242424;
  --border: #242424;
  --border-2: #333333;
  --text: #f2f2f2;
  --dim: #8f8f8f;
  --blue: #7aa7ff;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }
a { color: var(--blue); }

/* ================= topbar ================= */
#topbar {
  background: rgba(10,10,10,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.topbar-row1 {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0 8px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--text); color: var(--bg); font-size: 16px;
}
.brand .muted-part { color: var(--dim); font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 12px; color: var(--dim); font-size: 13px; min-width: 0; }
.topbar-right #me-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#topbar nav {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -4px;
}
#topbar nav::-webkit-scrollbar { display: none; }
#topbar nav a {
  color: var(--dim); text-decoration: none; padding: 10px 14px;
  font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
#topbar nav a:hover { color: var(--text); }
#topbar nav a.active { color: var(--text); border-bottom-color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 20px calc(60px + env(safe-area-inset-bottom)); }

/* ================= widgets ================= */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 14px; }
h1 { font-size: 20px; font-weight: 700; margin-bottom: 16px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--dim); }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--text); color: var(--bg);
  border: 1px solid var(--text); border-radius: 999px;
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: opacity .12s;
  min-height: 40px;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border-2); color: var(--text);
  font-weight: 500;
}
.btn-ghost:hover { opacity: 1; background: var(--card-2); }
.btn-danger { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.35); color: var(--red); }
.btn-danger:hover { opacity: 1; background: rgba(248,113,113,.2); }
.btn-sm { padding: 6px 13px; font-size: 13px; min-height: 32px; }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 13px;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  font-family: inherit;
}
@media (min-width: 641px) {
  input, select, textarea { font-size: 14px; }
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #555; }
input::placeholder, textarea::placeholder { color: #5a5a5a; }
label { display: block; margin-bottom: 5px; color: var(--dim); font-size: 13px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
th { color: var(--dim); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
tr:hover td { background: rgba(255,255,255,.02); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -8px; padding: 0 8px; }

.badge {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: rgba(74,222,128,.12);  color: var(--green); }
.badge-red    { background: rgba(248,113,113,.12); color: var(--red); }
.badge-yellow { background: rgba(251,191,36,.12);  color: var(--yellow); }
.badge-blue   { background: rgba(122,167,255,.14); color: var(--blue); }
.badge-gray   { background: rgba(143,143,143,.14); color: var(--dim); }

.amount-pos { color: var(--green); font-weight: 600; }
.amount-neg { color: var(--red); font-weight: 600; }

/* ================= login ================= */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 78vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login-card h1 { text-align: center; margin-bottom: 22px; }
.login-logo {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--text); color: var(--bg); font-size: 22px;
}

/* ================= user card ================= */
.user-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.user-header h1 { margin-bottom: 2px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px; margin-top: 16px;
}
.stat {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-width: 0;
}
.stat .stat-label { color: var(--dim); font-size: 12px; }
.stat .stat-value { font-size: 18px; font-weight: 700; margin-top: 3px; word-break: break-word; letter-spacing: -.01em; }

.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

.tabs {
  display: flex; gap: 2px; margin: 18px 0 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: none; color: var(--dim);
  padding: 9px 14px; cursor: pointer; font-size: 14px; font-family: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--text); }

.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; flex: 1; min-width: 130px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--dim); font-size: 13px; }

/* ================= modal ================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--card); border: 1px solid var(--border-2);
  border-radius: 16px; width: 100%; max-width: 440px;
  padding: 22px; max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.confirm-box {
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 15px; margin: 12px 0;
  line-height: 1.7;
}
.confirm-box .arrow { color: var(--dim); margin: 0 6px; }
.warn-note { color: var(--yellow); font-size: 13px; margin-top: 10px; }
.error-note { color: var(--red); font-size: 13px; margin-top: 8px; white-space: pre-wrap; }

/* ================= toast ================= */
#toast-root {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px; left: 16px;
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--card-3); border: 1px solid var(--border-2);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-sm); padding: 12px 16px; max-width: 380px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: slideUp .18s ease; white-space: pre-wrap; font-size: 13.5px;
}
.toast-ok  { border-left-color: var(--green); }
.toast-err { border-left-color: var(--red); }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid var(--border-2); border-top-color: var(--text);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; padding: 28px; color: var(--dim); }

/* ================= mobile ================= */
@media (max-width: 640px) {
  main { padding: 14px 12px calc(56px + env(safe-area-inset-bottom)); }
  .card { padding: 16px 14px; border-radius: 12px; }
  h1 { font-size: 18px; }

  .topbar-inner { padding: 0 12px; }
  .topbar-row1 { padding: 10px 0 6px; }
  .brand-text-full { display: none; }        /* короткий бренд на телефоне */
  .topbar-right { font-size: 12px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .stat-value { font-size: 16px; }

  /* кнопки действий — сетка 2 колонки, крупные для тапа */
  .actions-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .actions-bar .btn { width: 100%; min-height: 44px; padding: 10px 8px; font-size: 13.5px; }

  .filter-bar input, .filter-bar select { min-width: calc(50% - 8px); }
  .filter-bar .btn { flex: 1 0 100%; }

  th, td { padding: 8px 8px; font-size: 13px; }

  /* модалка — нижняя шторка */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none; border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    animation: sheetUp .22s ease;
  }
  .modal-actions { position: sticky; bottom: 0; }
  .modal-actions .btn { flex: 1; min-height: 46px; }

  #toast-root { align-items: stretch; }
  .toast { max-width: none; }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
