:root {
  --bg: #070b14;
  --bg-elevated: #0f172a;
  --surface: #131c31;
  --surface-hover: #1a2744;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #22d3ee;
  --accent-dim: #0891b2;
  --accent-glow: rgba(34, 211, 238, 0.15);
  --border: rgba(148, 163, 184, 0.14);
  --success: #34d399;
  --warning: #fbbf24;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --topbar-h: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

.hidden {
  display: none !important;
}

/* —— Topbar —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: rgba(7, 11, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #0f172a;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 0.95rem;
  font-weight: 600;
}

.brand-text small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.auth-guest,
.auth-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-badge {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-container {
  position: relative;
  display: flex;
  align-items: center;
}

.user-badge-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background-color 0.15s;
}

.user-badge-btn:hover {
  background-color: var(--surface-hover);
}

.dropdown-icon {
  font-size: 0.6rem;
  transition: transform 0.2s;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 320px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  z-index: 200;
  animation: slideDown 0.2s ease-out;
}

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

.user-menu-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.dropdown-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.user-menu-dropdown .dropdown-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.user-menu-dropdown .history-list-dropdown,
.user-menu-dropdown .profile-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 1rem 1rem;
  overflow-y: auto;
  flex: 1;
}

.user-menu-dropdown .history-list-dropdown .history-item,
.user-menu-dropdown .profile-form .field {
  width: 100%;
}

.user-menu-dropdown .history-item {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.user-menu-dropdown .history-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.user-menu-dropdown .history-file {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.user-menu-dropdown .profile-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.user-menu-dropdown .profile-form input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.user-menu-dropdown .profile-form input[disabled] {
  background: var(--surface);
  color: var(--text-muted);
}

.user-menu-dropdown .profile-form .field {
  display: grid;
  gap: 0.35rem;
}

.user-menu-dropdown .profile-note {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.dropdown-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.history-list-dropdown {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  overflow-y: auto;
  flex: 1;
}

.history-list-dropdown .history-item {
  padding: 0.75rem;
  font-size: 0.8rem;
}

.history-list-dropdown .history-snippet {
  -webkit-line-clamp: 1;
  font-size: 0.8rem;
}

.history-list-dropdown .history-stats {
  font-size: 0.7rem;
}

.btn-xs {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

/* —— Intro —— */
.page-intro {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 1rem;
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.page-intro h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
}

/* —— Main layout —— */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.workspace {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 960px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-header {
  margin-bottom: 1.25rem;
}

.card-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.card-desc {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.card-divider {
  margin: 1.5rem 0 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.card-divider h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* —— Input tabs —— */
.input-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.25rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.tab {
  flex: 1;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.tab.active {
  background: var(--surface-hover);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.tab-panel textarea {
  width: 100%;
  min-height: 220px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.65;
  resize: vertical;
}

.tab-panel textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* —— File drop —— */
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  padding: 2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}

.file-drop:hover {
  border-color: var(--accent-dim);
  background: var(--surface-hover);
}

.file-drop-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.file-drop-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.file-drop-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.file-drop-name {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--accent);
  word-break: break-all;
}

/* —— Form fields —— */
.config-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 520px) {
  .config-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field input,
.field select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  color: #0c4a6e;
}

.btn-primary:hover {
  box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-danger {
  background: #f87171;
  color: white;
}

.btn-danger:hover {
  box-shadow: 0 8px 24px rgba(248, 113, 113, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-lg {
  padding: 0.9rem 1.25rem;
  font-size: 1rem;
  margin-top: 1.25rem;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}

/* —— Output —— */
.status-pill {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.status-pill.is-loading {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.3);
}

.status-pill.is-success {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.3);
}

.status-pill.is-error {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
}

.result-empty {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-empty p {
  margin: 0;
  max-width: 280px;
}

.result-body {
  animation: fadeIn 0.3s ease;
}

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

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.meta-tag {
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.meta-tag strong {
  color: var(--text);
  font-weight: 600;
}

.result-text-wrap {
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  max-height: 420px;
  overflow-y: auto;
}

#summary-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 0.95rem;
}

/* —— History —— */
.card-history {
  margin-top: 1.25rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-empty,
.history-hint {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.history-item {
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.history-item:hover {
  border-color: rgba(34, 211, 238, 0.25);
}

.history-item-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.history-model {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--accent-glow);
  color: var(--accent);
}

.history-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-snippet {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-snippet strong {
  color: var(--text);
  font-weight: 500;
}

.history-stats {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* —— Footer —— */
.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* —— Modal —— */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.admin-dialog {
  max-width: 680px;
  width: min(100%, 680px);
  padding: 1.5rem;
}

.admin-user-row {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.admin-user-row:last-child {
  border-bottom: none;
}

.admin-user-info {
  display: grid;
  gap: 0.25rem;
}

.admin-user-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.admin-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-history-header {
  margin: 1rem 0 0.75rem;
}

.admin-history-header h3 {
  margin: 0 0 0.25rem;
}

.admin-user-stats {
  margin: 1rem 0 1rem;
}

.admin-user-stats-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.admin-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
}

.admin-stat-card strong {
  display: block;
  font-size: 1.25rem;
  margin-bottom: 0.35rem;
}

.admin-stat-card span {
  color: var(--text-muted);
}

.admin-stat-wide {
  grid-column: span 2;
}

.admin-panel-content {
  max-height: 60vh;
  overflow: auto;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

.modal-dialog h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
}

.modal-desc {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-form .field {
  margin-bottom: 1rem;
}

.modal-switch {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.form-error {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: #f87171;
}
