/* The service panel: quiet, one accent (green, for what runs), the rest greys. */

:root {
  color-scheme: dark;
  --bg: #111412;
  --surface: #181d1a;
  --surface-2: #202822;
  --border: #2c372f;
  --text: #edf3ec;
  --muted: #9eafa2;
  --faint: #7f8e83;
  --accent: #46c46a;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--surface));
  --warn: #d4ad45;
  --danger: #e26767;
  --radius: 8px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }

/* Header */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.2px; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; margin-left: 12px; flex-wrap: wrap; }
.nav button, .nav .nav-link {
  background: none; border: 0; padding: 6px 10px; border-radius: var(--radius);
  color: var(--muted); cursor: pointer; text-decoration: none;
}
.nav button:hover, .nav .nav-link:hover { color: var(--text); }
.nav button[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.top .spacer { flex: 1; }
.lang { display: flex; gap: 2px; }
.lang button { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.lang button[aria-pressed="true"] { color: var(--text); background: var(--surface-2); }

/* Blocks */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: var(--gap);
}
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.card h3 { margin: 16px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 140px; }
.stack > * + * { margin-top: 8px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; }
  /* The pages go to a line of their own under the brand and the buttons, and scroll sideways if they must. */
  .top { flex-wrap: wrap; }
  .nav { order: 1; flex-basis: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; }
  .nav button { flex: none; }
}

