:root, [data-theme="light"] {
  --bg: #f3f7f2;
  --card: #ffffff;
  --ink: #142418;
  --muted: #5f735f;
  --accent: #2f7a3c;
  --accent-2: #236330;
  --accent-soft: #e5f2e8;
  --accent-ink: #ffffff;
  --ok: #1f7a3a;
  --warn: #b7791f;
  --line: #d5e2d7;
  --shadow: 0 8px 24px rgba(20, 36, 24, 0.06);
  --radius: 18px;
  --dock-h: 76px;
  --pad-x: 16px;
  --gap: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #121a14;
  --card: #1c271f;
  --ink: #e8f0e9;
  --muted: #9aaf9d;
  --accent: #3f9a52;
  --accent-2: #58b36a;
  --accent-soft: #243528;
  --accent-ink: #ffffff;
  --ok: #5dca78;
  --warn: #d4a017;
  --line: #2d3d31;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg) !important;
  color: var(--ink) !important;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(12px + env(safe-area-inset-top))
    var(--pad-x)
    calc(var(--dock-h) + 20px + env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  margin-bottom: 16px;
  width: 100%;
}
.topbar-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.credits {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow);
}
.credits span { color: inherit; }
.credits-suf {
  font-weight: 700;
  opacity: 0.92;
  font-size: 13px;
}

