@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Syne:wght@700;800&display=swap');

:root {
  --bg: #0a0b0d;
  --bg2: #12141a;
  --panel: rgba(18, 20, 26, 0.82);
  --line: rgba(255,255,255,0.08);
  --text: #f4f1ea;
  --muted: #9a958c;
  --accent: #ff5a3d;
  --accent2: #ff8a3d;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --danger: #ff5a3d;
  --radius: 20px;
  --shadow: 0 24px 80px rgba(0,0,0,.45);
  --font: "Manrope", system-ui, sans-serif;
  --display: "Syne", "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(255,90,61,.18), transparent 55%),
    radial-gradient(700px 420px at 0% 20%, rgba(255,138,61,.10), transparent 50%),
    linear-gradient(180deg, #101218 0%, var(--bg) 40%, #070809 100%);
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}
a { color: var(--accent2); text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
.wrap {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 80px;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  object-fit: cover;
  display: block;
  background: linear-gradient(145deg, #ff7a45, #ff3d2e 55%, #b91c1c);
  box-shadow: 0 12px 40px rgba(255,90,61,.35);
  animation: glow 4s ease-in-out infinite;
}
.public-url {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  max-width: min(420px, 70vw);
  color: var(--accent2);
  font-size: .78rem;
  text-decoration: none;
  opacity: .9;
}
.public-url span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.public-url:hover { opacity: 1; text-decoration: underline; }
.mark-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.mark-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 8px 24px rgba(255,90,61,.3);
}
@keyframes glow {
  0%, 100% { box-shadow: 0 12px 40px rgba(255,90,61,.28); transform: translateY(0); }
  50% { box-shadow: 0 16px 48px rgba(255,90,61,.45); transform: translateY(-1px); }
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.panel + .panel { margin-top: 16px; }

.hero {
  text-align: center;
  padding: 36px 22px 28px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: auto 20% -40% 20%;
  height: 180px;
  background: radial-gradient(circle, rgba(255,90,61,.22), transparent 70%);
  pointer-events: none;
}
.hero .eyebrow {
  display: inline-block;
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 10px;
  font-weight: 700;
}
.hero h2 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  letter-spacing: -0.04em;
  font-weight: 800;
}
.hero p {
  margin: 0 auto 22px;
  max-width: 420px;
  color: var(--muted);
  line-height: 1.55;
  font-size: .95rem;
}
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.step {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.02);
}
.step b {
  display: block;
  font-family: var(--display);
  margin-bottom: 2px;
  font-size: .95rem;
}
.step .tiny { font-size: .75rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.stat {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}
.stat span { color: var(--muted); font-size: .78rem; }

.muted { color: var(--muted); }
.tiny { font-size: .8rem; color: var(--muted); }
.stack { display: grid; gap: 12px; }
.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 720px) {
  .grid-2, .stats { grid-template-columns: 1fr; }
}

label {
  display: grid;
  gap: 6px;
  font-size: .88rem;
  color: var(--muted);
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28);
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus {
  border-color: rgba(255,90,61,.55);
  box-shadow: 0 0 0 3px rgba(255,90,61,.12);
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
  min-height: 48px;
  transition: transform .08s ease, opacity .15s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #ff8a3d, #ff5a3d);
  color: #1a0b08;
}
.btn-danger {
  background: linear-gradient(135deg, #ff6b4a, #e11d2e);
  color: white;
  box-shadow: 0 14px 40px rgba(225,29,46,.28);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-sm { padding: 10px 12px; min-height: 40px; border-radius: 12px; font-size: .9rem; }
.btn-xl {
  width: min(420px, 100%);
  font-size: 1.08rem;
  padding: 18px 22px;
  border-radius: 16px;
  position: relative;
  z-index: 1;
}

.alert {
  border-radius: 14px;
  padding: 12px 14px;
  font-size: .92rem;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.25);
}
.alert.error { border-color: rgba(255,90,61,.4); color: #ffb4a4; }
.alert.ok { border-color: rgba(62,207,142,.35); color: #b6f5d3; }
.alert.warn { border-color: rgba(240,180,41,.35); color: #ffe0a3; }

.progress {
  margin-top: 14px;
  height: 8px;
  background: #0f1319;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff8a3d, #ff3d2e);
  transition: width .3s ease;
}

.manager {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
  transition: border-color .2s ease, transform .2s ease;
}
.manager:hover { border-color: rgba(255,138,61,.28); }
.manager .top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .75rem;
  font-weight: 700;
  border: 1px solid var(--line);
}
.badge.ready { color: var(--ok); border-color: rgba(62,207,142,.35); }
.badge.pending { color: var(--warn); border-color: rgba(240,180,41,.35); }
.badge.error, .badge.clearing { color: var(--danger); border-color: rgba(255,90,61,.35); }
.dialogs-modal {
  width: min(560px, 100vw);
  max-height: min(92vh, 900px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
}
.dialogs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#dialogsListView,
#dialogsChatView {
  min-height: 0;
}
.dialogs-list {
  max-height: none;
  overflow: auto;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 180px;
  max-height: 52vh;
  -webkit-overflow-scrolling: touch;
}
.dialog-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 12px;
  row-gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  text-align: left;
  cursor: pointer;
}
.dialog-row:hover { border-color: rgba(255,138,61,.35); background: rgba(255,255,255,.045); }
.dialog-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.dialog-row .meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
}
.dialog-row .meta .name {
  max-width: 100%;
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dialog-row .meta .sub {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.dialog-row .meta .flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.dialog-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
}
.dialog-chip.unread {
  color: var(--accent2);
  border-color: rgba(255,138,61,.35);
}
.dialog-open {
  justify-self: end;
  align-self: center;
  white-space: nowrap;
  min-width: 88px;
}
.dialogs-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#dialogsBack {
  width: 100%;
}
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-height: 220px;
  max-height: 56vh;
  padding: 8px 2px;
  -webkit-overflow-scrolling: touch;
}
.chat-bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: .88rem;
  line-height: 1.4;
  border: 1px solid var(--line);
  word-break: break-word;
}
.chat-bubble.out {
  align-self: flex-end;
  background: rgba(255,90,61,.16);
  border-color: rgba(255,90,61,.28);
}
.chat-bubble.in {
  align-self: flex-start;
  background: rgba(255,255,255,.05);
}
.chat-bubble .when {
  display: block;
  margin-top: 6px;
  font-size: .68rem;
  color: var(--muted);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem;
  word-break: break-all;
  color: var(--muted);
}

