:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --panel: #17191d;
  --panel-2: #202329;
  --panel-3: #292d34;
  --line: #343840;
  --text: #f7f4ef;
  --muted: #a6a8ae;
  --accent: #ff843d;
  --accent-2: #ffab74;
  --danger: #ff6663;
  --warning: #ffc65c;
  --success: #54d18b;
  --radius: 20px;
  --shadow: 0 18px 55px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 92% -10%, rgba(255, 132, 61, .14), transparent 34rem),
    linear-gradient(180deg, #121418 0, var(--bg) 30rem);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button { color: inherit; }

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

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled { cursor: default; opacity: .45; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(66px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  background: rgba(13, 14, 16, .84);
  backdrop-filter: blur(18px);
}

.brand, .head-actions, .stage, .modal-head, .row-actions, .typing-row, .result-tools {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }
.brand img { width: 38px; height: 38px; border-radius: 11px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.2px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.head-actions { gap: 8px; }

.icon-button, .avatar, .close {
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.icon-button { width: 40px; height: 40px; border-radius: 13px; font-size: 22px; }
.avatar { max-width: 120px; height: 40px; padding: 0 13px; overflow: hidden; border-radius: 13px; text-overflow: ellipsis; white-space: nowrap; }

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 18px max(14px, env(safe-area-inset-right)) calc(112px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.pane { display: none; animation: pane-in .18s ease-out; }
.pane.active { display: block; }
@keyframes pane-in { from { opacity: .45; transform: translateY(5px); } }

.safe-banner {
  margin-bottom: 14px;
  padding: 15px 17px;
  border: 1px solid rgba(84, 209, 139, .23);
  border-radius: 18px;
  background: rgba(84, 209, 139, .08);
}

.safe-banner span { color: var(--success); font-size: 12px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.safe-banner p { margin: 6px 0 0; color: #d6ddd8; font-size: 13px; line-height: 1.45; }

.card {
  margin-bottom: 14px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(33, 36, 42, .94), rgba(22, 24, 28, .98));
  box-shadow: 0 8px 28px rgba(0, 0, 0, .13);
}

.connection-card { display: grid; gap: 16px; }
.card h2, .page-title h1 { margin: 3px 0 0; letter-spacing: -.035em; }
.card h2 { font-size: 20px; }
.card p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.eyebrow { color: var(--accent-2); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.card-heading, .page-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.page-title { padding: 8px 4px 0; }
.page-title h1 { font-size: clamp(25px, 7vw, 36px); }
.step, .counter {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.step { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; color: var(--accent); font-weight: 800; }
.counter { padding: 7px 10px; border-radius: 999px; color: var(--muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; }
label > span { display: block; margin: 0 0 7px 2px; color: #cbcbd0; font-size: 12px; }
.field-help { display: block; margin: 7px 3px 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #111317;
  color: var(--text);
  padding: 0 13px;
}

select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #8f929a 50%), linear-gradient(135deg, #8f929a 50%, transparent 50%); background-position: calc(100% - 17px) 21px, calc(100% - 12px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { min-height: 112px; padding-top: 12px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: #666a73; }

.private-lock {
  display: flex;
  gap: 12px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid rgba(255, 132, 61, .24);
  border-radius: 15px;
  background: rgba(255, 132, 61, .07);
}
.private-lock > span { display: grid; flex: 0 0 auto; width: 27px; height: 27px; place-items: center; border-radius: 50%; background: var(--accent); color: #18100b; font-weight: 900; }
.private-lock strong, .private-lock small { display: block; }
.private-lock strong { font-size: 14px; }
.private-lock small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.message-field { margin-bottom: 15px; }

.primary, .secondary, .ghost, .danger {
  min-height: 46px;
  border-radius: 14px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 750;
  cursor: pointer;
}
.primary { background: linear-gradient(135deg, #ff934e, var(--accent)); color: #21140b; box-shadow: 0 8px 25px rgba(255, 132, 61, .16); }
.secondary { border-color: var(--line); background: var(--panel-3); }
.ghost { min-height: 40px; border-color: var(--line); background: transparent; color: #d6d6da; }
.danger { border-color: rgba(255, 102, 99, .32); background: rgba(255, 102, 99, .08); color: #ff9895; }
.wide { width: 100%; }

.progress-card { position: relative; overflow: hidden; }
.stage { justify-content: space-between; gap: 15px; }
.spinner { display: none; flex: 0 0 auto; width: 25px; height: 25px; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.active { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 17px; }
.stat-grid > div { min-width: 0; padding: 12px 9px; border: 1px solid var(--line); border-radius: 14px; background: #14161a; }
.stat-grid b, .stat-grid span { display: block; }
.stat-grid b { font-size: 22px; letter-spacing: -.03em; }
.stat-grid span { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.stat-grid .accent b { color: var(--accent); }
.row-actions { justify-content: flex-end; gap: 9px; margin-top: 14px; }

.result-tools { justify-content: space-between; gap: 9px; margin: 0 4px 13px; }
.result-list { display: grid; gap: 10px; }
.result-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
}
.result-card.selected { border-color: rgba(255,132,61,.64); box-shadow: inset 0 0 0 1px rgba(255,132,61,.14); }
.result-card input[type="checkbox"] { width: 22px; min-height: 22px; accent-color: var(--accent); }
.result-main { min-width: 0; }
.result-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 9px; }
.result-title { color: var(--text); font-size: 15px; font-weight: 750; line-height: 1.35; text-decoration: none; }
.result-price { flex: 0 0 auto; color: var(--accent-2); font-size: 14px; font-weight: 800; white-space: nowrap; }
.result-meta { margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.result-status { display: inline-flex; margin-top: 9px; padding: 5px 8px; border-radius: 999px; background: rgba(84,209,139,.09); color: #8fe7b4; font-size: 10px; }
.result-status.blocked { background: rgba(255,198,92,.08); color: var(--warning); }
.empty { padding: 34px 18px; border: 1px dashed var(--line); border-radius: 17px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.5; }

.send-dock {
  position: sticky;
  z-index: 10;
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(27, 29, 34, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.send-dock small, .send-dock strong { display: block; }
.send-dock small { color: var(--muted); font-size: 9px; }
.send-dock strong { margin-top: 3px; font-size: 12px; }

.detail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.detail-stats > div { padding: 15px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.detail-stats span, .detail-stats b { display: block; }
.detail-stats span { min-height: 30px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.detail-stats b { margin-top: 7px; font-size: 23px; }
.events { padding: 5px 15px; }
.event { display: grid; grid-template-columns: 72px 1fr; gap: 11px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.event:last-child { border: 0; }
.event-time { color: var(--muted); font-size: 10px; }
.event strong, .event p { display: block; margin: 0; }
.event strong { color: var(--accent-2); font-size: 10px; letter-spacing: .05em; }
.event p { margin-top: 4px; color: #d5d5d8; font-size: 12px; line-height: 1.45; }

.monitor-card { overflow: hidden; }
.monitor-head, .chat-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 13px; }
.monitor-dot { flex: 0 0 auto; width: 12px; height: 12px; margin-top: 8px; border-radius: 50%; background: #666a73; box-shadow: 0 0 0 6px rgba(102,106,115,.1); }
.monitor-dot.active { background: var(--success); box-shadow: 0 0 0 6px rgba(84,209,139,.11); }
.monitor-badge, .chat-status { flex: 0 0 auto; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 10px; }
.monitor-badge.active { border-color: rgba(84,209,139,.25); background: rgba(84,209,139,.08); color: #8fe7b4; }
.dialog-flow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 17px; }
.dialog-flow span { position: relative; min-width: 0; padding: 8px 4px; border-radius: 9px; background: #111317; color: #c2c4c9; font-size: 8px; line-height: 1.25; text-align: center; }
.dialog-flow span:not(:last-child)::after { content: '›'; position: absolute; z-index: 1; right: -5px; color: var(--accent); }
.chat-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 12px; }
.chat-stats > div { min-width: 0; padding: 11px 6px; border: 1px solid var(--line); border-radius: 12px; background: #14161a; text-align: center; }
.chat-stats b, .chat-stats span { display: block; }
.chat-stats b { color: var(--accent-2); font-size: 20px; }
.chat-stats span { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.last-check { display: block; margin-top: 10px; color: var(--muted); font-size: 10px; }
.chat-list { display: grid; gap: 10px; }
.chat-card { padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.chat-card.status-active { border-color: rgba(255,132,61,.34); }
.chat-card.status-agreed { border-color: rgba(84,209,139,.38); }
.chat-card.status-human { border-color: rgba(255,198,92,.4); }
.chat-card-head > div { min-width: 0; }
.chat-card-head a { display: block; overflow: hidden; color: var(--text); font-size: 14px; font-weight: 750; line-height: 1.35; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.chat-card-head small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.chat-card h3 { margin: 14px 0 6px; color: var(--accent-2); font-size: 14px; }
.chat-card > span { display: block; color: var(--muted); font-size: 10px; }
.chat-status { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-agreed .chat-status { border-color: rgba(84,209,139,.25); color: #8fe7b4; }
.status-human .chat-status { border-color: rgba(255,198,92,.26); color: var(--warning); }
.agreed-price { display: block; margin-top: 7px; color: var(--success); font-size: 13px; }
.chat-reason { margin: 8px 0 0; color: #d1d2d5; font-size: 11px; line-height: 1.45; }
.chat-reply { margin-top: 11px; padding: 11px; border-radius: 12px; background: #111317; }
.chat-reply span { color: var(--muted); font-size: 9px; }
.chat-reply p { margin: 5px 0 0; color: #e0e0e2; font-size: 11px; line-height: 1.45; }

.user-list { display: grid; gap: 10px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.user-row strong, .user-row small { display: block; }
.user-row small { margin-top: 4px; color: var(--muted); }
.role { padding: 5px 8px; border-radius: 999px; background: var(--panel-3); color: var(--muted); font-size: 10px; }
.inline-status, .login-error { min-height: 21px; margin-top: 10px; color: var(--accent-2); font-size: 12px; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  padding: 8px max(9px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(15, 16, 19, .92);
  backdrop-filter: blur(20px);
}
.bottom-nav button { flex: 1 1 0; max-width: 170px; min-height: 50px; border: 0; border-radius: 13px; background: transparent; color: #858991; font-size: 10px; cursor: pointer; }
.bottom-nav span { display: block; height: 22px; font-size: 20px; line-height: 20px; }
.bottom-nav button.active { background: rgba(255,132,61,.09); color: var(--accent-2); }

.modal { position: fixed; z-index: 80; inset: 0; display: none; align-items: flex-end; justify-content: center; padding: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(7px); }
.modal.open { display: flex; }
.modal-sheet { width: min(760px, 100%); max-height: 92vh; overflow: auto; padding: 18px max(15px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left)); border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0; background: #17191d; box-shadow: var(--shadow); }
.small-sheet { display: grid; gap: 11px; }
.modal-head { justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.modal-head strong, .modal-head small { display: block; }
.modal-head small { max-width: 70vw; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.close { width: 37px; height: 37px; border-radius: 12px; font-size: 24px; }
.browser-help, .privacy-note, .install-copy { color: var(--muted); font-size: 12px; line-height: 1.5; }
.browser-viewport { position: relative; overflow: hidden; min-height: 190px; margin: 11px 0; border: 1px solid var(--line); border-radius: 12px; background: #f4f4f4; }
.browser-viewport img { display: block; width: 100%; height: auto; min-height: 190px; object-fit: contain; touch-action: none; user-select: none; }
.browser-loading { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; background: #17191d; color: var(--muted); font-size: 12px; }
.browser-loading.hidden { display: none; }
.typing-row { gap: 8px; }
.typing-row input { min-width: 0; }
.typing-row button { flex: 0 0 auto; }
.browser-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 9px; }
.browser-controls button { min-height: 39px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); font-size: 11px; }
.privacy-note { margin: 11px 2px 0; }
.install-copy ol { padding-left: 22px; }
.install-copy li { margin: 8px 0; }

.toast { position: fixed; z-index: 120; right: 14px; bottom: calc(88px + env(safe-area-inset-bottom)); left: 14px; max-width: 560px; margin: auto; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: #292d34; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(14px); transition: .18s ease; font-size: 12px; text-align: center; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255,102,99,.5); color: #ffaaa7; }

.login-body { display: grid; min-height: 100vh; place-items: center; padding: 28px 16px; }
.login-shell { width: min(390px, 100%); text-align: center; }
.login-logo { width: 78px; height: 78px; margin-bottom: 17px; border-radius: 22px; box-shadow: 0 16px 40px rgba(255,132,61,.17); }
.login-shell h1 { margin: 5px 0 6px; font-size: 39px; letter-spacing: -.05em; }
.login-shell > p { margin: 0 auto 21px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.login-card { display: grid; gap: 13px; padding: 19px; border: 1px solid var(--line); border-radius: 21px; background: var(--panel); text-align: left; box-shadow: var(--shadow); }
.login-note { display: block; margin-top: 16px; color: #737780; font-size: 10px; line-height: 1.45; }

@media (min-width: 640px) {
  .app-shell { padding-top: 26px; }
  .connection-card { grid-template-columns: 1fr auto; align-items: center; }
  .modal { align-items: center; padding: 20px; }
  .modal-sheet { border-bottom: 1px solid var(--line); border-radius: 24px; }
  .browser-sheet { max-height: 96vh; }
  .browser-viewport { max-height: 62vh; overflow: auto; }
}

@media (max-width: 390px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .result-top { display: block; }
  .result-price { margin-top: 4px; }
  .browser-controls { grid-template-columns: repeat(2, 1fr); }
}

@media (display-mode: standalone) {
  #installBtn { display: none; }
}

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