/* ─── Mira Web App Styles ───────────────────────────────────── */

:root {
  --primary: #6C5CE7;
  --primary-dark: #5A4BD1;
  --primary-light: #A29BFE;
  --bg: #0F0F1A;
  --bg-card: #1A1A2E;
  --bg-input: #252540;
  --text: #E8E8F0;
  --text-muted: #8888A0;
  --border: #2D2D45;
  --success: #00B894;
  --danger: #FF6B6B;
  --warning: #FDCB6E;
  --shadow: 0 8px 32px rgba(0,0,0,0.3);
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ── Scrollbar ──────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ── Auth Pages (Login / Register) ──────────────────────────── */

.auth-container {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0F0F1A 0%, #1A1A2E 50%, #16213E 100%);
}

.auth-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 40px;
  width: 420px;
  max-width: 90vw;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-card h1 {
  font-size: 28px;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--primary-light), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 30px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  width: 100%;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--primary-light);
  width: 100%;
  margin-top: 12px;
}
.btn-ghost:hover { background: var(--bg-input); }

.auth-error {
  background: rgba(255,107,107,0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 14px;
  display: none;
}

.auth-success {
  background: rgba(0,184,148,0.1);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 14px;
  display: none;
  text-align: center;
}

.auth-success .pending-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.auth-success p {
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 8px;
}

/* ── Sidebar Toggle (mobile) ──────────────────────────────────── */

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  margin-right: 8px;
}
.sidebar-toggle:hover {
  background: var(--bg-input);
}

/* ── Sidebar Overlay (mobile) ────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

/* ── Main Layout (Chat View) ────────────────────────────────── */

.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  display: none;
}

/* Sidebar */
.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h2 {
  font-size: 18px;
  background: linear-gradient(135deg, var(--primary-light), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header .profile-btn {
  background: var(--bg-input);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.sidebar-header .profile-btn:hover { background: var(--primary); }

.new-chat-btn {
  margin: 12px 16px;
  padding: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s;
}
.new-chat-btn:hover { opacity: 0.9; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.session-item {
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.2s;
  border: 1px solid transparent;
}

.session-item:hover { background: var(--bg-input); }
.session-item.active {
  background: var(--bg-input);
  border-color: var(--primary);
}

.session-item .title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item .meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Main Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header .title {
  font-size: 16px;
  font-weight: 600;
}

.chat-header .user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.chat-header .user-badge .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--success));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 14px;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .sender {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  opacity: 0.7;
}

.message.assistant .sender { color: var(--primary-light); }
.message.user .sender { color: rgba(255,255,255,0.7); }

.message .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
}

/* Typing indicator */
.typing-indicator {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 16px 20px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: none;
}

.typing-dots {
  display: flex;
  gap: 6px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--primary-light);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* Input area */
.chat-input {
  padding: 16px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  background: var(--bg);
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.chat-input textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  font-family: inherit;
}

.chat-input textarea:focus {
  border-color: var(--primary);
}

.chat-input .send-btn {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input .send-btn:hover { opacity: 0.9; }
.chat-input .send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Welcome Screen ─────────────────────────────────────────── */

.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.welcome-screen .mira-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--success));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 20px;
}

.welcome-screen h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.welcome-screen p {
  color: var(--text-muted);
  max-width: 400px;
  line-height: 1.6;
  margin-bottom: 24px;
}

.welcome-screen .suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.welcome-screen .suggestion-chip {
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.welcome-screen .suggestion-chip:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* ── Profile Modal ──────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  display: none;
}

.modal-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 32px;
  width: 480px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.modal-card h2 {
  font-size: 22px;
  margin-bottom: 24px;
}

.modal-card .form-row {
  display: flex;
  gap: 12px;
}

.modal-card .form-row .form-group {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

/* ── Plan & Q&A Display ──────────────────────────────────────── */

.profile-plan {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}

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

.plan-badge-lg {
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: white;
}

.plan-expiry {
  font-size: 12px;
  font-weight: 600;
}

.qa-usage {
  margin-bottom: 8px;
}

.qa-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.qa-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.qa-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease, background 0.3s ease;
}

.plan-upgrade {
  margin-top: 10px;
  text-align: center;
}

.plan-upgrade a {
  text-decoration: none;
}
.plan-upgrade a:hover {
  text-decoration: underline;
}

/* ── Region Tabs (Plans Modal & Registration Closed) ─────────── */

.region-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.region-tab {
  padding: 7px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.region-tab:hover {
  border-color: var(--primary);
  color: var(--text);
}

.region-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── Plans Grid (Modal) ──────────────────────────────────────── */

.plans-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.plan-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: border-color 0.2s;
}
.plan-card:hover {
  border-color: var(--primary);
}

.plan-card .plan-name {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.plan-card .plan-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 8px;
}

.plan-card .plan-qa {
  font-size: 13px;
  color: var(--text-muted);
}

.plan-card .plan-days {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    z-index: 100;
    transition: left 0.3s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }
  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    display: block;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chat-header .title {
    font-size: 14px;
  }

  /* Mobile: more compact input, bigger tap target */
  .chat-input {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }
  .chat-input textarea {
    padding: 10px 12px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .chat-input .send-btn {
    padding: 10px 16px;
    min-width: 44px;
    min-height: 44px;
  }

  .message { max-width: 90%; }
}

/* ── Logout Button ──────────────────────────────────────────── */

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.logout-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Delete session button */
.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

.session-item:hover .delete-btn {
  opacity: 1;
}

.delete-btn:hover { color: var(--danger); }

.session-item-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.session-item-text {
  flex: 1;
  min-width: 0;
}

/* ── Sidebar Footer ──────────────────────────────────────────── */

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.admin-link {
  display: block;
  text-decoration: none;
  color: var(--primary-light);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  transition: background 0.2s;
  text-align: center;
}

.admin-link:hover {
  background: var(--bg-input);
  color: var(--text);
}
