:root {
  --app-bg: var(--tg-theme-secondary-bg-color, #f2f5f9);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-soft: color-mix(in srgb, var(--surface) 94%, var(--accent) 6%);
  --text: var(--tg-theme-text-color, #182230);
  --muted: var(--tg-theme-hint-color, #64748b);
  --accent: var(--tg-theme-button-color, #1769e0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #1769e0);
  --danger: var(--tg-theme-destructive-text-color, #d92d20);
  --border: color-mix(in srgb, var(--text) 13%, transparent);
  --shadow: 0 10px 32px rgba(27, 39, 53, 0.08);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--app-bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--app-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 92% 1%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 30rem),
    var(--app-bg);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:not(:disabled),
select:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 34%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1040px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(14px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(24px + var(--safe-bottom))
    calc(16px + var(--safe-left));
}

.app-header {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 52px;
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: var(--accent-text);
  background: var(--accent);
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 80%, #071f4d), var(--accent));
  box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.brand-copy p {
  margin: 0;
}

.brand-copy h1 {
  overflow: hidden;
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.beta-badge {
  margin-left: auto;
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

main {
  padding-top: clamp(26px, 7vw, 54px);
}

.intro {
  max-width: 660px;
  margin-bottom: 21px;
}

.intro h2,
.intro p {
  margin: 0;
}

.intro h2 {
  max-width: 600px;
  font-size: clamp(26px, 7.6vw, 42px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.07;
}

.intro p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 20px 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.section-heading h2,
.section-heading p {
  margin: 0;
}

.section-heading h2 {
  font-size: 18px;
  line-height: 1.25;
}

.section-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.step-number {
  display: grid;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 12px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  font-size: 14px;
  font-weight: 800;
}

#search-form {
  display: grid;
  gap: 21px;
}

.field-group {
  min-width: 0;
}

.field-group > label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.select-wrap,
.money-input-wrap {
  position: relative;
}

select,
input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--surface-soft);
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

select {
  appearance: none;
  padding: 0 46px 0 14px;
  text-overflow: ellipsis;
}

.select-wrap::after {
  position: absolute;
  top: 50%;
  right: 17px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

input {
  padding: 0 49px 0 14px;
  font-variant-numeric: tabular-nums;
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 72%, transparent);
}

select:hover,
input:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
}

select:focus,
input:focus {
  border-color: var(--accent);
  outline: 0;
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}

select:disabled {
  cursor: wait;
  opacity: 0.68;
}

.money-suffix {
  position: absolute;
  top: 50%;
  right: 17px;
  color: var(--muted);
  font-weight: 700;
  transform: translateY(-50%);
}

.field-hint,
.field-error {
  margin: 6px 1px 0;
  font-size: 12px;
  line-height: 1.4;
}

.field-hint {
  color: var(--muted);
}

.field-error {
  color: var(--danger);
}

.field-error:empty {
  display: none;
}

.presets {
  display: flex;
  gap: 7px;
  margin-top: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.presets::-webkit-scrollbar {
  display: none;
}

.preset-button {
  flex: 0 0 auto;
  min-height: 35px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 650;
}

.preset-button:hover,
.preset-button.is-selected {
  border-color: color-mix(in srgb, var(--accent) 36%, transparent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.primary-button,
.secondary-button,
.text-button,
.icon-text-button {
  min-height: 46px;
  border-radius: var(--radius-md);
  font-weight: 700;
}

.primary-button {
  border: 0;
  color: var(--accent-text);
  background: var(--accent);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 25%, transparent);
}

.primary-button:hover {
  filter: brightness(1.04);
}

.primary-button:active,
.secondary-button:active,
.preset-button:active {
  transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: none;
}

.search-button {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 1px;
}

.button-icon {
  position: relative;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.button-icon::after {
  position: absolute;
  right: -4px;
  bottom: -3px;
  width: 7px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: rotate(45deg);
  transform-origin: left center;
}

.progress-panel {
  display: grid;
  gap: 18px;
  padding: 24px 18px;
}

.status-visual {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 18px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.spinner {
  width: 25px;
  height: 25px;
  border: 3px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-copy h2,
.status-copy p {
  margin: 0;
}

.status-copy h2 {
  margin-top: 5px;
  font-size: 21px;
}

#progress-message {
  max-width: 620px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

progress {
  display: block;
  width: 100%;
  height: 7px;
  margin-top: 20px;
  overflow: hidden;
  appearance: none;
  border: 0;
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--text) 9%, transparent);
}

progress::-webkit-progress-bar {
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 9%, transparent);
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--accent);
  transition: width 250ms ease;
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--accent);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.error-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 13px;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--danger) 24%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
}

.error-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--danger);
  font-weight: 800;
}

.error-copy h2,
.error-copy p {
  margin: 0;
}

.error-copy h2 {
  font-size: 16px;
}

.error-copy p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.secondary-button {
  padding: 0 15px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  color: var(--accent);
  background: var(--surface);
}

.secondary-button:hover {
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.text-button,
.icon-text-button {
  border: 0;
  color: var(--link);
  background: transparent;
}

.text-button {
  padding: 0 9px;
}

#results-section {
  animation: reveal 220ms ease both;
}

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

.results-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 15px;
}

.results-heading h2,
.results-heading p {
  margin: 0;
}

.results-heading h2 {
  margin-top: 4px;
  font-size: clamp(23px, 6vw, 32px);
  letter-spacing: -0.02em;
}

.icon-text-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
  white-space: nowrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.summary-card {
  display: flex;
  min-width: 0;
  min-height: 108px;
  flex-direction: column;
  justify-content: space-between;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.summary-card:last-child {
  grid-column: 1 / -1;
  min-height: 92px;
}

.summary-card-accent {
  border-color: transparent;
  color: var(--accent-text);
  background: var(--accent);
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 82%, #071f4d), var(--accent));
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 20%, transparent);
}

.summary-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.3;
  text-overflow: ellipsis;
}

.summary-card-accent .summary-label {
  color: color-mix(in srgb, var(--accent-text) 72%, transparent);
}

.summary-card strong {
  display: block;
  margin-top: 10px;
  overflow: hidden;
  font-size: 31px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
}

.summary-card strong.summary-text {
  font-size: 15px;
  line-height: 1.3;
  white-space: normal;
}

.summary-unit {
  margin-top: 3px;
  font-size: 11px;
  opacity: 0.75;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 20px 0 12px;
}

.results-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.download-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  white-space: nowrap;
}