.section-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 10px;
}
.fold {
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}
.fold-sum {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}
.fold-sum::-webkit-details-marker { display: none; }
.fold-sum::after {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.fold[open] .fold-sum::after {
  transform: rotate(-135deg);
}
.fold-meta {
  margin-left: auto;
  margin-right: 10px;
  color: var(--ink);
  font-weight: 750;
}
.fold-body {
  padding: 0 10px 10px;
  margin: 0;
  max-height: min(42vh, 320px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.people-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.people-list li {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  box-shadow: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.people-list li.user-link {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.people-list li.user-link:active,
.people-list li.user-link:hover {
  border-color: var(--accent, #2f7a45);
}
.people-list li.user-link a.user-link-a {
  color: var(--accent, #2f7a45);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 650;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}
.people-list li span {
  font-size: 0.92rem;
  font-weight: 650;
  word-break: break-word;
}
.people-list .user-spent {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}
.field input {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
}

.rate-box {
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 0 0 18px;
  font-size: 0.98rem;
  line-height: 1.4;
}
.rate-box strong {
  color: var(--accent-2);
  font-weight: 800;
  white-space: nowrap;
}

.set-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.set-row:last-child { border-bottom: 0; }
.set-row span { color: var(--muted); }
.btn.block { width: 100%; }

.panel-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.theme-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.theme-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 8px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}
.theme-btn.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.content {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  gap: var(--gap);
}
.panel { display: none; animation: fade 0.18s ease; }
.panel.on {
  display: grid;
  gap: var(--gap);
}
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.card, .drop, .status, .empty {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card {
  padding: 18px 16px;
  margin: 0;
}
.card.focus { padding: 20px 16px; }

.stepper {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
}
.stepper-btn {
  height: 56px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 14px;
  font-size: 1.6rem;
  font-weight: 600;
  cursor: pointer;
}
.stepper-btn:active { transform: scale(0.97); }
.qty-input {
  height: 56px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 14px;
  text-align: center;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  outline: none;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.qty-input:focus {
  border-color: var(--accent);
}

.quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 0 0 18px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 0;
  font-weight: 750;
  font-size: 1rem;
  cursor: pointer;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 750;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.pay,
.btn.run {
  background: var(--accent) !important;
  color: var(--accent-ink) !important;
  border: 0;
}
.btn.run {
  flex: 1;
  background: var(--accent-2) !important;
  min-height: 52px;
}
.btn.pay {
  min-width: 120px;
  min-height: 52px;
  flex: 0 0 auto;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  min-height: 52px;
  padding-inline: 16px;
}
.btn.dl {
  background: var(--accent-soft) !important;
  color: var(--accent-2) !important;
  padding: 10px 14px;
  font-size: 0.92rem;
  white-space: nowrap;
}
.chip.on {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--accent-2) !important;
}
.paybox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--accent-soft) !important;
}
.paybox-text { min-width: 0; }
.paybox-label { color: var(--muted); font-size: 0.78rem; margin-bottom: 2px; }
.paybox-formula {
  color: var(--muted);
  font-size: 0.86rem;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.paybox-sum {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.status {
  padding: 14px 16px;
  margin: 0;
  display: grid;
  gap: 12px;
}
.status-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 650;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
  flex: 0 0 auto;
}
.status-item.ok .dot { background: var(--ok); }
.status-item.bad .dot { background: #c0392b; }

.drop {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 32px 18px;
  text-align: center;
  cursor: pointer;
  margin: 0;
  border-style: dashed;
}
.drop input { display: none; }
.drop-ico {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.drop-title { font-weight: 800; font-size: 1.05rem; }
.drop-hint { color: var(--muted); font-size: 0.88rem; line-height: 1.4; max-width: 280px; }

.files, .history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.files li, .history li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}
.files li span, .history .name {
  font-size: 0.92rem;
  font-weight: 650;
  word-break: break-word;
}
.files li.user-link {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.files li.user-link:active,
.files li.user-link:hover {
  border-color: var(--accent, #2f7a45);
}
.files li.user-link a.user-link-a {
  color: var(--accent, #2f7a45);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 0.92rem;
  font-weight: 650;
  word-break: break-word;
  display: block;
  width: 100%;
}
.history .meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  font-weight: 500;
}

.row-actions {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.hint, .msg {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0;
  padding: 0 2px;
}
.msg { min-height: 1.2em; }
.msg.ok { color: var(--ok); }
.msg.err { color: #c0392b; }

.empty {
  padding: 36px 20px;
  text-align: center;
  display: grid;
  gap: 10px;
  justify-items: center;
  margin: 0;
}
.empty-title { font-weight: 800; font-size: 1.1rem; }
.empty-text { color: var(--muted); font-size: 0.92rem; margin: 0 0 6px; }

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--dock-h) + env(safe-area-inset-bottom));
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.dock-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  display: grid;
  gap: 4px;
  justify-items: center;
  align-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 4px;
}
.dock-item.on {
  background: var(--accent-soft) !important;
  color: var(--accent-2) !important;
}
.dock-ico {
  height: 18px;
  width: 18px;
  display: grid;
  place-items: center;
  line-height: 0;
}
.dock-ico svg {
  display: block;
}

.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 20px;
}
.gate-card {
  width: min(100%, 360px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate .brand {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 12px;
}
.gate p { color: var(--muted); margin: 0; line-height: 1.45; }

.loader {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(8px);
}
.loader-card {
  width: min(100%, 280px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px 22px 24px;
  text-align: center;
}
.orbit {
  width: 84px;
  height: 84px;
  margin: 0 auto 16px;
  position: relative;
}
.orbit-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
}
.orbit-ring.delay {
  inset: 10px;
  border-top-color: var(--accent-2);
  animation-duration: 1.6s;
  animation-direction: reverse;
}
.orbit-core {
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7edc8a, var(--accent));
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent);
  animation: pulse 1.4s ease-in-out infinite;
}
.orbit-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  top: 50%;
  left: 50%;
  margin: -4px;
  animation: swing 1.8s ease-in-out infinite;
}
.orbit-dot.d1 { --a: 0deg; }
.orbit-dot.d2 { --a: 120deg; animation-delay: 0.15s; }
.orbit-dot.d3 { --a: 240deg; animation-delay: 0.3s; }
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { transform: scale(0.92); opacity: 0.85; }
  50% { transform: scale(1.05); opacity: 1; }
}
@keyframes swing {
  from { transform: rotate(var(--a)) translateX(34px) rotate(calc(-1 * var(--a))); }
  to { transform: rotate(calc(var(--a) + 360deg)) translateX(34px) rotate(calc(-1 * (var(--a) + 360deg))); }
}
.loader-title {
  font-weight: 800;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.loader-sub {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}
