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

:root {
  --bg: #0B0D12;
  --surface: #14171F;
  --surface-2: #1B1F2A;
  --surface-3: #232837;
  --border: #262B38;
  --border-soft: #1E222E;
  --text: #F3F4F6;
  --text-dim: #9BA1AE;
  --text-faint: #6B7180;

  --accent: #F97316;
  --accent-hover: #FB923C;
  --accent-active: #EA580C;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --accent-text: #FFEDD9;

  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.12);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Outfit', 'Inter', sans-serif;
  margin: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.hidden { display: none !important; }
.view { height: 100dvh; }

/* ---------- Login ---------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(249, 115, 22, 0.08), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(249, 115, 22, 0.05), transparent 45%),
    var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: min(400px, 100%);
  box-shadow: var(--shadow-lg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-active));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0B0D12;
  flex-shrink: 0;
  box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
}
.brand-mark svg { width: 20px; height: 20px; }

.brand h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--text-dim);
  font-size: 14.5px;
  margin: 0 0 28px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}

input, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  min-height: 44px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary, .btn-secondary, .btn-danger-ghost {
  min-height: 44px;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  font-size: 14.5px;
  font-weight: 600;
  border: none;
  transition: background-color 180ms ease, border-color 180ms ease, transform 120ms ease, opacity 180ms ease;
}
.btn-primary:active, .btn-secondary:active, .btn-danger-ghost:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #150C04;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-text); }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
}
.btn-danger-ghost:hover { background: var(--danger-soft); }

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 4px 0 0;
}

.status { min-height: 16px; }

/* ---------- Chat ---------- */
#chat-view {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-active));
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #150C04;
}

.user-label {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-dim);
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

.msg {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  max-width: 80%;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
  animation: rise 220ms ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #180E04;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg.pending {
  padding: 14px 18px;
  display: flex;
  align-items: center;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
  background: rgba(11, 13, 18, 0.9);
  backdrop-filter: blur(10px);
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  position: sticky;
  bottom: 0;
}

.chat-input input {
  flex: 1;
  min-height: 46px;
  border-radius: 999px;
  padding: 0 18px;
}

.send-btn {
  width: 46px;
  height: 46px;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #150C04;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 180ms ease, transform 120ms ease;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 180ms ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: var(--radius-lg); max-height: 84vh; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.modal-header h2 { font-size: 18px; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-soft);
}
.settings-section:last-child { border-bottom: none; padding-bottom: 0; }

.settings-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hint { color: var(--text-dim); font-size: 13px; margin: 0; line-height: 1.5; }

textarea { resize: vertical; font-size: 14.5px; line-height: 1.5; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* ---------- Quick menu ---------- */
.quick-toggle { flex-shrink: 0; }

.quick-menu {
  position: sticky;
  bottom: 78px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 15;
}

.quick-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  min-height: 44px;
  box-shadow: var(--shadow-sm);
  transition: border-color 180ms ease, background-color 180ms ease;
  align-self: flex-end;
  width: fit-content;
}
.quick-menu-item svg { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
.quick-menu-item:hover { border-color: var(--accent); background: var(--surface-3); }

.quick-panel {
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px;
}

.quick-panel:not(.hidden) {
  padding-bottom: 10px;
}

.quick-panel-card {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  animation: panelIn 200ms ease;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.quick-panel-timerbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  transform-origin: left;
  animation: countdown 10s linear forwards;
}

@keyframes countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.quick-panel-card h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.quick-panel-card ul { margin: 0; padding-left: 18px; }
.quick-panel-card li { margin-bottom: 4px; }

@media (max-width: 600px) {
  .msg { max-width: 88%; }
  .login-card { padding: 32px 24px; }
}
