/* ── Reset & Variables ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-2:   #22263a;
  --border:      #2e3245;
  --accent:      #6c63ff;
  --accent-h:    #8b85ff;
  --accent-dim:  rgba(108, 99, 255, 0.15);
  --text:        #e8eaf6;
  --text-muted:  #7b82a0;
  --success:     #4ade80;
  --error:       #f87171;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  0.18s ease;
}

/* ── Base ──────────────────────────────────────────────────── */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  padding: 2rem 1rem 4rem;
}

/* ── Layout ────────────────────────────────────────────────── */
.app-container {
  max-width: 780px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

header h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  background: linear-gradient(135deg, #a29bfe 0%, #6c63ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  letter-spacing: 0.5px;
}

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

main { display: flex; flex-direction: column; }

/* ── Section Title ─────────────────────────────────────────── */
.section-title {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 1.25rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

/* ── Fields ────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.field:last-child { margin-bottom: 0; }

.field-group { display: grid; gap: 1rem; }
.two-col   { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 560px) {
  .two-col, .three-col { grid-template-columns: 1fr; }
}

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

input[type="text"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  width: 100%;
  font-family: inherit;
}

input[readonly] {
  opacity: 0.55;
  cursor: default;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

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

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237b82a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.2rem;
}

.char-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

.char-count.warn { color: var(--error); }

/* ── Toggle Group ──────────────────────────────────────────── */
.toggle-group {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.55rem 0.5rem;
  transition: background var(--transition), color var(--transition);
}

.toggle.active {
  background: var(--accent);
  color: #fff;
}

.toggle:not(.active):hover {
  background: var(--accent-dim);
  color: var(--text);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.85rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: background var(--transition), transform var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-h);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  transition: background var(--transition);
}

.btn-secondary:hover { background: rgba(108, 99, 255, 0.25); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.45rem 0.9rem;
  transition: border-color var(--transition), color var(--transition);
}

.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }
.btn-ghost.small { font-size: 0.75rem; padding: 0.3rem 0.7rem; margin-top: 0.75rem; }

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Output ────────────────────────────────────────────────── */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.output-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.output-actions { display: flex; gap: 0.5rem; }

.output-text {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.8;
  padding: 1.25rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── History ───────────────────────────────────────────────── */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0.75rem 1rem;
  transition: border-color var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.history-item:hover { border-color: var(--accent); }

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.history-title {
  font-size: 0.85rem;
  font-weight: 500;
}

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

.history-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border-radius: 999px;
  color: var(--accent-h);
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  padding: 0.1rem 0.45rem;
  margin-left: 0.4rem;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.65rem 1.25rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Loading card ──────────────────────────────────────────── */
.loading-card {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border: 3px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Output placeholder ────────────────────────────────────── */
.output-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.875rem;
  line-height: 1.6;
}

.output-placeholder svg {
  opacity: 0.35;
}

/* ── History header ────────────────────────────────────────── */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.history-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.75rem 0;
}

.history-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity var(--transition);
}

.history-item:hover .history-arrow {
  opacity: 1;
  color: var(--accent-h);
}

/* ── Utility ───────────────────────────────────────────────── */
.hidden { display: none !important; }
