/* ============================================================
   DocFill — Design System & Styles
   Premium dark-mode glassmorphism UI with AI integration
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- Design Tokens --- */
:root {
  /* Background */
  --bg-primary: #07080d;
  --bg-secondary: #0f1018;
  --bg-card: rgba(255, 255, 255, 0.035);
  --bg-card-hover: rgba(255, 255, 255, 0.065);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --bg-glass-strong: rgba(255, 255, 255, 0.09);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(255, 255, 255, 0.08);

  /* Text */
  --text-primary: #eeeef5;
  --text-secondary: #9a9ab0;
  --text-muted: #5c5c72;
  --text-accent: #a78bfa;

  /* Accent */
  --accent-primary: #7c3aed;
  --accent-secondary: #a78bfa;
  --accent-gradient: linear-gradient(135deg, #7c3aed 0%, #a78bfa 50%, #c4b5fd 100%);
  --accent-glow: rgba(124, 58, 237, 0.3);

  /* AI accent */
  --ai-gradient: linear-gradient(135deg, #7c3aed 0%, #06b6d4 50%, #a78bfa 100%);
  --ai-glow: rgba(6, 182, 212, 0.2);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(124, 58, 237, 0.4);

  /* Status */
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.1);
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.1);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.1);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 50%;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--accent-glow);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-normal: 250ms var(--ease-out);
  --transition-slow: 400ms var(--ease-out);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Ambient background glow */
body::before {
  content: '';
  position: fixed;
  top: -30%;
  left: -10%;
  width: 60%;
  height: 60%;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -20%;
  right: -10%;
  width: 50%;
  height: 50%;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* --- Layout --- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Header / Logo --- */
.app-header {
  text-align: center;
  padding: var(--space-xl) 0 var(--space-lg);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.app-logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-logo .logo-icon {
  font-size: 2rem;
  -webkit-text-fill-color: initial;
  background: none;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.app-tagline {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 400;
  margin-top: var(--space-xs);
  letter-spacing: 0.5px;
}

/* Settings button */
.btn-settings {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-settings:hover {
  color: var(--text-primary);
  background: var(--bg-glass-strong);
  border-color: var(--border-accent);
}

/* --- Views --- */
.view {
  display: none;
  animation: fadeSlideIn 0.4s var(--ease-out);
}

.view.active {
  display: block;
}

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

/* --- Glass Card --- */
.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: all var(--transition-normal);
}

/* ============================================================
   HERO CARD — Start Fresh
   ============================================================ */

.hero-card {
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-2xl);
  border: 1px solid var(--border-accent);
}

.hero-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--ai-gradient);
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(124, 58, 237, 0.15);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--space-md);
}

.hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: var(--space-xs);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: var(--space-xl);
  line-height: 1.6;
}

.hero-section {
  margin-bottom: var(--space-lg);
}

/* --- File Upload Row --- */
.file-upload-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.btn-upload-file {
  flex-shrink: 0;
  gap: var(--space-sm);
}

.btn-upload-file svg {
  flex-shrink: 0;
}

.file-name {
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name.has-file {
  color: var(--success);
  font-weight: 500;
}

/* --- Upload Zone --- */
.upload-zone {
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
}

.upload-zone.upload-zone-compact {
  padding: var(--space-lg);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-primary);
  background: rgba(124, 58, 237, 0.05);
}

.upload-zone.drag-over {
  border-style: solid;
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.15);
}

.upload-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-muted);
}

.upload-zone-content svg {
  color: var(--text-muted);
  opacity: 0.6;
}

.upload-zone-content p {
  font-size: 0.85rem;
}

.upload-browse {
  color: var(--accent-secondary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.upload-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* --- Photo Preview Grid --- */
.photo-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.photo-preview-grid:empty {
  display: none;
}

.photo-preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.photo-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.7);
  border: none;
  border-radius: var(--radius-full);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.photo-preview-item:hover .photo-preview-remove {
  opacity: 1;
}

/* --- Optional Tag --- */
.optional-tag {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-glass);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ============================================================
   AI PROCESSING ANIMATION
   ============================================================ */

.ai-processing {
  text-align: center;
  padding: var(--space-xl) 0;
}

.ai-processing-animation {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: var(--space-md);
}

.ai-pulse {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--ai-gradient);
  animation: aiPulse 1.4s ease-in-out infinite;
}