@media (max-width: 720px) {
  .steps { grid-template-columns: 1fr; }
  .dialogs-modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 94vh;
    margin: 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }
  .dialogs-toolbar {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .dialog-row {
    grid-template-columns: 22px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: start;
  }
  .dialog-row input {
    grid-row: 1;
    margin-top: 3px;
  }
  .dialog-row .meta { grid-column: 2; grid-row: 1; }
  .dialog-open {
    grid-column: 2;
    grid-row: 2;
    justify-self: stretch;
    align-self: stretch;
    width: 100%;
    min-width: 0;
  }
  .dialogs-actions { grid-template-columns: 1fr; }
  .dialogs-list, .chat-thread { max-height: 46vh; }
  .chat-bubble { max-width: 92%; }
}

@media (min-width: 721px) {
  .modal-back { align-items: center; }
  .dialogs-modal { border-radius: var(--radius); }
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.62);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  backdrop-filter: blur(6px);
}
.modal-back.open { display: flex; }
.modal {
  width: min(500px, 100%);
  background: #14161c;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: max(8px, env(safe-area-inset-bottom));
  animation: rise .22s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (min-width: 720px) {
  .modal-back { align-items: center; }
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.login-card {
  width: min(420px, 100%);
}
.login-card .mark {
  font-family: var(--display);
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.05em;
  margin: 0 0 8px;
  background: linear-gradient(120deg, #fff 20%, #ff8a3d 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.copy-ok { color: var(--ok); }
.section-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(0,0,0,.25);
  border: 1px solid var(--line);
  width: fit-content;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: .88rem;
}
.tab.active {
  background: rgba(255,90,61,.16);
  color: var(--text);
}