.download-icon {
  font-size: 20px;
  line-height: 1;
}

.partial-warning {
  display: grid;
  gap: 4px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, #d97706 42%, transparent);
  border-radius: var(--radius-md);
  color: color-mix(in srgb, var(--text) 88%, #92400e 12%);
  background: color-mix(in srgb, #f59e0b 13%, var(--surface));
  font-size: 12px;
  line-height: 1.45;
}

.partial-warning strong {
  font-size: 13px;
}

.empty-state {
  padding: 35px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
  background: var(--surface);
}

.empty-icon {
  display: grid;
  width: 50px;
  height: 50px;
  margin: 0 auto 12px;
  place-items: center;
  border-radius: 16px;
  color: var(--muted);
  background: var(--surface-soft);
  font-weight: 800;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state h3 {
  font-size: 18px;
}

.empty-state p {
  max-width: 350px;
  margin: 7px auto 17px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.result-cards {
  display: grid;
  gap: 10px;
}

.result-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(27, 39, 53, 0.045);
}

.result-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.result-card h3,
.result-card p {
  margin: 0;
}

.result-card h3 {
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.35;
}

.result-card .inn {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.asset-value {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.result-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 15px 0;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.detail-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
}

.detail-value {
  display: block;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.4;
}

.result-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  color: var(--link);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.result-link::after {
  margin-left: 5px;
  content: "↗";
}

.table-wrap {
  display: none;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.table-debtor {
  display: block;
  min-width: 190px;
  max-width: 310px;
  font-weight: 700;
  line-height: 1.4;
}

.table-secondary {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.table-money {
  color: var(--accent);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table-link {
  color: var(--link);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

footer {
  margin-top: 26px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}

footer p {
  margin: 2px 0;
}

footer a {
  color: var(--link);
  text-decoration: none;
}

.toast {
  position: fixed;
  z-index: 20;
  right: calc(14px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  left: calc(14px + var(--safe-left));
  width: fit-content;
  max-width: min(520px, calc(100% - 28px));
  margin: 0 auto;
  padding: 12px 15px;
  border-radius: 12px;
  color: #ffffff;
  background: rgba(19, 28, 41, 0.94);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.24);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  animation: toast-in 180ms ease both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (min-width: 640px) {
  .app-shell {
    padding-right: calc(24px + var(--safe-right));
    padding-left: calc(24px + var(--safe-left));
  }

  .search-panel {
    padding: 25px;
  }

  #search-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 24px;
  }

  .search-button {
    grid-column: 1 / -1;
    width: auto;
    min-width: 220px;
    justify-self: start;
    padding: 0 28px;
  }

  .progress-panel {
    grid-template-columns: auto 1fr;
    padding: 30px;
  }

  .summary-grid {
    grid-template-columns: 0.75fr 1.2fr 1.35fr;
  }

  .summary-card,
  .summary-card:last-child {
    grid-column: auto;
    min-height: 118px;
  }
}

@media (min-width: 820px) {
  .result-cards {
    display: none;
  }

  .table-wrap {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@supports not (color: color-mix(in srgb, #000 50%, #fff)) {
  :root {
    --surface-soft: var(--surface);
    --border: rgba(100, 116, 139, 0.24);
  }
}