.ai-pulse.delay-1 { animation-delay: 0.2s; }
.ai-pulse.delay-2 { animation-delay: 0.4s; }

@keyframes aiPulse {
  0%, 100% { transform: scale(0.8); opacity: 0.4; }
  50% { transform: scale(1.2); opacity: 1; }
}

.ai-processing-text {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: var(--space-xs);
}

.ai-processing-subtext {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* --- AI Sparkle --- */
.ai-sparkle {
  font-size: 1.1em;
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.15); }
}

/* --- AI Button --- */
.btn-ai {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
}

.btn-ai::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.btn-ai:hover::after {
  transform: translateX(100%);
}

/* ============================================================
   SAVED TEMPLATES SECTION
   ============================================================ */

.saved-templates-section {
  margin-top: var(--space-lg);
}

/* --- Template Cards --- */
.template-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.view-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.view-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: var(--space-xl);
}

.template-grid {
  display: grid;
  gap: var(--space-md);
}

.template-grid:empty {
  display: none;
}

.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.template-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.template-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--border-accent);
}

.template-card:hover::before {
  opacity: 1;
}

.template-card:active {
  transform: translateY(0) scale(0.99);
}

.template-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.template-card-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: var(--space-md);
}

.template-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.template-card-meta span {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* No templates message */
.no-templates-msg {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ============================================================
   AI EDITOR PANEL
   ============================================================ */

.ai-editor-panel {
  margin-bottom: var(--space-lg);
  border: 1px solid var(--border-accent);
  position: relative;
  overflow: hidden;
}

.ai-editor-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--ai-gradient);
}

.ai-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-md);
}

.ai-editor-title {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.btn-collapse {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  transition: all var(--transition-fast);
  border-radius: 4px;
}

.btn-collapse:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.btn-collapse.collapsed svg {
  transform: rotate(180deg);
}

.ai-editor-body {
  transition: all var(--transition-normal);
  overflow: hidden;
}

.ai-editor-body.collapsed {
  height: 0 !important;
  padding: 0;
  margin: 0;
  opacity: 0;
}

/* Chat Messages */
.ai-chat-messages {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-right: var(--space-xs);
}

.ai-message {
  display: flex;
  gap: var(--space-sm);
  animation: fadeSlideIn 0.3s var(--ease-out);
}

.ai-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: var(--bg-glass-strong);
}

.ai-message-assistant .ai-message-avatar {
  background: rgba(124, 58, 237, 0.2);
}

.ai-message-user .ai-message-avatar {
  background: rgba(6, 182, 212, 0.2);
}

.ai-message-content {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 85%;
}

.ai-message-content ul {
  margin: var(--space-xs) 0 0;
  padding-left: var(--space-md);
}

.ai-message-content li {
  margin-bottom: 2px;
  font-size: 0.8rem;
}

.ai-message-user .ai-message-content {
  background: rgba(124, 58, 237, 0.1);
  border-color: rgba(124, 58, 237, 0.2);
  color: var(--text-primary);
}

/* Chat Input */
.ai-chat-input-row {
  display: flex;
  gap: var(--space-sm);
}

.ai-chat-input {
  flex: 1;
  padding: 10px var(--space-md) !important;
  font-size: 0.88rem !important;
}

.btn-send {
  padding: 10px 14px !important;
  min-height: 42px;
  flex-shrink: 0;
}

/* ============================================================
   FORM FIELDS — with AI suggest buttons
   ============================================================ */

.field-group {
  margin-bottom: var(--space-lg);
}

.field-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field-required {
  color: var(--error);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  background: var(--error-bg);
  border-radius: 4px;
  text-transform: uppercase;
}

.field-description {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  line-height: 1.5;
}

.field-input-row {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
}

.field-input-row .text-input {
  flex: 1;
}

