/* ---------- Токены ---------- */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #14171c;
  --muted: #667085;
  --border: #e2e5e9;
  --border-strong: #cfd4da;
  --accent: #0d8a6f;
  --accent-hover: #0b765f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ee;
  --pos: #11804e;
  --neg: #c0392b;
  --warn: #9a5b06;
  --warn-soft: #fdf4e3;
  --err-soft: #fdeceb;
  --bar: #9ad7c5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .22);
  --radius: 12px;
  --radius-sm: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #161a20;
    --surface-2: #1d222a;
    --text: #e7e9ec;
    --muted: #949cab;
    --border: #262c35;
    --border-strong: #353c47;
    --accent: #2bb894;
    --accent-hover: #34cba4;
    --accent-ink: #06231b;
    --accent-soft: #123128;
    --pos: #4ccf8c;
    --neg: #f07a6e;
    --warn: #f0b45a;
    --warn-soft: #2d2412;
    --err-soft: #331a18;
    --bar: #2a7d66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
}
body.modal-open { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn-text { color: var(--warn); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.main { padding-top: 20px; padding-bottom: 60px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Шапка ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-row { display: flex; align-items: center; gap: 24px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-size: 14px; }
.brand-text small { color: var(--muted); font-size: 11.5px; }
.brand.big { justify-content: center; font-size: 18px; margin-bottom: 18px; }

.tabs { display: flex; gap: 4px; align-self: stretch; }
.tabs a {
  display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar-actions form { margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); }
.chip.ghost { border-color: transparent; color: var(--muted); }
.chip.ghost:hover { color: var(--text); }
.chip-icon { color: var(--muted); }
.chip.busy .chip-icon { animation: spin 1s linear infinite; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); }
.dot.bad { background: var(--neg); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Сводка ---------- */
.hero { background: var(--surface); border-bottom: 1px solid var(--border); padding: 18px 0 20px; }
.hero-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.hero-period { font-size: 15px; font-weight: 550; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 12px 16px; min-width: 0; }
.stats.cards .stat { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value.small { font-size: 16px; }
.stat-value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 5px; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--err-soft); border-color: var(--neg); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; font-size: 18px; }
.btn.disabled { opacity: .35; pointer-events: none; }
.btn.block { width: 100%; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px; font-weight: 650;
  display: inline-grid; place-items: center; background: rgba(255, 255, 255, .25);
}
.link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.icon-btn { border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input, .select, .field input, .field select, .field textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
textarea.input, .field textarea { height: auto; padding: 8px 10px; resize: vertical; }
.input.sm { height: 28px; font-size: 13px; padding: 0 6px; }
.input:focus, .select:focus, .field input:focus, .field select:focus, .field textarea:focus, .inline:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent);
}
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
.field > span { color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; }
.inline {
  width: 100%; min-width: 120px; height: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit;
}
.inline:hover { border-color: var(--border); background: var(--surface); }
.inline.saved { border-color: var(--pos); }
.inline.failed { border-color: var(--neg); }

/* ---------- Карточки и сетка ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.note { background: transparent; box-shadow: none; border-style: dashed; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.page-head { display: flex; flex-direction: column; gap: 6px; }
.page-head p { margin: 0; }
.back { font-size: 13px; color: var(--muted); }
.addr-full { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.addr-full .mono { font-size: 13px; word-break: break-all; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); }
.plain { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); margin-top: 14px; font-size: 13.5px; }
.alert.err { background: var(--err-soft); color: var(--neg); margin: 0 0 14px; }
.modal .alert { margin: 0 0 12px; }

/* ---------- Неделя ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.weeknav-controls { display: flex; align-items: center; gap: 6px; }
.weeknav-controls .select { min-width: 220px; }
.weeknav-note { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; }
.weeknav-note b { color: var(--text); font-weight: 600; }
.summary-line { display: flex; gap: 8px 22px; flex-wrap: wrap; align-items: baseline; padding: 0 2px; }
.summary-line b { font-size: 16px; margin-left: 4px; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.card.flush .table-wrap { margin: 0; padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 18px; }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: 18px; }
.num, .table th.num { text-align: right; white-space: nowrap; }
.table .actions { width: 1%; text-align: right; white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }
.quiet { color: inherit; }
.quiet:hover { color: var(--accent); }

.breakdown td { padding-top: 8px; padding-bottom: 8px; }
.breakdown .bar-cell { width: 34%; }
.breakdown .share { width: 44px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--bar); border-radius: 3px; }

.wallet-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wallet-text { min-width: 0; }
.wallet-name { color: var(--text); font-weight: 550; }
a.wallet-name:hover { color: var(--accent); }
.unlabeled { color: var(--muted); font-style: italic; font-weight: 400; }
.addr { color: var(--muted); font-size: 11.5px; }
.dir {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.dir.in { background: color-mix(in srgb, var(--pos) 14%, transparent); color: var(--pos); }
.dir.out { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); }
.amount { font-weight: 600; }
.amount.in { color: var(--pos); }
.amount.out { color: var(--text); }
tr.is-dust td { opacity: .5; }
tr.is-swap .wallet-name { color: var(--accent); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; white-space: nowrap; color: var(--text);
}
.tag.soft { color: var(--muted); }
.tag.empty { border-style: dashed; color: var(--warn); background: transparent; }
a.tag:hover { text-decoration: none; border-color: var(--warn); }
.asset { font-size: 11.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; }
.asset.usdt { background: color-mix(in srgb, #26a17b 16%, transparent); color: #1a8a67; }
.asset.trx { background: color-mix(in srgb, #ef0027 12%, transparent); color: #d4183a; }
@media (prefers-color-scheme: dark) {
  .asset.usdt { color: #4fd1a8; }
  .asset.trx { color: #ff6b81; }
}
.crm { font-size: 12.5px; white-space: nowrap; }
.crm.ok { color: var(--pos); }
.crm.marked { color: var(--muted); }
.crm.err { color: var(--neg); cursor: help; }
.crm.none { color: var(--muted); opacity: .7; }

.kebab {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid transparent; background: none; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.kebab:hover, .kebab.open { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.segmented a { padding: 4px 12px; border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 550; }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .input { flex: 1 1 280px; max-width: 420px; }
.wallet-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form .input { flex: 1; }

/* ---------- Меню ---------- */
.menu {
  position: absolute; z-index: 60; min-width: 240px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px;
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--text); font: inherit;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--neg); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- Модальное окно ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 20, .5); }
.modal-box {
  position: relative; width: min(900px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal-head, .modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; }
.modal-head { justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-foot { border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.modal-body { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body p { margin: 0; }
.crm-tools { display: flex; gap: 6px 12px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.crm-list { max-height: 330px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 0; padding: 0; }
.crm-list .table th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.crm-list .table td, .crm-list .table th { padding: 7px 10px; }
.crm-list tr.no-cat td { background: color-mix(in srgb, var(--warn-soft) 60%, transparent); }
.check-col { width: 32px; }
.crm-total { font-size: 13.5px; }
.crm-total b { font-size: 15px; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress-text { font-weight: 550; }
.log { margin: 0; padding: 10px 12px 10px 34px; max-height: 300px; overflow: auto; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 12.5px; }
.log li { margin: 2px 0; }
.log .ok { color: var(--pos); }
.log .error { color: var(--neg); }
.log .t { color: var(--muted); font-family: var(--mono); margin-right: 6px; }

/* ---------- Уведомления ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg);
  max-width: 380px; font-size: 13.5px; transition: opacity .3s, transform .3s;
}
.toast.err { background: var(--neg); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(6px); }

/* ---------- Вход ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.login-box h1 { font-size: 40px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Адаптив ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .wrap { padding: 0 14px; }
  .topbar-row { flex-wrap: wrap; gap: 0 12px; padding-top: 8px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; min-height: 42px; }
  .brand-text small { display: none; }
  .stat-value { font-size: 19px; }
  .wallet-form { grid-template-columns: minmax(0, 1fr); }
  .weeknav-controls .select { min-width: 0; flex: 1; }
  .weeknav-controls { width: 100%; }
  .table-wrap { margin: 0 -18px; }
  .modal { padding: 0; }
  .modal-box { max-height: 100vh; height: 100%; border-radius: 0; }
}
