/* Tracker PWA — стили. Mobile-first, тема по системной настройке. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111114;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #2563eb;
  --accent-text: #ffffff;
  --tint: rgba(37, 99, 235, 0.10);
  --warn-bg: #fff4d6;
  --warn-text: #7a5200;
  --bad: #c2410c;
  --press: rgba(0, 0, 0, 0.05);
  --pending: #b45309;
  --pending-bg: rgba(180, 83, 9, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --line: rgba(255, 255, 255, 0.10);
    --accent: #5b8def;
    --accent-text: #0b1220;
    --tint: rgba(91, 141, 239, 0.18);
    --warn-bg: #3a2d08;
    --warn-text: #f5d37a;
    --bad: #f97316;
    --press: rgba(255, 255, 255, 0.07);
    --pending: #f5b041;
    --pending-bg: rgba(245, 176, 65, 0.16);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* --- Вход --- */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
}

.login-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
  text-align: center;
  letter-spacing: -0.01em;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }

.field input {
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  width: 100%;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--tint); }

.login-error { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--bad); }

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 17px;
  font-weight: 600;
}
.primary:active { opacity: 0.85; }
.login-form.is-busy .primary { opacity: 0.6; pointer-events: none; }

/* --- Шапка --- */

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }

.top-actions { display: flex; gap: 4px; }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.link:active { background: var(--press); }
.link .spin { transition: transform 0.2s; }
.link.is-spinning .spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Полоска «нет связи» --- */

.bar {
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13px;
  text-align: center;
  padding: 6px 16px;
}

/* --- Сводка --- */

.main { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  background: var(--card);
  border-radius: 16px;
  padding: 14px 14px 12px;
  min-width: 0;
}
.stat .label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.stat .value {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.stat .label .unit { opacity: 0.75; margin-left: 2px; }
.stat .why { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .why:empty { display: none; }

.stamp {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
}
.stamp .tz { opacity: 0.8; }

.sync-wrap {
  display: inline-flex;
  align-self: center;
  color: var(--muted);
  opacity: 0.55;
  margin-left: 2px;
}
.sync-wrap.is-off { opacity: 0.9; }
.sync-wrap .sync { display: block; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 420px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 5;
}

/* --- Вкладки --- */

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 16px 0 10px;
  padding: 3px;
  background: var(--press);
  border-radius: 12px;
}
.tabs [role=tab] {
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 6px 10px 5px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.25;
}
.tabs [role=tab][aria-selected=true] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.tabs .count { font-weight: 500; opacity: 0.6; margin-left: 2px; }
.tabs .tab-name { display: block; }
.tabs .sum {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
  margin-top: 1px;
}
.tabs [role=tab][aria-selected=true] .sum { color: var(--muted); }

/* --- Список --- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.group {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 10px 2px 0;
}

.row {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 12px 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.row-main { flex: 1; min-width: 0; }

.amount {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
}
.amount .cur { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.amount .approx { font-size: 13px; font-weight: 500; color: var(--muted); }

.sub { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

.badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--pending);
  background: var(--pending-bg);
  border-radius: 999px;
  padding: 2px 7px;
  text-transform: lowercase;
}

.reject { font-size: 13px; color: var(--bad); margin-top: 4px; }

.toggle {
  flex: none;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--accent);
  white-space: nowrap;
}
.toggle.restore { background: var(--tint); border-color: transparent; }
.toggle:active { background: var(--press); }
.toggle:disabled { opacity: 0.45; cursor: default; }

.row.is-deferred .row-main { opacity: 0.55; }
.row.is-pending .row-main { opacity: 0.75; }

.empty { text-align: center; color: var(--muted); margin: 32px 0; }

@media (min-width: 600px) {
  .main, .top { max-width: 560px; margin-left: auto; margin-right: auto; }
  .top { border-bottom: 0; }
}