/* Controls */
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  min-height: 34px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--faint); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field input, label.field select, label.field textarea { font-size: 14px; color: var(--text); }
label.field textarea { resize: vertical; line-height: 1.45; }
label.check { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; font-size: 13px; color: var(--muted); cursor: pointer; }
label.check input { min-height: 0; width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  min-height: 34px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 28px; padding: 3px 9px; font-size: 13px; }
.btn.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--muted); text-decoration: underline; }
.btn.wide { width: 100%; }
.btn[aria-pressed="true"] { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

/* Messages */
.notice { padding: 9px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-top: var(--gap); }
.notice.error { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }

/* Behind every page: two soft lights that drift very slowly (they sit outside #app, so a redraw does not restart them). */
.backdrop { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.backdrop i {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
  opacity: 0.55; will-change: transform;
}
.backdrop i:first-child { left: -28vmax; top: -34vmax; animation: drift-a 28s ease-in-out infinite alternate; }
.backdrop i:last-child { right: -32vmax; bottom: -40vmax; opacity: 0.35; animation: drift-b 36s ease-in-out infinite alternate; }
@keyframes drift-a { to { transform: translate3d(16vmax, 12vmax, 0) scale(1.12); } }
@keyframes drift-b { to { transform: translate3d(-14vmax, -10vmax, 0) scale(1.1); } }
#app { position: relative; z-index: 1; transition: opacity 0.24s ease, transform 0.24s ease; }
/* The page hands over to the panel (LEAVE_MS in app.js is this time). */
#app.is-leaving { opacity: 0; transform: translateY(-8px); pointer-events: none; }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes letter { from { opacity: 0; transform: translateY(0.5em); } }
@keyframes logo-in { from { opacity: 0; transform: translateY(12px) scale(0.84); } }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes pill { from { transform: translateX(calc(var(--from, var(--i, 0)) * 100%)); } }
@keyframes swap { from { opacity: 0; transform: translateY(8px); } }
@keyframes nudge { 0% { opacity: 0; transform: translateX(-8px); } 30% { transform: translateX(6px); } 60% { transform: translateX(-3px); } 100% { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sign-in */
.auth { max-width: 400px; margin: 0 auto; padding: 8vh 16px 40px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.auth-logo {
  width: 76px; height: 76px;
  filter: drop-shadow(0 4px 24px color-mix(in srgb, var(--accent) 50%, transparent));
  animation: bob 5.5s ease-in-out infinite;
}
.auth-name { display: flex; font-size: 28px; font-weight: 650; letter-spacing: 0.4px; }
.auth-letter { display: inline-block; }
.auth-tagline { margin: 8px 0 0; text-align: center; color: var(--muted); }
.auth-card {
  margin-top: 24px; padding: 20px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}
.auth-note { margin: 0 0 16px; }
.auth-providers { display: grid; gap: 8px; }
.provider {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; min-height: 44px; padding: 8px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.provider:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 7%, var(--surface-2));
}
.provider:active:not(:disabled) { transform: none; }
.provider:disabled { opacity: 0.5; cursor: default; }
.provider-mark { display: inline-flex; width: 20px; height: 20px; }
.provider-mark svg { width: 100%; height: 100%; }
.auth-or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--faint); font-size: 12px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-telegram { display: flex; justify-content: center; min-height: 4px; }

.auth-tabs {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 4px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.auth-pill {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 2);
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  transform: translateX(calc(var(--i, 0) * 100%));
  animation: pill 0.32s cubic-bezier(0.3, 0.9, 0.3, 1) both;
}
.auth-tabs button {
  position: relative; z-index: 1; padding: 6px; background: none; border: 0;
  color: var(--muted); cursor: pointer; transition: color 0.2s ease;
}
.auth-tabs button[aria-selected="true"] { color: var(--text); }
.auth-tabs button:hover { color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.is-swapping { animation: swap 0.28s ease both; }
.auth-card input { min-height: 40px; transition: border-color 0.16s ease, box-shadow 0.16s ease; }
.auth-card input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 40px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 32px; height: 32px;
  background: none; border: 0; border-radius: 6px; color: var(--faint); cursor: pointer;
  transition: color 0.16s ease;
}
.pw-toggle:hover, .pw-toggle[aria-pressed="true"] { color: var(--text); }
.submit { position: relative; min-height: 40px; font-weight: 600; transition: background 0.16s ease, border-color 0.16s ease; }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
.spinner {
  position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border: 2px solid color-mix(in srgb, var(--text) 25%, transparent); border-top-color: var(--text); border-radius: 50%;
  opacity: 0; animation: spin 0.7s linear infinite;
}
.submit.is-busy .spinner { opacity: 1; }
.submit.is-busy > span { opacity: 0; }
.submit:disabled { opacity: 1; }
.auth-lang { display: flex; justify-content: center; margin-top: 16px; }

/* What arrives, arrives once: the letters one by one, then each part a little after the one before. */
.is-arriving [data-rise] { animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--k, 0) * 80ms + 120ms); }
.is-arriving .auth-letter { animation: letter 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--k) * 45ms + 100ms); }
.is-arriving .auth-logo { animation: logo-in 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2) both, bob 5.5s ease-in-out 0.7s infinite; }
.notice.is-fresh { animation: nudge 0.4s ease both; }
.notice.is-fresh:not(.error) { animation: rise 0.35s ease both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 480px) {
  .auth { padding-top: 6vh; }
  .auth-card { padding: 16px; }
}

/* Bots */
.stats { display: flex; gap: 24px; flex-wrap: wrap; }
.stat b { display: block; font-size: 18px; font-weight: 600; }
.stat span { color: var(--muted); font-size: 12px; }

.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item.open { background: var(--surface-2); }
.item .name { font: inherit; font-weight: 500; color: inherit; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.item .name:hover { text-decoration: underline; }
.item .sub { color: var(--faint); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.active { background: var(--accent); }
.dot.connecting { background: var(--warn); }
.dot.disconnected { background: var(--danger); }
.empty { padding: 16px; color: var(--muted); text-align: center; }

.detail { padding: 12px; border-top: 1px solid var(--border); background: var(--bg); }
.chat {
  height: 260px; overflow-y: auto; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.chat .out { color: var(--muted); }

.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; text-align: left;
}
.toggle .lamp { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex: none; }
.toggle[aria-pressed="true"] { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.toggle[aria-pressed="true"] .lamp { background: var(--accent); }
.toggle.locked { cursor: default; color: var(--faint); }
.toggle .lock { margin-left: auto; font-size: 11px; color: var(--faint); }

.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--border); color: var(--muted); }
.badge.live { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* Plans */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: 12px; }
td.current, th.current { background: var(--surface-2); }
.scroll { overflow-x: auto; }

/* Admin */
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.error-text { color: var(--danger); }
