:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #ff3b30);
  --radius: 14px;
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app { min-height: 100vh; padding: 20px 16px calc(24px + var(--safe-bottom)); }
.screen { display: none; animation: fade .18s ease-out; }
.app[data-screen="loading"]  .screen[data-screen="loading"],
.app[data-screen="outside"]  .screen[data-screen="outside"],
.app[data-screen="service"]  .screen[data-screen="service"],
.app[data-screen="target"]   .screen[data-screen="target"],
.app[data-screen="package"]  .screen[data-screen="package"],
.app[data-screen="pay"]      .screen[data-screen="pay"],
.app[data-screen="history"]  .screen[data-screen="history"] { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.title { font-size: 24px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.2px; }
.subtitle { color: var(--hint); margin: 0 0 20px; font-size: 15px; }
.hint { color: var(--hint); font-size: 13px; margin: 10px 4px 0; }
.hint.error { color: var(--destructive); }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.center { text-align: center; padding-top: 32px; }

.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  background: var(--section); color: var(--text);
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 14px 16px; font: inherit; cursor: pointer;
  transition: transform .08s ease, border-color .12s ease;
}
.card:active { transform: scale(.985); }
.card.selected { border-color: var(--accent); }
.card .icon { font-size: 28px; width: 40px; text-align: center; flex: none; }
.card .body { flex: 1; min-width: 0; }
.card .name { font-weight: 600; font-size: 17px; }
.card .desc { color: var(--hint); font-size: 13px; margin-top: 2px; }
.card .price { font-weight: 700; font-size: 17px; white-space: nowrap; }
.card .price small { color: var(--hint); font-weight: 500; font-size: 12px; display: block; text-align: right; }
.card .chev { color: var(--hint); font-size: 20px; }

.field {
  display: flex; align-items: center; gap: 8px;
  background: var(--section); border-radius: var(--radius); padding: 4px 6px 4px 14px;
  border: 2px solid transparent;
}
.field:focus-within { border-color: var(--accent); }
.field input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; padding: 10px 0;
}
.field input::placeholder { color: var(--hint); }
.paste {
  border: 0; background: var(--bg2); color: var(--link); font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 10px; padding: 8px 12px; cursor: pointer;
}

.link { background: none; border: 0; color: var(--link); font: inherit; font-size: 15px; padding: 8px; cursor: pointer; }
.link.subtle { color: var(--link); font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
.footer-link { text-align: center; margin-top: 28px; }

.btn {
  display: block; text-align: center; text-decoration: none; width: 100%; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; font-size: 16px;
  padding: 14px; cursor: pointer; margin-top: 10px;
}
.btn.secondary { background: var(--section); color: var(--link); }

.summary {
  background: var(--section); border-radius: var(--radius); padding: 4px 16px; margin: 20px 0 8px; text-align: left;
}
.summary .kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 15px; }
.summary .kv + .kv { border-top: 1px solid var(--bg2); }
.summary .kv .k { color: var(--hint); }
.summary .kv .v { font-weight: 600; text-align: right; word-break: break-all; }

.status-icon { font-size: 56px; line-height: 1; margin: 0 auto 18px; height: 64px; display: flex; align-items: center; justify-content: center; }
.status-icon.ok { color: #34c759; }
.status-icon.warn { }
.actions { margin-top: 16px; }

.spinner {
  width: 36px; height: 36px; border-radius: 50%; margin: 0 auto;
  border: 3px solid var(--bg2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.screen[data-screen="loading"] .spinner { margin-top: 40vh; }
@keyframes spin { to { transform: rotate(360deg); } }

.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--section); border-radius: var(--radius); padding: 12px 14px; }
.item .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.item .name { font-weight: 600; }
.item .target { font-size: 13px; margin-top: 2px; word-break: break-all; }
.item .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; color: var(--hint); }
.badge { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--bg2); color: var(--hint); white-space: nowrap; }
.badge.ok { background: rgba(52,199,89,.15); color: #28a745; }
.badge.warn { background: rgba(255,149,0,.15); color: #e08600; }
.badge.bad { background: rgba(255,59,48,.15); color: var(--destructive); }
.badge.info { background: rgba(36,129,204,.15); color: var(--link); }
.progress { height: 4px; background: var(--bg2); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .3s ease; }
.item .retry { margin-top: 10px; }
.empty { text-align: center; color: var(--hint); margin-top: 40px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(24px + var(--safe-bottom));
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; text-align: center;
  font-size: 14px; opacity: .95; z-index: 10;
}

.btn.dev-main { position: fixed; left: 16px; right: 16px; width: auto; bottom: calc(16px + var(--safe-bottom)); margin: 0; z-index: 5; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.btn.dev-main:disabled { opacity: .5; }
.btn.dev-main.busy { opacity: .7; }
.link.dev-back { position: fixed; top: 8px; left: 8px; z-index: 5; font-size: 16px; padding: 6px 10px; background: var(--bg2); border-radius: 10px; }
body:has(.dev-back:not([hidden])) .app { padding-top: 48px; }
.target-link {
  color: var(--link); font-weight: 500; text-decoration: none; word-break: break-all;
}
.target-link::after { content: " ↗"; font-size: 12px; opacity: .8; }

.card .badge { margin-left: 6px; }
.card .meta-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.notice {
  margin-top: 16px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--section); font-size: 14px; line-height: 1.4;
}
.notice .kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.notice .kv .k { color: var(--hint); }
.notice .kv .v { font-weight: 600; }
.notice .err { color: var(--destructive); margin-bottom: 6px; }
.link.dev-back { position: fixed; top: 8px; left: 8px; z-index: 5; font-size: 16px; padding: 6px 10px; background: var(--bg2); border-radius: 10px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal { background: var(--section); border-radius: 18px; padding: 20px 16px 12px; width: 100%; max-width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-text { margin: 0 4px 12px; font-size: 15px; line-height: 1.45; white-space: pre-line; }
.modal-actions .btn { margin-top: 8px; }

.item { cursor: pointer; }
.item .details { display: none; margin-top: 10px; border-top: 1px solid var(--bg2); padding-top: 4px; }
.item.expanded .details { display: block; }
.item .details .kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; }
.item .details .kv .k { color: var(--hint); }
.item .details .kv .v { font-weight: 600; text-align: right; word-break: break-all; }
.item .details .kv .v.err { color: var(--destructive); }
.item .chev-down { color: var(--hint); font-size: 12px; margin-left: 6px; transition: transform .15s ease; display: inline-block; }
.item.expanded .chev-down { transform: rotate(180deg); }
.item .actions-row { display: flex; gap: 8px; }
.item .actions-row .btn { margin-top: 10px; }

.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--section); color: var(--link);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.icon-btn:active svg { transform: rotate(180deg); }
.icon-btn svg { transition: transform .3s ease; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
.row.between { margin-bottom: 16px; }
.row.between .title { margin: 0; }
