:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f1f3f5);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14212b);
  --muted: var(--tg-theme-hint-color, #73808a);
  --line: rgba(100, 116, 139, 0.18);
  --accent: #ff3b30;
  --accent-deep: #d92b21;
  --success: #168a57;
  --success-soft: #e7f7ef;
  --shadow: 0 12px 30px rgba(20, 33, 43, 0.08);
  --radius: 22px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 100% 0, rgba(255, 59, 48, 0.09), transparent 30%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 580px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2 { margin: 0; letter-spacing: -0.035em; }
h1 { font-size: 27px; line-height: 1.1; }
h2 { font-size: 24px; }

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 5px 14px rgba(20, 33, 43, 0.06);
  font-size: 25px;
  cursor: pointer;
}

.icon-button.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 150px;
  padding: 24px;
  border-radius: 28px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.08), transparent 55%),
    linear-gradient(135deg, #101c25, #263540);
  box-shadow: 0 18px 34px rgba(15, 23, 32, 0.2);
}

.summary-copy { display: flex; flex-direction: column; gap: 7px; }
.summary-label { color: rgba(255,255,255,0.68); font-size: 13px; }
.summary-copy strong { font-size: clamp(30px, 9vw, 43px); letter-spacing: -0.05em; }
.summary-copy > span:last-child { color: rgba(255,255,255,0.68); font-size: 12px; }

.progress-ring {
  --progress: 0deg;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress), rgba(255,255,255,0.14) 0);
  position: relative;
}

.progress-ring::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: #23323c;
}

.progress-ring span { z-index: 1; font-size: 13px; font-weight: 800; }

.toolbar { margin-top: 18px; }
.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(20, 33, 43, 0.04);
}
.search-field span { color: var(--muted); font-size: 24px; transform: rotate(-15deg); }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.search-field input::placeholder { color: var(--muted); }

.segments {
  display: flex;
  gap: 8px;
  margin: 13px -16px 0;
  padding: 0 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segments::-webkit-scrollbar { display: none; }
.segment {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 15px;
  background: var(--surface);
  white-space: nowrap;
  cursor: pointer;
}
.segment.active { border-color: #15232d; color: #fff; background: #15232d; }

.status-tabs {
  display: grid;
  grid-template-columns: .8fr 1.1fr 1.1fr;
  margin-top: 12px;
  padding: 4px;
  border-radius: 15px;
  background: rgba(100, 116, 139, 0.1);
}
.status-tab {
  border: 0;
  border-radius: 12px;
  padding: 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}
.status-tab span { margin-left: 4px; font-size: 12px; }
.status-tab.active { color: var(--text); background: var(--surface); box-shadow: 0 3px 12px rgba(20,33,43,.07); }

.collection-list { display: grid; gap: 11px; margin-top: 14px; }
.route-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 0;
}
.route-heading strong { font-size: 16px; }
.route-heading span { color: var(--muted); text-align: right; font-size: 12px; font-weight: 700; }
.collection-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 7px 22px rgba(20, 33, 43, 0.045);
}
.collection-card[data-action="details"] { cursor: pointer; }
.collection-card[data-action="details"]:active { transform: scale(.99); }
.collection-card.collected { opacity: 0.72; }
.card-location { display: flex; align-items: center; gap: 7px; color: var(--accent); font-size: 12px; font-weight: 800; }
.location-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.card-name { margin: 7px 0 4px; font-size: 16px; font-weight: 750; line-height: 1.25; }
.card-building { color: var(--muted); font-size: 12px; }
.card-contacts { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.debt-age { margin-top: 9px; color: var(--text); font-size: 11px; font-weight: 750; }
.debt-age span { color: var(--accent); }
.card-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 13px; }
.card-amount { white-space: nowrap; font-size: 17px; font-weight: 850; }
.collect-button {
  border: 0;
  border-radius: 12px;
  padding: 9px 13px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
}
.collect-button.manual { color: var(--text); background: rgba(100,116,139,.12); box-shadow: none; }
.print-button { border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; color: var(--text); background: var(--surface); font-size: 12px; font-weight: 800; cursor: pointer; white-space: nowrap; }
.collected-mark { color: var(--success); font-size: 13px; font-weight: 800; }
.ready-mark { color: var(--success); text-align: right; font-size: 11px; font-weight: 800; }
.change-mark { max-width: 130px; color: #b45309; text-align: right; font-size: 12px; font-weight: 850; line-height: 1.2; }
.waiting-mark { max-width: 110px; color: var(--muted); text-align: right; font-size: 10px; font-weight: 700; line-height: 1.2; }

.empty-state { padding: 44px 25px; text-align: center; color: var(--muted); }
.empty-icon { display: block; margin-bottom: 12px; font-size: 38px; }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--text); font-size: 18px; }

.loading-card { height: 112px; border-radius: var(--radius); background: linear-gradient(100deg, rgba(100,116,139,.08) 25%, rgba(100,116,139,.15) 40%, rgba(100,116,139,.08) 60%); background-size: 300% 100%; animation: shimmer 1.4s infinite; }
.loading-card.short { height: 94px; }
@keyframes shimmer { to { background-position: -150% 0; } }

