/* ─────────────────────────────────────────────────────────────
   Тема в стиле dev-инструмента (тёмный «GitLab/GitHub»).
   ───────────────────────────────────────────────────────────── */
:root {
  --bg: #1a1a1a;
  --surface: #232323;
  --surface-2: #2b2b2b;
  --border: #383838;
  --border-soft: #2f2f2f;
  --text: #e8e8e8;
  --hint: #8d8d8d;
  --link: #62a0ff;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #da3633;
  --green: #3fb950;
  --red: #f85149;
  --radius: 9px;
  --radius-sm: 7px;
  --shadow: none;
  --pad: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}
body { overflow-x: hidden; }

#root {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 84px;
  overflow-x: hidden;
}

svg.icon { stroke: currentColor; fill: none; display: block; flex: none; }
.ic { display: inline-flex; align-items: center; justify-content: center; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px var(--pad);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.app-header__title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.app-header__title > div { min-width: 0; }
.logo {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--link); flex: none;
}
.logo svg { width: 20px; height: 20px; }
.h-title { font-weight: 600; font-size: 16px; letter-spacing: .1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-sub { color: var(--hint); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer; flex: none;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: #333; border-color: #444; }
.icon-btn:active { background: #2a2a2a; }

.view { flex: 1; padding: var(--pad); display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 15px;
  border: 1px solid var(--border-soft); overflow: hidden;
}

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--hint); margin: 8px 2px 0; display: flex; align-items: center; gap: 7px;
  font-weight: 600;
}
.section-title svg { width: 14px; height: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border-radius: var(--radius-sm); padding: 14px 8px;
  text-align: center; border: 1px solid var(--border-soft); min-width: 0;
}
.stat__icon { color: var(--link); margin-bottom: 4px; display: grid; place-items: center; }
.stat__icon svg { width: 19px; height: 19px; }
.stat__value { font-size: 20px; font-weight: 700; }
.stat__label { font-size: 11px; color: var(--hint); margin-top: 2px; }

.token-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; gap: 8px; flex-wrap: wrap; }
.token-row + .token-row { border-top: 1px solid var(--border-soft); }
.token-name { font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600;
  background: color-mix(in srgb, var(--link) 16%, transparent); color: var(--link);
  border: 1px solid color-mix(in srgb, var(--link) 30%, transparent);
}
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.money--in { color: var(--green); }
.money--out { color: var(--red); }
.net-line { display: flex; gap: 12px; justify-content: flex-end; font-size: 13px; color: var(--hint); flex-wrap: wrap; }