.btn-suggest {
  flex-shrink: 0;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.25);
  color: var(--accent-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  height: fit-content;
  margin-top: 2px;
}

.btn-suggest:hover {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--accent-primary);
}

.btn-suggest:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   FORM INPUTS
   ============================================================ */

.input-group {
  margin-bottom: var(--space-md);
}

.input-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.text-input {
  width: 100%;
  padding: var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: all var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.text-input:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.text-input::placeholder {
  color: var(--text-muted);
}

textarea.text-input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

/* --- JSON paste area --- */
.json-paste-area {
  min-height: 160px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.3);
}

.btn-primary:hover {
  background: #6d28d9;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg-glass-strong);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--border-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  min-height: 40px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  font-size: 1.1rem;
}

.btn-save-template {
  font-size: 0.82rem;
  padding: 8px 14px;
  min-height: 38px;
}

/* ============================================================
   TABLE EDITOR
   ============================================================ */

.table-editor {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-editor table {
  width: 100%;
  border-collapse: collapse;
  min-width: 300px;
}

.table-editor th {
  background: var(--bg-glass-strong);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.table-editor td {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--border-subtle);
}

.table-editor td:last-child {
  width: 44px;
  text-align: center;
}

.table-editor input {
  width: 100%;
  padding: 10px var(--space-sm);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: all var(--transition-fast);
  min-height: 40px;
}

.table-editor input:focus {
  background: var(--bg-input);
  border-color: var(--border-accent);
}

.table-editor .btn-remove-row {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 8px;
  border-radius: 6px;
  transition: all var(--transition-fast);
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-editor .btn-remove-row:hover {
  color: var(--error);
  background: var(--error-bg);
}

.table-actions {
  padding: var(--space-sm);
  display: flex;
  justify-content: center;
}

.btn-add-row {
  background: none;
  border: 1px dashed var(--border-medium);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 10px var(--space-md);
  border-radius: 6px;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 40px;
}

.btn-add-row:hover {
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
  background: rgba(124, 58, 237, 0.05);
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--border-subtle);
}

/* ============================================================
   PROMPT SECTION (for template upload view)
   ============================================================ */

.prompt-section {
  margin-bottom: var(--space-xl);
}

.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: var(--space-md);
}

.section-title .section-number {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.25);
}

/* ============================================================
   ALERTS
   ============================================================ */

.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  animation: fadeSlideIn 0.3s var(--ease-out);
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--error);
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid rgba(52, 211, 153, 0.2);
  color: var(--success);
}

.alert-warning {
  background: var(--warning-bg);
  border: 1px solid rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

/* ============================================================
   SPINNER
   ============================================================ */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

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

/* ============================================================
   BACK BAR & BADGE
   ============================================================ */

.back-bar {
  margin-bottom: var(--space-lg);
}

.selected-template-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-glass);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--accent-secondary);
  font-weight: 600;
  margin-bottom: var(--space-lg);
}

/* ============================================================
   MODALS (Settings, Save Template)
   ============================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

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

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideUp 0.3s var(--ease-out);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close-modal {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.btn-close-modal:hover {
  background: var(--bg-glass-strong);
  color: var(--text-primary);
}

.modal-body {
  /* space for content */
}

/* Settings */
.settings-section {
  margin-bottom: var(--space-lg);
}

