:root {
  --bg: #081120;
  --panel: rgba(15, 23, 42, 0.76);
  --panel-strong: rgba(15, 23, 42, 0.94);
  --muted: #94a3b8;
  --text: #edf2ff;
  --primary: #7c3aed;
  --primary-strong: #5b21b6;
  --border: rgba(148, 163, 184, 0.18);
  --user-bubble: linear-gradient(135deg, #4f46e5, #7c3aed);
  --assistant-bubble: rgba(15, 23, 42, 0.9);
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1d4ed8 0%, #0f172a 35%, #020817 100%);
  color: var(--text);
  font-family: Inter, 'Segoe UI', sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  width: min(460px, 100%);
  background: rgba(15, 23, 42, 0.76);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.auth-card.signup-mode .brand-block {
  margin-bottom: 1.25rem;
}

.auth-card.signup-mode .auth-header {
  margin-bottom: 1rem;
}

.auth-card.signup-mode .auth-header h2 {
  font-size: 1.8rem;
}

.auth-card.signup-mode .auth-form {
  gap: 0.7rem;
}

.auth-card.signup-mode .field {
  gap: 0.3rem;
}

.auth-card.signup-mode .field input {
  padding: 0.7rem 0.9rem;
}

.auth-card.signup-mode .primary-btn {
  padding: 0.75rem 1rem;
}

.auth-card.signup-mode .social-auth {
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.auth-card.signup-mode .social-auth-btn {
  padding: 0.6rem 1rem;
}

.auth-card.signup-mode .text-link {
  margin-top: 0.65rem;
}

.auth-card.signup-mode .auth-message {
  margin-top: 0.4rem;
}

@media (max-height: 800px) {
  .auth-shell {
    align-items: flex-start;
    padding-block: 0.45rem;
  }

  .auth-card.signup-mode {
    padding: 1.25rem 1.5rem;
  }

  .auth-card.signup-mode .brand-block {
    margin-bottom: 0.9rem;
  }

  .auth-card.signup-mode .auth-header {
    margin-bottom: 0.65rem;
  }

  .auth-card.signup-mode .auth-header h2 {
    font-size: 1.6rem;
  }

  .auth-card.signup-mode .auth-header p {
    display: none;
  }

  .auth-card.signup-mode .auth-form {
    gap: 0.5rem;
  }

  .auth-card.signup-mode .field input {
    padding-block: 0.55rem;
  }

  .auth-card.signup-mode .social-auth {
    margin-top: 0.45rem;
  }

  .auth-card.signup-mode .social-auth-btn {
    padding-block: 0.5rem;
  }
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.brand-badge {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.45);
}

.brand-badge.small {
  width: 36px;
  height: 36px;
  border-radius: 12px;
}

.eyebrow {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: #c4b5fd;
}

.eyebrow.small {
  font-size: 0.65rem;
}

.brand-block h1,
.brand-row h2,
.topbar h3 {
  margin: 0.2rem 0 0;
}

.auth-header {
  margin-bottom: 1.5rem;
  text-align: center;
}

.auth-header h2 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
}

.auth-header p {
  margin: 0;
  color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.social-auth {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.social-auth-label {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.82rem;
}

.social-auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.social-auth-btn:hover {
  background: rgba(148, 163, 184, 0.14);
}

.auth-message {
  min-height: 1.2rem;
  margin: 0.75rem 0 0;
  color: #f87171;
  font-size: 0.85rem;
  font-weight: 700;
}

.app-modal {
  width: min(440px, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.app-modal::backdrop {
  background: rgba(2, 8, 23, 0.76);
  backdrop-filter: blur(4px);
}

.app-modal-content {
  padding: 1.75rem;
}

.app-modal-content h2 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
}

.app-modal-content p {
  margin: 0;
  color: #cbd5e1;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.app-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.5rem;
}

.app-modal-actions .primary-btn,
.app-modal-actions .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  text-decoration: none;
}

.app-modal-actions .secondary-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.field label {
  color: #e2e8f0;
  font-size: 0.9rem;
}

.field input,
select,
textarea {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 0.9rem 1rem;
}

.password-input-wrap {
  position: relative;
}

.password-input-wrap .password-input {
  width: 100%;
  padding-right: 3.25rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.password-toggle:hover {
  color: var(--text);
}

.password-toggle:focus-visible {
  outline: 2px solid #c4b5fd;
  outline-offset: 2px;
}

.password-toggle svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.password-toggle .eye-closed,
.password-toggle[aria-pressed="true"] .eye-open {
  display: none;
}

.password-toggle[aria-pressed="true"] .eye-closed {
  display: block;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

.primary-btn,
.secondary-btn,
.text-link {
  border-radius: 12px;
  border: none;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.sidebar-actions .secondary-btn.active {
  border-color: rgba(124, 58, 237, 0.8);
  background: rgba(124, 58, 237, 0.12);
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white;
  padding: 0.9rem 1.2rem;
}

.secondary-btn {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.8rem 1rem;
}

.small-btn {
  padding: 0.7rem 0.9rem;
}

.text-link {
  background: transparent;
  color: #c4b5fd;
  padding: 0;
  margin-top: 1rem;
}

.primary-btn:hover,
.secondary-btn:hover,
.text-link:hover {
  transform: translateY(-1px);
}

.wide {
  width: 100%;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.25rem;
  min-height: 100vh;
  padding: 1.25rem;
}

.sidebar,
.main-panel {
  background: rgba(15, 23, 42, 0.74);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.sidebar {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.history-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-label {
  margin: 0 0 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  min-height: 0;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  cursor: pointer;
}

.conversation-item.active {
  border-color: rgba(124, 58, 237, 0.8);
  background: rgba(124, 58, 237, 0.12);
}

.conversation-item strong {
  font-size: 0.96rem;
}

.conversation-item span,
.empty-item,
.empty-chat p {
  color: var(--muted);
  font-size: 0.82rem;
}

.main-panel {
  display: flex;
  flex-direction: column;
  padding: 1.2rem;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.plan-badge {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.28);
  font-size: 0.8rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1.2rem;
}

.stat-card {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem 1.1rem;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.55rem;
  font-size: 2rem;
}

.billing-card {
  margin-top: 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem 1.2rem;
}

.billing-card h4 {
  margin: 0.25rem 0 0;
}

.media-panel {
  margin-top: 1.2rem;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1rem;
}

.media-header {
  margin-bottom: 1rem;
}

.media-header h4 {
  margin: 0.3rem 0 0;
}

.media-grid {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 1rem;
}

.media-upload-box,
.media-controls {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
}

.upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem;
  color: var(--text);
  background: rgba(124, 58, 237, 0.18);
  cursor: pointer;
  text-align: center;
}

.upload-label input {
  display: none;
}

.media-preview {
  margin-top: 0.9rem;
  height: 220px;
  min-height: 220px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  overflow: hidden;
}

.media-preview.empty {
  color: var(--muted);
  padding: 1rem;
}

.media-preview img,
.media-frame img,
.media-frame video {
  max-width: 100%;
  max-height: 260px;
  width: 100%;
  border-radius: 12px;
  object-fit: cover;
}

.media-preview img {
  height: 100%;
  max-height: none;
}

.media-controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.prompt-with-attach {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  overflow: hidden;
}

.prompt-with-attach textarea {
  min-height: 80px;
  max-height: 200px;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.9rem 1rem 0.9rem 6rem;
}

.chat-image-attachment {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: 100%;
  padding: 0.65rem 0.75rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.chat-image-attachment img {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: cover;
}

.chat-image-attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-photo-btn {
  flex: 0 0 auto;
  width: 1.8rem;
  height: 1.8rem;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  line-height: 1;
}

.attach-photo-btn {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4.5rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(124, 58, 237, 0.18);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.media-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.media-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.88rem;
}

.media-status.success {
  color: #86efac;
}

.media-status.warning {
  color: #fbbf24;
}

.media-status.error {
  color: #fca5a5;
}

.media-output {
  display: block;
}

.media-result {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.media-frame {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
}

.chat-panel {
  margin-top: 1.2rem;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.message-row {
  display: flex;
  align-items: flex-start;
}

.message-row.user {
  justify-content: flex-end;
}

.message-bubble {
  align-self: flex-start;
  flex: 0 0 auto;
  max-width: min(75%, 760px);
  padding: 0 1rem 0 0;
  border-radius: 8px;
  line-height: 1;
  white-space: pre-wrap;
}

.message-bubble.user {
  background: var(--user-bubble);
  color: white;
}

.message-bubble.assistant {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
}

.composer {
  display: flex;
  gap: 0.8rem;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  min-height: 80px;
  max-height: 200px;
}

.empty-chat {
  display: grid;
  place-items: center;
  min-height: 240px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px dashed var(--border);
  border-radius: 18px;
  text-align: center;
  padding: 2rem;
}

.empty-chat h4 {
  margin-bottom: 0.5rem;
}

@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 640px) {
  .auth-card {
    padding: 1.25rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .composer,
  .billing-card,
  .mini-form {
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .message-bubble {
    max-width: 100%;
  }
}