.sync-note { display: flex; justify-content: center; align-items: center; gap: 7px; padding: 18px 0 0; color: var(--muted); font-size: 11px; }
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 10; background: rgba(7, 13, 18, 0.48); backdrop-filter: blur(3px); }
.confirm-sheet {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: 0;
  width: min(100%, 580px);
  padding: 13px 20px calc(22px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  transform: translateX(-50%);
  box-shadow: 0 -18px 50px rgba(7, 13, 18, 0.22);
}
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 20px; border-radius: 10px; background: var(--line); }
.sheet-close { position: absolute; top: 17px; right: 18px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: rgba(100,116,139,.1); font-size: 22px; }
.confirm-location { margin: 8px 0 20px; color: var(--muted); }
.manual-warning { margin: -9px 0 17px; padding: 11px 12px; border: 1px solid rgba(255, 149, 0, .25); border-radius: 12px; color: #9a5b00; background: rgba(255, 149, 0, .1); font-size: 12px; line-height: 1.35; }
.form-label { display: flex; justify-content: space-between; margin: 14px 0 7px; font-size: 12px; font-weight: 800; }
.form-label span { color: var(--muted); font-weight: 500; }
.amount-field { display: flex; align-items: center; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 15px; background: var(--bg); }
.amount-field:focus-within { border-color: var(--accent); }
.amount-field input { width: 100%; padding: 14px 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 22px; font-weight: 800; }
.amount-field span { font-size: 19px; color: var(--muted); }
textarea { width: 100%; resize: none; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 15px; outline: 0; color: var(--text); background: var(--bg); }
textarea:focus { border-color: var(--accent); }
.confirm-button { width: 100%; margin-top: 17px; padding: 15px; border: 0; border-radius: 15px; color: #fff; background: var(--accent); font-weight: 850; box-shadow: 0 10px 22px rgba(255,59,48,.22); }
.confirm-button:disabled { opacity: .6; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--accent); text-align: center; font-size: 12px; }

.details-sheet {
  position: fixed;
  z-index: 13;
  left: 50%;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(100%, 580px);
  max-height: 92vh;
  padding: 13px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  transform: translateX(-50%);
  box-shadow: 0 -18px 50px rgba(7, 13, 18, 0.22);
}
.details-location { margin: 6px 0 14px; color: var(--muted); font-size: 12px; }
.details-total { display: flex; flex-direction: column; gap: 3px; padding: 15px; border-radius: 17px; color: #fff; background: #15232d; }
.details-total span, .details-total small { color: rgba(255,255,255,.67); }
.details-total strong { font-size: 27px; letter-spacing: -.035em; }
.details-body { display: grid; gap: 10px; margin: 13px -3px 0; padding: 0 3px 8px; overflow-y: auto; }
.details-loading, .details-empty { padding: 28px 14px; color: var(--muted); text-align: center; }
.invoice-card { padding: 14px; border: 1px solid var(--line); border-radius: 17px; background: var(--bg); }
.invoice-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.invoice-head > div { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.invoice-head strong { font-size: 13px; }
.invoice-head > strong { color: var(--accent); white-space: nowrap; font-size: 14px; }
.invoice-head span, .invoice-caption { color: var(--muted); font-size: 10px; }
.invoice-caption { margin-top: 3px; }
.invoice-items { display: grid; gap: 8px; margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--line); }
.invoice-item { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; line-height: 1.3; }
.invoice-item span { min-width: 0; }
.invoice-item small { color: var(--muted); }
.invoice-item strong { white-space: nowrap; }
.invoice-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.pdf-button { border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; color: var(--text); background: var(--surface); font-weight: 800; }
.details-sheet .confirm-button { flex: 0 0 auto; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 12px 17px; border-radius: 999px; color: #fff; background: #15232d; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; white-space: nowrap; }
[hidden] { display: none !important; }

@media (prefers-color-scheme: dark) {
  :root { --surface: var(--tg-theme-secondary-bg-color, #17232c); --bg: var(--tg-theme-bg-color, #0d151b); --line: rgba(203, 213, 225, 0.12); --success-soft: #123829; --shadow: 0 12px 30px rgba(0,0,0,.2); }
  .segment.active { background: #e8edf0; border-color: #e8edf0; color: #15232d; }
}

@media (max-width: 370px) {
  .summary-card { padding: 20px; }
  .progress-ring { width: 64px; height: 64px; flex-basis: 64px; }
  .collection-card { grid-template-columns: 1fr; padding: 15px; }
  .card-side { align-items: stretch; gap: 8px; }
  .card-amount, .ready-mark, .waiting-mark, .change-mark { max-width: none; text-align: left; }
  .waiting-mark { max-width: none; }
  .collect-button { width: 100%; }
}


/* Dark banking-style work interface: high contrast and one clear action. */
:root{color-scheme:dark;--bg:#090a0d;--surface:#17181d;--text:#f7f8fb;--muted:#9699a5;--line:rgba(255,255,255,.09);--accent:#3986ff;--accent-deep:#226be0;--success:#43d39a;--success-soft:rgba(67,211,154,.12);--shadow:0 18px 42px rgba(0,0,0,.34);--radius:20px}
body{background:radial-gradient(95% 45% at 50% -12%,rgba(57,134,255,.17),transparent 66%),var(--bg);color:var(--text)}
.app-shell{width:min(100%,620px);padding:calc(20px + env(safe-area-inset-top)) 15px calc(30px + env(safe-area-inset-bottom))}
.topbar{margin-bottom:19px}.eyebrow{color:#75a9ff;font-size:10px;letter-spacing:.15em}.topbar h1{font-size:28px;color:#fff}.icon-button{border-color:rgba(255,255,255,.11);background:#1c1d23;color:#fff;box-shadow:none}
.summary-card{min-height:158px;border:1px solid rgba(255,255,255,.1);border-radius:25px;background:linear-gradient(138deg,#202229,#111217 68%);box-shadow:0 20px 42px rgba(0,0,0,.34)}
.summary-label,.summary-copy>span:last-child{color:#aeb1bb}.summary-copy strong{color:#fff}.progress-ring{background:conic-gradient(var(--accent) var(--progress),rgba(255,255,255,.12) 0);box-shadow:0 0 0 1px rgba(255,255,255,.06)}.progress-ring::after{background:#1e2027}
.search-field{border-color:rgba(255,255,255,.09);border-radius:15px;background:#17181d;box-shadow:none}.search-field input{color:#fff}.search-field input::placeholder,.search-field span{color:#858995}
.segment{border-color:rgba(255,255,255,.1);background:#17181d;color:#c4c6ce}.segment.active{border-color:#3986ff;background:#253d65;color:#eaf2ff}.status-tabs{background:#15161a;border:1px solid rgba(255,255,255,.06)}.status-tab{color:#858995}.status-tab.active{background:#2a2b31;color:#fff;box-shadow:none}
.route-heading strong{color:#fff}.route-heading span{color:#8e93a1}.collection-card{border-color:rgba(255,255,255,.09);border-radius:19px;background:linear-gradient(140deg,#1c1d23,#15161a);box-shadow:0 10px 24px rgba(0,0,0,.18)}.collection-card.collected{background:#121b18;opacity:.82}.card-location{color:#72a7ff}.card-name,.card-amount{color:#fff}.card-building,.card-contacts{color:#9296a2}.debt-age{color:#d9dbe2}.debt-age span{color:#71a7ff}.collect-button{border-radius:11px;background:linear-gradient(135deg,#4794ff,#2673e9);box-shadow:0 8px 18px rgba(34,107,224,.25)}.collect-button.manual{background:#2a2c33;color:#e5e7ee}.print-button{border-color:rgba(255,255,255,.1);background:#25262d;color:#e7e9ef}.ready-mark{color:#51daa3}.waiting-mark{color:#9195a1}.change-mark{color:#ffbf65}.collected-mark{color:#57dca7}
.empty-state{color:#9094a0}.empty-state strong{color:#fff}.loading-card{background:linear-gradient(100deg,#15161a 25%,#24262d 40%,#15161a 60%)}.sync-note{color:#848894}.sync-dot{background:#4bd69f;box-shadow:0 0 10px rgba(75,214,159,.65)}
.sheet-backdrop{background:rgba(0,0,0,.72);backdrop-filter:blur(6px)}.confirm-sheet,.details-sheet{border:1px solid rgba(255,255,255,.1);border-bottom:0;background:#17181d;box-shadow:0 -18px 52px rgba(0,0,0,.52)}.sheet-handle{background:#555862}.sheet-close{background:#292a30;color:#fff}.confirm-location,.details-location{color:#9b9faa}.manual-warning{border-color:rgba(255,190,94,.25);background:rgba(255,181,56,.09);color:#ffc878}.form-label{color:#eff0f4}.form-label span{color:#8f939e}.amount-field{border-color:rgba(255,255,255,.13);background:#101116}.amount-field:focus-within,textarea:focus{border-color:#4c93ff}.amount-field input,textarea{color:#fff;background:transparent}.amount-field span{color:#8f939e}textarea{border-color:rgba(255,255,255,.13);background:#101116}.confirm-button{border-radius:14px;background:linear-gradient(135deg,#4794ff,#2673e9);box-shadow:0 10px 22px rgba(34,107,224,.26)}.form-error{color:#ff8997}
.details-total{border:1px solid rgba(255,255,255,.08);background:linear-gradient(135deg,#22242b,#16171c)}.details-total span,.details-total small{color:#aaadb7}.invoice-card{border-color:rgba(255,255,255,.09);background:#101116}.invoice-head>strong{color:#73a8ff}.invoice-head span,.invoice-caption,.invoice-item small,.invoice-footer{color:#9296a1}.invoice-items{border-color:rgba(255,255,255,.08)}.pdf-button{border-color:rgba(255,255,255,.1);background:#25262d;color:#edf0f6}.toast{background:#2a2c33;color:#fff}
@media(max-width:370px){.summary-card{padding:20px}.collection-card{background:#191a20}}
