:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12161b;
  --panel-2: #181d24;
  --line: #252c35;
  --text: #f4f7fb;
  --muted: #8d98a7;
  --accent: #55d6a7;
  --accent-strong: #2fba88;
  --danger: #ff6b6b;
  --user: #1d654f;
  --assistant: #171c22;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 28%, #172039, var(--bg) 48%); }
.login-card { width: min(100%, 360px); padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: rgba(18,22,27,.96); box-shadow: 0 24px 70px rgba(0,0,0,.38); text-align: center; }
.login-icon { width: 76px; height: 76px; display: block; margin: 0 auto 14px; }
.login-card h1 { font-size: 24px; }
.login-card p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 8px 0 20px; }
.login-card input { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-2); color: var(--text); padding: 0 14px; outline: none; }
.login-card input:focus { border-color: #637eea; box-shadow: 0 0 0 3px rgba(99,126,234,.14); }
.login-card button { width: 100%; min-height: 48px; margin-top: 10px; border: 0; border-radius: 13px; background: #5f75ec; color: white; font-weight: 700; cursor: pointer; }
.login-card button:disabled { opacity: .55; }
.login-error { min-height: 18px; color: #ff9f9f; font-size: 12px; margin-top: 10px; }

.app-shell { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 16, .92);
  backdrop-filter: blur(18px);
  z-index: 20;
}
.brand-row, .top-actions { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  overflow: hidden; background: #0b0d10;
  box-shadow: 0 6px 24px rgba(255, 255, 255, .08);
}
.brand-mark img { width: 100%; height: 100%; display: block; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; letter-spacing: -.01em; }
.status-text { color: var(--muted); font-size: 12px; margin-top: 2px; }
.icon-button {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  min-height: 38px; border-radius: 11px; padding: 0 12px; cursor: pointer;
}
.hidden { display: none !important; }

.main-layout { min-height: 0; flex: 1; position: relative; display: flex; }
.chat-column { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 20px max(16px, calc((100vw - 820px) / 2)) 18px;
  scroll-behavior: smooth;
}
.message { max-width: 760px; margin: 0 auto 16px; display: flex; }
.message.user { justify-content: flex-end; }
.bubble {
  max-width: min(88%, 680px); padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 18px; background: var(--assistant); line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px;
}
.message.user .bubble { background: var(--user); border-color: #2a7a60; border-bottom-right-radius: 6px; }
.message.assistant .bubble { border-bottom-left-radius: 6px; }
.message-meta { color: rgba(255,255,255,.5); font-size: 10px; margin-top: 7px; }
.empty-state { color: var(--muted); text-align: center; max-width: 340px; margin: 20vh auto 0; line-height: 1.5; }

.connection-banner {
  background: #6a3b17; color: #ffdab8; text-align: center; padding: 8px 12px; font-size: 12px;
}
.message.live-message { justify-content: flex-start; margin-bottom: 12px; }
.live-reply {
  width: min(88%, 680px); padding: 2px 14px; color: var(--text); font-size: 14px;
  line-height: 1.5;
}
.live-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 5px; color: var(--muted); font-size: 11px; line-height: 1.3;
}
.live-stage { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #a6dfca; }
.live-elapsed { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.live-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.live-content.waiting { min-height: 22px; display: flex; align-items: center; }
.live-cursor {
  display: inline-block; width: 6px; height: 6px; margin-left: 7px; border-radius: 50%;
  background: var(--accent); vertical-align: middle; animation: live-pulse 1.25s ease-in-out infinite;
}
.live-content.waiting .live-cursor { width: 7px; height: 7px; margin-left: 0; }
@keyframes live-pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

.composer {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 10px max(12px, calc((100vw - 820px) / 2)) calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line); background: rgba(11,13,16,.94); backdrop-filter: blur(18px);
}
.composer textarea {
  flex: 1; min-height: 46px; max-height: 180px; resize: none; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel-2); color: var(--text);
  padding: 12px 14px; outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: #367c63; box-shadow: 0 0 0 3px rgba(85,214,167,.09); }
.send-button {
  width: 46px; height: 46px; border: 0; border-radius: 15px; background: var(--accent);
  color: #07130f; font-size: 25px; font-weight: 700; cursor: pointer;
}
.send-button:disabled { opacity: .45; }

.control-panel {
  width: 360px; border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 18px; z-index: 30;
}
.panel-head, .section-title { display: flex; align-items: center; justify-content: space-between; }
.panel-head { margin-bottom: 18px; }
.panel-head .icon-button { display: none; font-size: 24px; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.control-button {
  min-height: 44px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); color: var(--text); cursor: pointer;
}
.control-button.danger { border-color: #683737; color: #ffadad; }
.control-button.danger-secondary { color: #d7a0a0; }
.settings-block, .queue-block, .usage-block { margin-top: 22px; }
.settings-block { display: grid; gap: 8px; }
.settings-block label { color: var(--muted); font-size: 12px; margin-top: 5px; }
select {
  width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel-2); color: var(--text); padding: 0 10px;
}
.section-title h3, .usage-block h3 { font-size: 14px; }
.badge { min-width: 24px; padding: 3px 7px; border-radius: 999px; background: #263029; color: #a4e7cd; text-align: center; font-size: 11px; }
.small-button { border: 1px solid #376652; border-radius: 9px; background: #17231e; color: #a4e7cd; padding: 6px 10px; font-size: 11px; cursor: pointer; }
.small-button:disabled { opacity: .55; cursor: wait; }
.logout-button { width: 100%; min-height: 42px; border: 1px solid #493638; border-radius: 11px; background: transparent; color: #c8989d; cursor: pointer; }
.limit-list { display: grid; gap: 10px; margin-top: 11px; }
.limit-row { border: 1px solid var(--line); border-radius: 11px; background: #14191f; padding: 10px; }
.limit-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 650; }
.limit-meta { color: var(--muted); font-size: 11px; margin-top: 7px; }
.limit-track { height: 6px; background: #252c35; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.limit-fill { height: 100%; background: var(--accent); border-radius: inherit; }
.queue-list { margin-top: 10px; display: grid; gap: 8px; }
.queue-item { padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #14191f; }
.queue-item-title { font-size: 12px; font-weight: 650; }
.queue-item-text { color: var(--muted); font-size: 11px; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 9px; }
.panel-backdrop { display: none; }

.send-dialog {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  padding: 18px; background: rgba(3, 5, 8, .72); backdrop-filter: blur(8px);
}
.send-dialog-card {
  width: min(100%, 430px); padding: 20px; border: 1px solid var(--line);
  border-radius: 20px; background: var(--panel); box-shadow: 0 24px 70px rgba(0,0,0,.48);
}
.send-dialog-card h2 { font-size: 18px; }
.send-dialog-card > p { margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.send-choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }
.send-choice {
  min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); color: var(--text); cursor: pointer;
}
.send-choice.primary { border-color: #39775f; background: #1b5c48; }
.send-choice:disabled { opacity: .45; cursor: not-allowed; }
.schedule-form { display: grid; gap: 9px; margin-top: 14px; }
.schedule-form label { color: var(--muted); font-size: 12px; }
.schedule-form input {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--panel-2); color: var(--text); color-scheme: dark;
}
.schedule-hint { min-height: 18px; margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.cancel-send {
  width: 100%; min-height: 40px; margin-top: 6px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer;
}

@media (max-width: 900px) {
  .control-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(88vw, 380px);
    padding-top: max(18px, env(safe-area-inset-top)); transform: translateX(102%);
    transition: transform .2s ease; box-shadow: -18px 0 50px rgba(0,0,0,.35);
  }
  .control-panel.open { transform: translateX(0); }
  .panel-head .icon-button { display: block; }
  .panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.46); z-index: 25; }
  .panel-backdrop.open { display: block; }
  .messages { padding-inline: 13px; }
  .bubble { max-width: 92%; }
  .send-choice-grid { grid-template-columns: 1fr; }
}

@media (min-width: 901px) {
  #panelButton { display: none; }
}