.settings-label {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.settings-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

.settings-link {
  color: var(--accent-secondary);
  text-decoration: none;
  font-weight: 500;
}

.settings-link:hover {
  text-decoration: underline;
}

.api-key-input-row {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.api-key-input-row .text-input {
  flex: 1;
}

.btn-toggle-key {
  flex-shrink: 0;
  padding: 10px 12px;
  min-height: 42px;
}

.api-key-actions {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.api-key-status {
  font-size: 0.82rem;
  min-height: 20px;
}

/* ============================================================
   FILE INPUT STYLING
   ============================================================ */

input[type="file"].text-input {
  padding: var(--space-md);
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.4;
}

input[type="file"].text-input::file-selector-button {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  margin-right: 12px;
  transition: background var(--transition-fast);
}

input[type="file"].text-input::file-selector-button:hover {
  background: #6d28d9;
}

/* ============================================================
   RESPONSIVE — TABLET (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {
  .app-container {
    padding: var(--space-md) var(--space-md);
  }

  .template-header {
    flex-direction: column;
    gap: var(--space-md);
  }

  .template-header .btn {
    width: 100%;
  }

  .template-grid {
    gap: var(--space-md);
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .file-upload-row {
    flex-direction: column;
    align-items: stretch;
  }

  .file-name {
    text-align: center;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (max-width: 640px)
   ============================================================ */
@media (max-width: 640px) {
  :root {
    --space-lg: 20px;
    --space-xl: 28px;
  }

  .app-container {
    padding: var(--space-sm) var(--space-sm);
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  }

  .app-header {
    padding: var(--space-lg) 0 var(--space-md);
  }

  .app-logo {
    font-size: 1.5rem;
  }

  .app-logo .logo-icon {
    font-size: 1.6rem;
  }

  .app-tagline {
    font-size: 0.8rem;
  }

  .hero-card {
    padding: var(--space-lg);
  }

  .hero-title {
    font-size: 1.25rem;
  }

  /* Cards */
  .glass-card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .template-card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .template-card-name {
    font-size: 1rem;
  }

  .template-card-desc {
    font-size: 0.82rem;
    margin-bottom: var(--space-sm);
  }

  .template-card-meta {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  /* View titles */
  .view-title {
    font-size: 1.1rem;
  }

  .view-subtitle {
    font-size: 0.82rem;
    margin-bottom: var(--space-lg);
  }

  .section-title {
    font-size: 0.88rem;
  }

  /* Upload zone */
  .upload-zone {
    padding: var(--space-lg);
  }

  .upload-zone.upload-zone-compact {
    padding: var(--space-md);
  }

  .photo-preview-item {
    width: 60px;
    height: 60px;
  }

  /* Form fields */
  .field-group {
    margin-bottom: var(--space-md);
  }

  .text-input {
    padding: 14px var(--space-md);
    font-size: 1rem;
    border-radius: var(--radius-sm);
  }

  /* Table editor */
  .table-editor {
    border-radius: var(--radius-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-editor table {
    min-width: 320px;
  }

  .table-editor th {
    padding: var(--space-sm);
    font-size: 0.7rem;
  }

  .table-editor td {
    padding: var(--space-xs);
  }

  .table-editor input {
    font-size: 0.85rem;
    padding: 8px var(--space-sm);
    min-height: 38px;
  }

  /* Buttons */
  .btn {
    padding: 14px var(--space-lg);
    font-size: 0.88rem;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
  }

  /* AI Editor */
  .ai-chat-messages {
    max-height: 200px;
  }

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

  /* Selected badge */
  .selected-template-badge {
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
  }

  /* Alert */
  .alert {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
  }

  .back-bar {
    margin-bottom: var(--space-md);
  }

  /* Field input row stacks on mobile */
  .field-input-row {
    flex-direction: column;
  }

  .btn-suggest {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (max-width: 400px)
   ============================================================ */
@media (max-width: 400px) {
  .app-container {
    padding: var(--space-xs) var(--space-xs);
  }

  .app-header {
    padding: var(--space-md) 0 var(--space-sm);
  }

  .app-logo {
    font-size: 1.3rem;
  }

  .hero-card {
    padding: var(--space-md);
  }

  .section-title .section-number {
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
  }

  .template-card {
    padding: var(--space-sm) var(--space-md);
  }
}

/* ============================================================
   LARGE SCREENS — 2 column template grid
   ============================================================ */
@media (min-width: 641px) {
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --- Selection --- */
::selection {
  background: rgba(124, 58, 237, 0.3);
  color: #fff;
}

.progress-bar-container {
  width: 100%;
  max-width: 300px;
  height: 6px;
  background: var(--bg-glass-strong);
  border-radius: 3px;
  overflow: hidden;
  margin: 1rem auto;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  width: 0%;
  transition: width 0.5s ease-out;
}
