:root {
  --bg0: #f4f7f4;
  --bg1: #e8f0ea;
  --surface: #ffffff;
  --surface2: #eef4f0;
  --border: #d5e0d8;
  --text: #1c2b24;
  --muted: #5f7268;
  --accent: #8a6b2e;
  --accent-soft: #f3ead4;
  --accent2: #2f7a55;
  --danger: #c44b3c;
  --ok: #1f8a52;
  --eur: #9a7420;
  --rub: #2f7a55;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(28, 43, 36, 0.08);
  --font: "Segoe UI", "PT Sans", "Helvetica Neue", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 0% -10%, #dceee3 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #efe6cc 0%, transparent 48%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: calc(72px + var(--safe-b)); }

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #c4a35a, #2f7a55);
  box-shadow: var(--shadow);
}
.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }

.view { display: none; }
.view.active { display: block; animation: fade .22s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.balances {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.bal {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.bal .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 6px;
}
.bal strong {
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.bal.eur strong { color: var(--eur); }
.bal.eur.returned strong { color: var(--ok); }
.bal.rub strong { color: var(--rub); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stats-row > div {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px;
  border: 1px solid var(--border);
}
.stats-row span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 4px;
}
.stats-row b {
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.section-title {
  margin: 18px 0 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.row .meta { min-width: 0; flex: 1; }
.row .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}
.row .amt {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}
.row .amt.plus { color: var(--ok); }
.row .amt.minus { color: var(--danger); }
.row .amt.neutral { color: var(--eur); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface2);
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  width: 100%;
  background: linear-gradient(135deg, #b8923f, #8a6b2e);
  color: #fffdf7;
  margin-top: 6px;
}
.btn.secondary {
  background: #e5f3eb;
  color: var(--accent2);
  border: 1px solid #b7d9c5;
}
.btn.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1.1rem;
  width: 42px; height: 42px; padding: 0;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}
.btn.danger-sm {
  background: #fff5f3;
  color: var(--danger);
  border: 1px solid #f0c4bd;
  padding: 6px 10px;
  font-size: 0.78rem;
}

.tabs, .subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab, .subtab {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(28, 43, 36, 0.04);
}
.tab.active, .subtab.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #e0cfa0;
}

.panel { display: none; }
.panel.active {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
label small { opacity: 0.75; }

input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #fbfcfb;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  font-size: 1rem;
}
input:focus, select:focus {
  outline: 2px solid rgba(138, 107, 46, 0.35);
  outline-offset: 1px;
  background: #fff;
}
option { background: #fff; color: var(--text); }

.rate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.hint {
  margin: -2px 0 0;
  font-size: 0.78rem;
  color: var(--accent2);
  min-height: 1.1em;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.hist { display: none; }
.hist.active { display: flex; }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  max-width: 560px;
  margin: 0 auto;
  box-shadow: 0 -6px 20px rgba(28, 43, 36, 0.06);
}
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 8px 4px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.nav-btn span { font-size: 1.15rem; line-height: 1; }
.nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: #fff;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 50;
  max-width: calc(100% - 32px);
  font-size: 0.9rem;
}
#toast.error { border-color: #f0c4bd; color: var(--danger); }
#toast.ok { border-color: #b7d9c5; color: var(--ok); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px 8px;
  font-size: 0.9rem;
}

/* Auth */
.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 22px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 18px; }
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}
.auth-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff5f3;
  border: 1px solid #f0c4bd;
  color: var(--danger);
  font-size: 0.9rem;
}

/* honeypot — полностью скрыто от людей */
.hp-field {
  position: absolute !important;
  left: -9999px !important;
  top: 0 !important;
  width: 1px !important;
  height: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.bottom-nav.nav-2 {
  grid-template-columns: repeat(2, 1fr);
}

.access-box {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfb;
}
.access-box legend {
  padding: 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
}
.check-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 0.95rem;
}
.check-item input {
  width: auto;
  margin: 0;
}

body.role-creditor #hist-eur {
  display: flex;
}