.list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tx {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border-radius: var(--radius-sm); padding: 11px 13px;
  border: 1px solid var(--border-soft); transition: background .12s, border-color .12s;
  min-width: 0;
}
.tx:hover { background: #262626; border-color: var(--border); }
.tx__icon {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  flex: none; margin-top: 1px;
}
.tx__icon svg { width: 17px; height: 17px; }
.tx__icon--in { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.tx__icon--out { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.tx__icon--income { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.tx__icon--expense { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.tx__icon--both { background: color-mix(in srgb, var(--link) 16%, transparent); color: var(--link); }
.tx__main { flex: 1; min-width: 0; }
.tx__top { display: flex; justify-content: space-between; gap: 8px; }
.tx__amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.tx__meta { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Строка категории + действий: бейдж тянется/переносится, иконки фиксированы справа */
.tx__cat { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.tx__cat > .badge { flex: 1 1 auto; min-width: 0; }
.tx__cat-acts { flex: none; display: flex; gap: 6px; }

.tx__note {
  margin-top: 6px; font-size: 12.5px; color: var(--text); opacity: .9;
  display: flex; align-items: flex-start; gap: 6px; white-space: normal; word-break: break-word;
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 6px;
  padding: 6px 8px;
}
.tx__note svg { width: 13px; height: 13px; color: var(--link); margin-top: 2px; flex: none; }

.badge {
  display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: 6px;
  background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link);
  border: 1px solid color-mix(in srgb, var(--link) 28%, transparent); font-weight: 600;
  white-space: normal; word-break: break-word; max-width: 100%;
}
.badge--empty { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--red);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent); }
.badge--income { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green);
  border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.badge--expense { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red);
  border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.badge--both { background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link);
  border-color: color-mix(in srgb, var(--link) 28%, transparent); }

.wallet__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.wallet__name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.wallet__name svg { width: 17px; height: 17px; color: var(--link); flex: none; }
.wallet__addr { font-size: 12px; color: var(--hint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; margin-top: 2px; }
.wallet__bal { display: flex; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.bal-pill { background: var(--bg); border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px 12px; flex: 1 1 120px; min-width: 0; }
.bal-pill__label { font-size: 11px; color: var(--hint); }
.bal-pill__value { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.wallet__flow { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--hint); margin-top: 4px; flex-wrap: wrap; gap: 6px; }
.wallet__actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.btn {
  border: 1px solid transparent; border-radius: 7px; padding: 10px 15px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .12s, border-color .12s, transform .1s;
  background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; max-width: 100%;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: #2a7bf6; }
.btn:active { transform: translateY(1px); }
.btn--block { width: 100%; }
.btn--ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: #333; border-color: #454545; }
.btn--danger { background: color-mix(in srgb, var(--danger) 18%, var(--surface-2)); color: var(--red);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 28%, var(--surface-2)); }
.btn--sm { padding: 8px 12px; font-size: 13px; border-radius: 7px; }
.btn--sm svg { width: 14px; height: 14px; }
.btn--icon { padding: 8px; width: 36px; height: 36px; }
.btn--icon svg { width: 17px; height: 17px; }
.btn--grow { flex: 1 1 auto; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-width: 0; }
.field label { font-size: 12px; color: var(--hint); padding-left: 2px; }
.input, .select {
  width: 100%; max-width: 100%; padding: 11px 13px; border-radius: 7px; font-size: 14.5px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
}
.input::placeholder { color: #6a6a6a; }
.input:focus, .select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }

.select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='16'%20height='16'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%238d8d8d'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M6%209l6%206%206-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px 16px;
  text-overflow: ellipsis;
}
.select:focus {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='16'%20height='16'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%2362a0ff'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M6%209l6%206%206-6'/%3E%3C/svg%3E");
}
.select option { background: #232323; color: var(--text); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); cursor: pointer; }

.segmented { display: flex; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 8px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.segmented button {
  flex: 1 1 0; min-width: 64px; border: none; background: transparent; color: var(--hint); padding: 8px 4px;
  border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; transition: .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active { background: var(--accent); color: var(--accent-text); }

.chart-card { background: var(--surface); border-radius: var(--radius); padding: 13px 14px 8px;
  border: 1px solid var(--border-soft); overflow: hidden; }
.chart-card__title { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
.chart-card__title svg { width: 15px; height: 15px; color: var(--link); flex: none; }
.chart-box { position: relative; width: 100%; height: 240px; }
.chart-empty { color: var(--hint); text-align: center; padding: 36px 8px; font-size: 13px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 760px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #1d1d1d;
  border-top: 1px solid var(--border);
  padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
}
.tab {
  border: none; background: transparent; color: var(--hint); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; padding: 4px;
  transition: color .15s; min-width: 0;
}
.tab svg { width: 21px; height: 21px; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--link); }

.sheet-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 760px;
  border-radius: 12px 12px 0 0; border: 1px solid var(--border); border-bottom: none;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 78vh; overflow-y: auto; animation: slideup .22s ease;
}
.sheet__handle { width: 40px; height: 4px; border-radius: 3px; background: #555; margin: 6px auto 12px; }
.sheet__title { font-weight: 700; font-size: 15px; margin-bottom: 12px; text-align: center; }
.sheet__body { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sheet__close { width: 100%; }
.pick {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 13px; border-radius: 8px; background: var(--bg); cursor: pointer;
  border: 1px solid var(--border-soft); transition: background .12s, border-color .12s;
}
.pick:hover { background: #262626; border-color: var(--border); }
.pick .row { min-width: 0; }
.pick span { overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; color: var(--hint); padding: 30px 16px; }
.empty__icon { color: #5a5a5a; margin-bottom: 8px; display: grid; place-items: center; }
.empty__icon svg { width: 36px; height: 36px; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--hint); }
.hint { font-size: 12px; color: var(--hint); }

.loader { display: grid; place-items: center; padding: 50px 0; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--link); animation: spin 0.8s linear infinite;
}

.toast {
  position: fixed; left: 50%; bottom: 94px; transform: translateX(-50%);
  background: #2d2d2d; color: var(--text); padding: 10px 16px; border-radius: 8px;
  font-weight: 600; font-size: 13px; z-index: 60; border: 1px solid var(--border);
  max-width: 90%; animation: fade .2s ease;
}
.toast--error { background: color-mix(in srgb, var(--danger) 30%, #2d2d2d); border-color: var(--danger); color: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
