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

:root {
  color-scheme: light dark;
  --page: var(--tg-theme-bg-color, #f4f6fb);
  --surface: var(--tg-theme-section-bg-color, rgba(255, 255, 255, 0.88));
  --surface-solid: var(--tg-theme-section-bg-color, #ffffff);
  --surface-soft: var(--tg-theme-secondary-bg-color, #edf1f7);
  --text: var(--tg-theme-text-color, #111827);
  --muted: var(--tg-theme-hint-color, #667085);
  --accent: var(--tg-theme-button-color, #5965f3);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #5965f3);
  --line: var(--tg-theme-section-separator-color, rgba(17, 24, 39, 0.09));
  --green: #20b486;
  --orange: #f79009;
  --red: #ef5350;
  --violet: #7a5af8;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.09);
  --shadow-small: 0 6px 20px rgba(16, 24, 40, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { min-height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 34rem),
    var(--page);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button { color: inherit; }
svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.ambient {
  position: fixed;
  width: 18rem;
  height: 18rem;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  opacity: .18;
}
.ambient-one { right: -8rem; top: 10rem; background: var(--violet); }
.ambient-two { left: -10rem; bottom: 4rem; background: var(--green); }

.app-shell {
  position: relative;
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 20px calc(48px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 2px 14px;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  border-bottom: 1px solid transparent;
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  color: white;
  background: linear-gradient(145deg, var(--accent), var(--violet));
  border-radius: 14px;
  box-shadow: 0 9px 24px color-mix(in srgb, var(--accent) 28%, transparent);
}
.brand-mark svg { width: 25px; height: 25px; stroke-width: 1.9; }
.brand-copy { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.brand-copy strong { font-size: 15px; letter-spacing: -.02em; }
.brand-copy span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
}

.step-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin: 8px 0 24px; padding: 0 6px; }
.step-line { height: 1px; background: var(--line); }
.step-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.step-tab span { display: grid; width: 27px; height: 27px; place-items: center; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 9px; font-size: 12px; font-weight: 800; }
.step-tab b { font-size: 13px; }
.step-tab.active { color: var(--text); }
.step-tab.active span { color: var(--accent-text); background: var(--accent); border-color: transparent; box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 22%, transparent); }
.step-tab:disabled { cursor: default; opacity: .45; }

.screen { animation: screen-in .28s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(7px); } }

.hero-card {
  position: relative;
  overflow: hidden;
  padding: 28px;
  color: #f8f9ff;
  background:
    radial-gradient(circle at 88% 12%, rgba(143, 155, 255, .34), transparent 32%),
    linear-gradient(145deg, #11172d, #202958 68%, #313572);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 26px;
  box-shadow: 0 24px 55px rgba(13, 20, 48, .2);
}
.hero-card::after { content: "@"; position: absolute; right: 18px; bottom: -50px; color: rgba(255,255,255,.055); font-size: 150px; font-weight: 900; line-height: 1; transform: rotate(-8deg); }
.hero-card .eyebrow { color: #aeb8ff; }
.hero-card h1 { position: relative; z-index: 1; max-width: 540px; margin-top: 10px; font-size: clamp(29px, 7vw, 44px); line-height: 1.04; letter-spacing: -.045em; }
.hero-card > p { position: relative; z-index: 1; max-width: 550px; margin-top: 14px; color: rgba(244, 246, 255, .72); font-size: 14px; }
.hero-facts { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 24px; color: rgba(255,255,255,.88); font-size: 12px; font-weight: 700; }
.hero-facts span { display: flex; align-items: center; gap: 7px; }
.fact-dot { width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(255,255,255,.07); }
.fact-dot-green { background: #43d9a7; }
.fact-dot-violet { background: #a5adff; }

.eyebrow { display: inline-block; color: var(--accent); font-size: 10px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-top: 30px; }
.section-heading h1, .section-heading h2 { margin-top: 3px; font-size: 24px; line-height: 1.1; letter-spacing: -.035em; }
.section-note { max-width: 540px; margin: 8px 0 16px; color: var(--muted); font-size: 13px; }
.count-pill { display: grid; min-width: 31px; height: 31px; place-items: center; padding: 0 9px; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; font-weight: 800; }

.panel {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-small);
  backdrop-filter: blur(15px);
}
.form-panel { display: grid; grid-template-columns: 1.1fr .9fr; gap: 13px; margin-top: 12px; }
.form-panel .button, .form-panel .form-error { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > span { padding-left: 2px; color: var(--muted); font-size: 11px; font-weight: 750; }
.control {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: 13px;
  outline: 0;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.control::placeholder { color: color-mix(in srgb, var(--muted) 72%, transparent); }
.control:focus { background: var(--surface-solid); border-color: color-mix(in srgb, var(--accent) 50%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent); }
select.control { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-repeat: no-repeat; background-size: 5px 5px; padding-right: 34px; }

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 17px;
  border: 0;
  border-radius: 14px;
  font-weight: 780;
  letter-spacing: -.01em;
  cursor: pointer;
  transition: transform .13s ease, opacity .13s ease, box-shadow .13s ease;
}
.button:active { transform: scale(.975); }
.button:disabled { cursor: default; opacity: .42; transform: none; }
.button svg { width: 18px; height: 18px; }
.button-primary { color: var(--accent-text); background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, var(--violet))); box-shadow: 0 9px 22px color-mix(in srgb, var(--accent) 23%, transparent); }
.button-secondary { color: var(--text); background: var(--surface-soft); border: 1px solid var(--line); }
.button-quiet { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.button-large { width: 100%; min-height: 54px; margin-top: 16px; font-size: 16px; }

.form-error { min-height: 0; color: var(--red); font-size: 12px; }
.form-error:empty { display: none; }

.stack-list { display: flex; flex-direction: column; gap: 10px; }
.account-card, .chat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 17px;
  box-shadow: var(--shadow-small);
}
.avatar { display: grid; width: 43px; height: 43px; flex: 0 0 auto; place-items: center; color: white; background: linear-gradient(145deg, var(--accent), var(--violet)); border-radius: 14px; font-size: 14px; font-weight: 850; }
.avatar.chat-avatar { color: var(--green); background: color-mix(in srgb, var(--green) 13%, var(--surface-solid)); }
.card-body { min-width: 0; flex: 1; }
.card-title { overflow: hidden; font-size: 14px; font-weight: 780; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { overflow: hidden; margin-top: 2px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.card-actions { display: flex; align-items: center; gap: 6px; }
.mini-button { min-height: 34px; padding: 7px 10px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 10px; font-size: 11px; font-weight: 750; cursor: pointer; }
.mini-button.danger { color: var(--red); }
.status-badge { display: inline-flex; align-items: center; padding: 5px 9px; color: var(--green); background: color-mix(in srgb, var(--green) 11%, transparent); border-radius: 999px; font-size: 10px; font-weight: 850; text-transform: uppercase; }

.empty-state { padding: 22px; color: var(--muted); background: color-mix(in srgb, var(--surface) 65%, transparent); border: 1px dashed color-mix(in srgb, var(--muted) 28%, transparent); border-radius: 17px; text-align: center; }
.empty-state strong { display: block; color: var(--text); font-size: 13px; }
.empty-state span { font-size: 11px; }

.jobs-heading { align-items: center; margin-top: 8px; }
.text-button { padding: 7px 10px; color: var(--link); background: transparent; border: 0; font-size: 12px; font-weight: 800; cursor: pointer; }
.boundary-note { display: flex; gap: 12px; margin: 16px 0; padding: 15px; color: #e9eaff; background: linear-gradient(135deg, #202852, #252b60); border: 1px solid rgba(255,255,255,.07); border-radius: 18px; box-shadow: 0 14px 35px rgba(25, 31, 72, .16); }
.note-icon { display: grid; width: 37px; height: 37px; flex: 0 0 auto; place-items: center; color: #aeb5ff; background: rgba(255,255,255,.08); border-radius: 12px; }
.note-icon svg { width: 20px; height: 20px; }
.boundary-note strong { font-size: 13px; }
.boundary-note p { margin-top: 3px; color: rgba(235,237,255,.65); font-size: 11px; }

.composer { display: grid; grid-template-columns: 1.25fr .75fr; gap: 13px; }
.switch-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 11px 2px; cursor: pointer; }
.switch-row span { display: flex; flex-direction: column; }
.switch-row b { font-size: 13px; }
.switch-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i { position: relative; width: 43px; height: 25px; flex: 0 0 auto; background: color-mix(in srgb, var(--muted) 22%, transparent); border-radius: 999px; transition: .18s ease; }
.switch-row i::after { content: ""; position: absolute; width: 19px; height: 19px; top: 3px; left: 3px; background: white; border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: .18s ease; }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(18px); }
.composer .button, .composer .form-error { grid-column: 1 / -1; }

.queue-heading { display: flex; align-items: center; justify-content: space-between; margin: 26px 2px 12px; }
.queue-heading h2 { font-size: 16px; letter-spacing: -.02em; }
.launch-bar { display: grid; grid-template-columns: .35fr .65fr; gap: 10px; margin-top: 14px; }

.dashboard { margin-top: 30px; padding-top: 28px; border-top: 1px solid var(--line); }
.dashboard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dashboard-head h2 { margin-top: 3px; font-size: 22px; letter-spacing: -.03em; }
.live-pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); border-radius: 999px; font-size: 10px; font-weight: 850; text-transform: uppercase; }
.live-pill i { width: 6px; height: 6px; background: currentColor; border-radius: 50%; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 12%, transparent); animation: pulse 1.5s ease infinite; }
.live-pill.done { color: var(--accent); }
.live-pill.done i { animation: none; }
.live-pill.stopped { color: var(--red); }
.live-pill.stopped i { animation: none; }
@keyframes pulse { 50% { opacity: .38; } }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.metric { padding: 14px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-small); }
.metric span { display: block; overflow: hidden; font-size: clamp(20px, 6vw, 28px); font-weight: 850; letter-spacing: -.04em; text-overflow: ellipsis; }
.metric small { color: var(--muted); font-size: 9px; font-weight: 750; text-transform: uppercase; }
.metric-accent span { color: var(--accent); }
.dashboard-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 12px 0 15px; }

.job-card { padding: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-small); }
.job-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.job-name { overflow: hidden; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.job-account { margin-top: 2px; color: var(--muted); font-size: 10px; }
.job-status { flex: 0 0 auto; padding: 5px 8px; border-radius: 999px; font-size: 9px; font-weight: 850; text-transform: uppercase; }
.job-status.running, .job-status.queued { color: var(--orange); background: color-mix(in srgb, var(--orange) 11%, transparent); }
.job-status.completed { color: var(--green); background: color-mix(in srgb, var(--green) 11%, transparent); }
.job-status.failed, .job-status.cancelled { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.job-track { position: relative; overflow: hidden; height: 5px; margin: 13px 0 9px; background: var(--surface-soft); border-radius: 999px; }
.job-track i { position: absolute; inset: 0; background: var(--green); transform-origin: left; }
.job-track.indeterminate i { width: 42%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: scanning 1.45s ease-in-out infinite; }
.job-track.failed i { background: var(--red); }
@keyframes scanning { from { transform: translateX(-110%); } to { transform: translateX(260%); } }
.job-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 5px 14px; color: var(--muted); font-size: 10px; }
.job-meta strong { color: var(--text); }
.job-boundary { margin-top: 6px; color: var(--muted); font-size: 10px; }
.job-wait { margin-top: 8px; padding: 8px 10px; color: var(--orange); background: color-mix(in srgb, var(--orange) 9%, transparent); border-radius: 10px; font-size: 10px; font-weight: 700; }
.job-error { margin-top: 8px; color: var(--red); font-size: 11px; }
.job-actions { display: flex; gap: 8px; margin-top: 11px; }

.modal { position: fixed; z-index: 100; inset: 0; display: grid; align-items: end; justify-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 9, 20, .52); backdrop-filter: blur(8px); }
.modal-sheet { position: relative; width: min(100%, 520px); padding: 12px 22px calc(24px + var(--safe-bottom)); background: var(--surface-solid); border: 1px solid var(--line); border-radius: 25px 25px 0 0; box-shadow: 0 -20px 60px rgba(5,9,20,.2); animation: sheet-in .22s ease both; }
@keyframes sheet-in { from { transform: translateY(100%); } }
.modal-handle { width: 34px; height: 4px; margin: 0 auto 20px; background: var(--line); border-radius: 999px; }
.modal-sheet h3 { margin-top: 4px; font-size: 23px; letter-spacing: -.03em; }
.modal-sheet > p:not(.form-error) { margin: 5px 0 16px; color: var(--muted); font-size: 12px; }
.code-control { margin-bottom: 2px; text-align: center; font-size: 21px; font-weight: 800; letter-spacing: .25em; }
.modal-actions { display: grid; grid-template-columns: .42fr .58fr; gap: 9px; margin-top: 14px; }

.toast { position: fixed; z-index: 150; left: 50%; bottom: calc(20px + var(--safe-bottom)); max-width: calc(100vw - 32px); padding: 11px 16px; color: #fff; background: #111827; border: 1px solid rgba(255,255,255,.1); border-radius: 13px; box-shadow: 0 16px 35px rgba(0,0,0,.25); font-size: 12px; font-weight: 750; text-align: center; transform: translateX(-50%); animation: toast-in .2s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 560px) {
  .app-shell { padding-right: 14px; padding-left: 14px; }
  .hero-card { padding: 24px 20px; border-radius: 22px; }
  .form-panel, .composer { grid-template-columns: 1fr; }
  .field-wide, .composer .button, .composer .form-error, .switch-row { grid-column: 1; }
  .section-heading { margin-top: 25px; }
}

@media (max-width: 390px) {
  .step-tab b { display: none; }
  .launch-bar { grid-template-columns: .4fr .6fr; }
  .launch-bar .button { padding-inline: 10px; font-size: 13px; }
  .account-card, .chat-card { gap: 9px; padding: 12px; }
  .avatar { width: 39px; height: 39px; }
  .mini-button { padding-inline: 8px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: var(--tg-theme-bg-color, #0c101b);
    --surface: var(--tg-theme-section-bg-color, rgba(25, 31, 46, .86));
    --surface-solid: var(--tg-theme-section-bg-color, #171d2b);
    --surface-soft: var(--tg-theme-secondary-bg-color, #22293a);
    --text: var(--tg-theme-text-color, #f4f6fa);
    --muted: var(--tg-theme-hint-color, #929bad);
    --line: var(--tg-theme-section-separator-color, rgba(255,255,255,.09));
    --shadow: 0 18px 50px rgba(0,0,0,.2);
    --shadow-small: 0 6px 20px rgba(0,0,0,.14);
  }
  .hero-card { background: radial-gradient(circle at 88% 12%, rgba(143,155,255,.25), transparent 32%), linear-gradient(145deg, #151b32, #202753 68%, #292e66); }
}
