@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;1,300&family=Lora:ital,wght@0,400;0,500;1,400&display=swap');

:root {
  --bg: #080610;
  --bg2: #0e0b1a;
  --surface: #151020;
  --surface2: #1c1630;
  --gold: #c8860a;
  --gold-light: #e8c870;
  --gold-dim: rgba(200, 134, 10, 0.12);
  --gold-border: rgba(200, 134, 10, 0.2);
  --text: #ddd5c5;
  --text-dim: rgba(221, 213, 197, 0.55);
  --text-muted: rgba(221, 213, 197, 0.28);
  --user-bubble: #1a1530;
  --clio-bubble: #100d1c;
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  height: 100%;
  height: -webkit-fill-available;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Lora', Georgia, serif;
  color: var(--text);
}

.app-body {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  min-height: -webkit-fill-available;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 24px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

/* ── SCREEN SYSTEM ── */
.screen {
  position: fixed;
  inset: 0;
  max-width: 500px;
  margin: 0 auto;
}

/* ── AUTH SCREEN ── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 24px calc(env(safe-area-inset-bottom, 0px) + 20px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
}

.auth-glow {
  position: fixed;
  top: -30%;
  left: 50%;
  transform: translateX(-50%);
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200,134,10,0.07) 0%, transparent 70%);
  pointer-events: none;
}

.auth-inner {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: fadeUp 0.5s ease;
}

.auth-eye {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--gold-border);
}

.auth-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 9px;
  color: var(--gold-light);
}

.auth-tagline {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 2.5px;
  font-style: italic;
}

.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  padding: 26px 22px 22px;
  animation: fadeUp 0.5s ease 0.08s both;
}

.auth-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 21px;
  font-weight: 300;
  color: var(--gold-light);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  margin-bottom: 20px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.auth-label {
  font-size: 9px;
  letter-spacing: 2.5px;
  color: var(--text-muted);
  font-family: 'Cormorant Garamond', serif;
  text-transform: uppercase;
}

.auth-input {
  background: var(--bg2);
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-family: 'Lora', serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  -webkit-appearance: none;
}

.auth-input:focus { border-color: rgba(200, 134, 10, 0.5); }
.auth-input::placeholder { color: var(--text-muted); }

.auth-error {
  font-size: 12px;
  color: #e05858;
  min-height: 14px;
  margin-bottom: 6px;
}

.auth-submit {
  width: 100%;
  padding: 13px;
  background: var(--gold);
  border: none;
  border-radius: 12px;
  color: var(--bg);
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px;
  letter-spacing: 4px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 6px;
}

.auth-submit:hover, .auth-submit:active { background: var(--gold-light); }
.auth-submit:disabled { opacity: 0.45; cursor: not-allowed; }

.auth-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.auth-toggle-btn {
  background: none;
  border: none;
  color: var(--gold);
  cursor: pointer;
  font-size: 12px;
  font-family: 'Lora', serif;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
}

/* ── APP SCREEN ── */
.app-screen {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--gold-border);
  flex-shrink: 0;
  z-index: 10;
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--gold-border);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface);
}

.header-avatar svg { width: 100%; height: 100%; }
.header-info { flex: 1; min-width: 0; }

.header-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  font-weight: 300;
  letter-spacing: 5px;
  color: var(--gold-light);
  line-height: 1.1;
}

.header-status { font-size: 10px; color: var(--text-muted); letter-spacing: 1.5px; margin-top: 2px; }
.header-actions { display: flex; gap: 6px; }

.header-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--gold-border);
  color: var(--gold);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.header-btn:hover, .header-btn:active { background: var(--gold-dim); border-color: var(--gold); }
.header-btn svg { width: 15px; height: 15px; }

/* ── MESSAGES ── */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar { width: 2px; }
.messages::-webkit-scrollbar-thumb { background: var(--gold-border); border-radius: 2px; }

.typing-indicator {
  display: none;
  padding: 10px 14px;
  background: var(--clio-bubble);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  gap: 4px;
  align-items: center;
  align-self: flex-start;
  margin: 0 14px 4px;
  flex-shrink: 0;
}

.typing-indicator.visible { display: flex; }

.typing-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.3;
  animation: blink 1.1s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes blink {
  0%, 100% { opacity: 0.2; transform: scale(0.85); }
  50% { opacity: 0.9; transform: scale(1); }
}

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

/* Bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeUp 0.25s ease;
}

.message.user  { align-self: flex-end;  align-items: flex-end; }
.message.clio  { align-self: flex-start; align-items: flex-start; }
.message.model { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(200, 134, 10, 0.18);
  border-bottom-right-radius: 4px;
}

.message.clio .bubble, .message.model .bubble {
  background: var(--clio-bubble);
  border: 1px solid var(--gold-border);
  border-bottom-left-radius: 4px;
}

.message-time { font-size: 10px; color: var(--text-muted); margin-top: 3px; padding: 0 3px; }

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 30px;
  text-align: center;
}

.empty-eye { width: 56px; height: 56px; opacity: 0.35; }

.empty-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 300;
  letter-spacing: 5px;
  color: var(--gold-light);
  opacity: 0.6;
}

.empty-subtitle { font-size: 14px; color: var(--text-muted); font-style: italic; line-height: 1.7; }

/* ── INPUT AREA ── */
.input-area {
  padding: 10px 14px env(safe-area-inset-bottom, 8px);
  background: var(--bg);
  border-top: 1px solid var(--gold-border);
  flex-shrink: 0;
}

