:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-subtle: #f1f5f9;
  
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: #f0fdfa;
  --primary-glow: rgba(13, 148, 136, 0.15);
  
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-line: #fecaca;
  
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
  
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --ok-line: #bbf7d0;
  
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(13, 148, 136, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.skip {
  position: absolute; left: -999px; top: 0; background: #fff; padding: 10px 16px; z-index: 1000; border-radius: var(--radius-sm); font-weight: 600;
}
.skip:focus { left: 12px; top: 12px; box-shadow: var(--shadow-lg); }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- EMERGENCY BANNER --- */
.emergency {
  background: linear-gradient(90deg, #b91c1c 0%, #dc2626 100%);
  color: #fff;
  padding: 10px 16px;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px rgba(185, 28, 28, 0.15);
}
.emergency-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.emergency-icon { font-size: 1.1rem; }
.emergency a {
  color: #fff;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* --- TOP NAVBAR --- */
.top {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, #0f766e 100%);
  color: #fff;
  box-shadow: 0 4px 8px var(--primary-glow);
}
.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.userbar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-email {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- MAIN CONTAINER --- */
main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.banner {
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.banner.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-line);
}

/* --- AUTH VIEW --- */
.auth {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
  padding: 20px 0;
}
@media (min-width: 768px) {
  .auth {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: center;
    padding: 30px 0;
  }
}
.hero-pill {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(13, 148, 136, 0.2);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.hero h1 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0 0 14px;
}
.hero p {
  color: var(--ink-secondary);
  font-size: 1.05rem;
  line-height: 1.55;
  margin: 0 0 24px;
}
.features-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.feat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.feat-icon {
  font-size: 1.25rem;
  line-height: 1;
}
.feat-item strong {
  display: block;
  font-size: 0.9rem;
  color: var(--ink);
}
.feat-item small {
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.tabs {
  display: flex;
  gap: 6px;
  background: var(--line-subtle);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 14px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
}
.tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 6px;
  color: var(--ink-secondary);
}
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.label-row label { margin-bottom: 0; }
.hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

input, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  background: #fff;
  transition: var(--transition);
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

/* PASSWORD WRAPPER & TOGGLE EYE */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrapper input {
  padding-right: 44px;
}
.toggle-pw {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  padding: 6px;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.toggle-pw:hover {
  color: var(--ink);
  background: var(--line-subtle);
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  border: 0;
  border-radius: var(--radius);
  padding: 11px 20px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn.primary {
  background: var(--primary);
  color: #fff;
}
.btn.primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px var(--primary-glow);
}
.btn.ghost {
  background: transparent;
  color: var(--ink-secondary);
  border: 1.5px solid var(--line);
}
.btn.ghost:hover {
  background: var(--line-subtle);
  border-color: #cbd5e1;
}
.btn.text {
  background: transparent;
  color: var(--primary);
  padding: 8px 12px;
}
.btn.text:hover {
  background: var(--primary-light);
}
.btn.small {
  padding: 7px 14px;
  font-size: 0.82rem;
  border-radius: 9px;
}
.btn.full-width {
  width: 100%;
  margin-top: 10px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.msg {
  min-height: 1.4em;
  margin: 12px 0 0;
  font-size: 0.9rem;
  text-align: center;
}
.msg.error { color: var(--danger); font-weight: 600; }
.msg.ok {
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-weight: 600;
}
.fine {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 16px 0 0;
  text-align: center;
  line-height: 1.4;
}

/* --- CHAT VIEW --- */
.chat {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-header-info {
  display: flex;
  align-items: center;
  justify-content: center;
}
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  padding: 5px 14px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--primary-hover);
  box-shadow: var(--shadow-sm);
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.7);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(13, 148, 136, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(13, 148, 136, 0); }
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 50vh;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px 4px;
  scroll-behavior: smooth;
}
.bubble {
  max-width: 86%;
  padding: 14px 18px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow-sm);
  font-size: 0.95rem;
  line-height: 1.6;
}
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary) 0%, #0f766e 100%);
  color: #fff;
  border-color: var(--primary);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 10px var(--primary-glow);
}
.bubble.bot {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.emergency {
  border: 2px solid var(--danger);
  background: var(--danger-bg);
}
.bubble.blocked, .bubble.no_answer {
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.bubble.error {
  background: var(--danger-bg);
  border-color: var(--danger-line);
  color: var(--danger);
  align-self: center;
  font-weight: 500;
}

.sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 0.82rem;
  color: var(--muted);
  white-space: normal;
}
.sources a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.disc {
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: normal;
  font-style: italic;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 1.2em;
}
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: b 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes b {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* CHIPS */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--primary-hover);
  border-radius: var(--radius-full);
  padding: 8px 14px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.chip:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* COMPOSER */
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.composer textarea {
  width: 100%;
  resize: none;
  max-height: 140px;
  min-height: 50px;
  padding: 13px 48px 13px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.btn-icon {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: var(--radius-full);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.btn-icon:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.btn-icon.recording {
  color: #fff;
  background: var(--danger);
  animation: pulse 1s infinite;
}
.send-btn {
  margin: 0;
  height: 50px;
  padding: 0 20px;
  flex-shrink: 0;
}
.composer-foot {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0 4px;
}

/* --- MODAL DIALOG --- */
.modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: transparent;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 580px;
  width: 90vw;
}
.modal::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}
.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink);
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }
.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-intro {
  margin: 0 0 8px;
  color: var(--ink-secondary);
  font-size: 0.95rem;
}
.arch-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--line-subtle);
  padding: 12px 14px;
  border-radius: var(--radius);
}
.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.arch-step strong {
  display: block;
  font-size: 0.92rem;
  color: var(--ink);
  margin-bottom: 2px;
}
.arch-step p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

/* --- FOOTER --- */
.foot {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 20px 16px;
  margin-top: auto;
}
.foot-inner {
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
}
.foot-inner p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}
.notice-card {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: #78350f;
  line-height: 1.5;
}
.notice-card strong {
  display: block;
  margin-bottom: 4px;
  color: #92400e;
}
.notice-card p { margin: 0; }

.footer-security {
  margin: 8px 0 6px;
}
.security-tag {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 700;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.foot-inner small {
  color: #94a3b8;
  font-size: 0.75rem;
}

@media (max-width: 640px) {
  .hero h1 { font-size: 1.7rem; }
  .user-email { display: none; }
  .bubble { max-width: 92%; }
}
