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

:root {
  --bg: #070b14;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-solid: #0f1523;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-hover: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(139, 92, 246, 0.4);
  --primary: #8b5cf6;
  --primary-2: #6366f1;
  --primary-glow: rgba(139, 92, 246, 0.3);
  --accent: #22d3ee;
  --accent-glow: rgba(34, 211, 238, 0.2);
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.08);
  --green-border: rgba(16, 185, 129, 0.25);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.08);
  --blue-border: rgba(59, 130, 246, 0.25);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.08);
  --red-border: rgba(239, 68, 68, 0.25);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: rgba(255, 255, 255, 0.07);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 15% 10%, rgba(139, 92, 246, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 80%, rgba(99, 102, 241, 0.08) 0%, transparent 50%);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { max-width: 920px; margin: 0 auto; padding: 0 20px; }

/* === Header === */
.header {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(7, 11, 20, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-icon { font-size: 22px; }
.logo-text {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, #c4b5fd 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* === Hero === */
.hero {
  padding: 64px 0 52px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -60px; left: 50%;
  transform: translateX(-50%);
  width: 600px; height: 300px;
  background: radial-gradient(ellipse, rgba(139, 92, 246, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.25);
  color: #c4b5fd;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  margin-bottom: 20px;
}

.hero-title {
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #f1f5f9 20%, #c4b5fd 60%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 14px;
}

.hero-subtitle {
  font-size: clamp(16px, 2.5vw, 20px);
  color: var(--text-muted);
  font-weight: 400;
  line-height: 1.5;
  margin-bottom: 12px;
}

.hero-desc {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 32px;
  line-height: 1.7;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; align-items: center; gap: 3px; }

.stat-num {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, #8b5cf6, #22d3ee);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label { font-size: 12px; color: var(--text-dim); }

/* === Quick Templates === */
.templates-section {
  margin-bottom: 28px;
}

.templates-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

.templates-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tpl-btn {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 6px 14px;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.tpl-btn:hover {
  background: rgba(139, 92, 246, 0.1);
  border-color: rgba(139, 92, 246, 0.35);
  color: #c4b5fd;
  transform: translateY(-1px);
}

/* === Form Card === */
.form-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 32px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  margin-bottom: 32px;
  transition: border-color 0.3s;
}

.form-card:hover { border-color: rgba(139, 92, 246, 0.2); }

.form-section {
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 580px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 7px; }

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.required { color: #a78bfa; }

input, textarea, select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 11px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
}

input::placeholder, textarea::placeholder { color: var(--text-dim); }

input:focus, textarea:focus, select:focus {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(139, 92, 246, 0.05);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

input.field-error, textarea.field-error, select.field-error {
  border-color: rgba(239, 68, 68, 0.6);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

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

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  cursor: pointer;
}

select option { background: #0f1523; color: var(--text); }

/* === Buttons === */
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 22px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
  letter-spacing: 0.1px;
}

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

.btn-primary {
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(139, 92, 246, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-sm { padding: 7px 14px; font-size: 13px; }

.btn-pdf {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
}

.btn-pdf:hover { box-shadow: 0 6px 20px rgba(220, 38, 38, 0.45); transform: translateY(-1px); }

/* === Alert === */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 14px;
  line-height: 1.55;
}

.alert code {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.alert-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.alert-error  { background: var(--red-bg);   border: 1px solid var(--red-border);   color: #fca5a5; }
.alert-success { background: var(--green-bg); border: 1px solid var(--green-border); color: #6ee7b7; }
.alert-info   { background: var(--blue-bg);  border: 1px solid var(--blue-border);  color: #93c5fd; }

/* === History === */
.history-section { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--border); }

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-empty {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color 0.2s, background 0.2s;
  flex-wrap: wrap;
}

.history-item:hover {
  border-color: rgba(139, 92, 246, 0.25);
  background: var(--glass-hover);
}

.history-info { flex: 1; min-width: 0; }

.history-client {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.history-date { font-size: 12px; color: var(--text-dim); }

.history-type {
  font-size: 11px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #a78bfa;
  padding: 1px 8px;
  border-radius: 10px;
}

.history-links { display: flex; gap: 6px; flex-shrink: 0; }

.history-link {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
}

.history-link:hover { background: rgba(139, 92, 246, 0.1); color: #c4b5fd; border-color: rgba(139,92,246,0.3); }

.history-link.pdf { color: #fca5a5; }
.history-link.pdf:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #fca5a5; }

/* === Loading Overlay === */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 11, 20, 0.88);
  backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}

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

.spinner {
  width: 48px; height: 48px;
  border: 3px solid rgba(139, 92, 246, 0.2);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-muted);
  font-size: 15px;
}

.loading-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: -12px;
}

/* === Result Page === */
.result-header { margin-bottom: 28px; }

.result-title {
  font-size: clamp(18px, 3vw, 24px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 14px;
}

.result-meta { display: flex; flex-wrap: wrap; gap: 8px; }

.meta-badge {
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 500;
}

.meta-badge.type {
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.2);
  color: #67e8f9;
}

/* === Sections Grid === */
.sections-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 640px) { .sections-grid { grid-template-columns: 1fr; } }

.section-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, transform 0.2s;
}

.section-card:hover {
  border-color: rgba(139, 92, 246, 0.3);
  transform: translateY(-1px);
}

.section-card--accent {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.06) 0%, rgba(99, 102, 241, 0.04) 100%);
  border-color: rgba(139, 92, 246, 0.2);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-icon { font-size: 17px; }

.section-header h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.section-card p, .markdown-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
}

/* === Full Text / Document Block === */
.full-text-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}

.full-text-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(139, 92, 246, 0.04);
}

.full-text-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.full-text-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.full-text-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.full-text-content {
  padding: 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.75;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,92,246,0.3) transparent;
}

.full-text-content::-webkit-scrollbar { width: 5px; height: 5px; }
.full-text-content::-webkit-scrollbar-track { background: transparent; }
.full-text-content::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.3); border-radius: 3px; }

/* === Bottom Actions === */
.bottom-actions { display: flex; gap: 12px; flex-wrap: wrap; padding-bottom: 8px; }

/* === Footer === */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  text-align: center;
  margin-top: auto;
  background: rgba(0,0,0,0.2);
}

.footer p { font-size: 12px; color: var(--text-dim); }

/* === Main === */
.main { flex: 1; padding: 0 0 56px; }