.input-attachments { display: flex; gap: 8px; margin-bottom: 8px; }

.attach-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  font-family: 'Lora', serif;
  transition: all 0.15s;
}

.attach-btn:hover, .attach-btn:active { background: var(--gold-dim); border-color: var(--gold); color: var(--gold-light); }
.attach-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.upload-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.upload-preview.visible { display: flex; }
.upload-preview-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.upload-preview-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 0; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--gold-border);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s;
}

.input-row:focus-within { border-color: rgba(200, 134, 10, 0.5); }

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Lora', serif;
  font-size: 15.5px;
  line-height: 1.5;
  resize: none;
  max-height: 110px;
  min-height: 26px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#messageInput::placeholder { color: var(--text-muted); font-style: italic; }

.send-btn, .voice-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.send-btn { background: var(--gold); color: var(--bg); }
.send-btn:hover, .send-btn:active { background: var(--gold-light); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }

.voice-btn { background: transparent; border: 1px solid var(--gold-border); color: var(--gold); }
.voice-btn:hover, .voice-btn:active { background: var(--gold-dim); }
.voice-btn.recording {
  background: rgba(180, 40, 40, 0.15);
  border-color: #c84040;
  color: #e05050;
  animation: recPulse 1s ease infinite;
}
.voice-btn svg { width: 17px; height: 17px; }

@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200, 50, 50, 0.25); }
  50%       { box-shadow: 0 0 0 7px rgba(200, 50, 50, 0); }
}

/* ── PANELS ── */
.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
}

.panel-overlay.visible {
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

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

.panel {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  background: var(--bg2);
  border-top: 1px solid var(--gold-border);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.28s ease;
  max-height: 65vh;
  overflow-y: auto;
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }

.panel-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px;
  font-weight: 300;
  letter-spacing: 4px;
  color: var(--gold-light);
}

.panel-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--gold-border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.panel-close svg { width: 10px; height: 10px; }

.fact-item {
  padding: 10px 12px;
  border-left: 2px solid var(--gold-border);
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.55;
}

.pattern-item {
  padding: 10px 12px;
  border-left: 2px solid var(--gold);
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.55;
}

.pattern-type { font-size: 9px; letter-spacing: 2px; color: var(--gold); margin-bottom: 3px; font-family: 'Cormorant Garamond', serif; }

/* ── PROFILE ── */
.profile-content { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0; }

.profile-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 1px solid var(--gold-border);
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); margin-bottom: 4px;
}

.profile-avatar svg { width: 30px; height: 30px; }

.profile-username {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  font-weight: 300;
  letter-spacing: 3px;
  color: var(--gold-light);
}

.logout-btn {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px;
  padding: 9px 20px;
  background: transparent;
  border: 1px solid rgba(200, 80, 80, 0.3);
  border-radius: 20px;
  color: #c06060;
  cursor: pointer;
  font-size: 12px;
  font-family: 'Lora', serif;
  letter-spacing: 1px;
  transition: all 0.15s;
}

.logout-btn:hover, .logout-btn:active { background: rgba(200, 80, 80, 0.1); border-color: #c06060; }

/* ── DESKTOP ── */
@media (min-width: 600px) {
  .app-body, .auth-body {
    max-width: 460px;
    margin: 0 auto;
    border-left: 1px solid var(--gold-border);
    border-right: 1px solid var(--gold-border);
  }
  .panel { max-width: 460px; }
}

/* ── MESSAGE AVATARS ── */
.message-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message.user .message-inner { flex-direction: row-reverse; }
.message.clio .message-inner { flex-direction: row; }

.message-right {
  display: flex;
  flex-direction: column;
}

.message.user .message-right { align-items: flex-end; }
.message.clio .message-right { align-items: flex-start; }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--gold-border);
}

.msg-avatar-clio {
  background: var(--surface);
}

.msg-avatar-clio svg { width: 100%; height: 100%; }

.msg-avatar-user {
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
}

.msg-avatar-user svg { width: 16px; height: 16px; }

.msg-avatar-img {
  background-color: var(--surface2);
  background-repeat: no-repeat;
  background-position: center;
}

/* Profile avatar upload */
.profile-avatar-wrap {
  position: relative;
  cursor: pointer;
}

.profile-avatar-wrap:hover .profile-avatar-overlay {
  opacity: 1;
}

.profile-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--gold-light);
}

.profile-avatar-overlay svg { width: 18px; height: 18px; }

/* ── PROFILE DUAL AVATARS ── */
.profile-avatars-row {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 6px;
}

.profile-avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-avatar-label {
  font-size: 9px;
  letter-spacing: 2.5px;
  color: var(--text-muted);
  font-family: 'Cormorant Garamond', serif;
  text-transform: uppercase;
}

/* ── ATTACHMENT PREVIEWS (dentro la bolla) ── */
.attachment-image {
  display: block;
  width: 100%;
  max-width: 220px;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 2px;
}

.bubble:has(.attachment-image) { padding: 5px; }
.bubble-text { margin-top: 6px; padding: 0 4px 2px; }

.attachment-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.attachment-doc svg { flex-shrink: 0; color: var(--gold); }
.attachment-doc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

.attachment-voice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 2px;
}

.attachment-voice svg { flex-shrink: 0; color: var(--gold); }
