/* ============================================================
   SAUFIN-AI PRO DESIGN SYSTEM v3.0 (Stripe-inspired)
   ============================================================ */

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

:root {
  --bg: #ffffff;
  --bg-subtle: #f6f9fc;
  --bg-muted: #f1f5f9;
  --border: #e3e8ee;
  --border-strong: #cfd7df;
  --text-primary: #0a2540;
  --text-secondary: #425466;
  --text-muted: #697386;
  --text-light: #8898aa;
  --brand: #635bff;
  --brand-dark: #5851e8;
  --brand-light: #7a73ff;
  --brand-subtle: #f7f5ff;
  --success: #0e9f6e;
  --success-bg: #def7ec;
  --danger: #e02424;
  --danger-bg: #fde8e8;
  --info: #1a56db;
  --info-bg: #e1effe;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'SF Mono', Monaco, Menlo, Consolas, monospace;
  --r-sm: 6px;
  --r: 8px;
  --r-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(50, 50, 93, 0.04);
  --shadow-sm: 0 2px 5px -1px rgba(50, 50, 93, 0.08), 0 1px 3px -1px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 6px -1px rgba(50, 50, 93, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 10px 15px -3px rgba(50, 50, 93, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 15px 35px -5px rgba(50, 50, 93, 0.15), 0 5px 15px -3px rgba(0, 0, 0, 0.08);
  --shadow-brand: 0 7px 14px 0 rgba(99, 91, 255, 0.3), 0 3px 6px 0 rgba(0, 0, 0, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.011em;
}

/* HEADER */
header {
  background: rgba(255, 255, 255, 0.85) !important;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border) !important;
  padding: 14px 32px !important;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-xs);
}

.logo, header > div:first-child {
  font-size: 19px !important;
  font-weight: 800 !important;
  letter-spacing: -0.03em;
  color: var(--text-primary) !important;
  display: flex;
  align-items: center;
  gap: 8px;
  background: none !important;
  -webkit-text-fill-color: initial !important;
}

.logo:before {
  content: "S";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #635bff 0%, #7a73ff 100%);
  color: white;
  border-radius: var(--r-sm);
  font-weight: 800;
  font-size: 16px;
  box-shadow: var(--shadow-brand);
}

/* TABS */
.tabs, nav {
  display: flex;
  gap: 4px;
  background: var(--bg-muted);
  padding: 4px;
  border-radius: var(--r);
  border: 1px solid var(--border);
}

.tab, .tabs button, nav button, button[onclick*="switchTab"] {
  padding: 8px 16px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: var(--text-secondary) !important;
  background: transparent !important;
  border: none !important;
  border-radius: var(--r-sm) !important;
  cursor: pointer !important;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tab:hover, button[onclick*="switchTab"]:hover {
  color: var(--text-primary) !important;
  background: white !important;
}

.tab.active, button[onclick*="switchTab"].active {
  background: white !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-sm);
}

/* LAYOUT */
.container, main { max-width: 1080px; margin: 0 auto; padding: 40px 24px; }

.hero { text-align: center; margin-bottom: 48px; padding: 0 16px; }

.hero h1, h1 {
  font-size: 44px !important;
  font-weight: 800 !important;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  margin-bottom: 16px !important;
  line-height: 1.1;
}

.hero p { font-size: 18px !important; color: var(--text-muted); max-width: 560px; margin: 0 auto; }

/* CARDS */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-lg) !important;
  padding: 24px !important;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  transition: box-shadow 0.2s ease;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-title {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: var(--text-primary);
  margin-bottom: 16px !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

/* FORM */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

textarea, input[type="text"], input[type="email"], input[type="number"], select {
  width: 100%;
  padding: 12px 14px !important;
  font-size: 15px !important;
  font-family: var(--font);
  color: var(--text-primary);
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  outline: none;
  transition: all 0.15s ease;
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.12);
}

textarea { min-height: 260px !important; line-height: 1.6; }

/* BUTTONS */
button, .btn {
  padding: 10px 20px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  border: 1px solid transparent !important;
  border-radius: var(--r) !important;
  cursor: pointer !important;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font);
  white-space: nowrap;
}

button:disabled { opacity: 0.5; cursor: not-allowed !important; }

.primary {
  background: var(--brand) !important;
  color: white !important;
  border-color: var(--brand) !important;
  box-shadow: var(--shadow-sm);
}

.primary:hover:not(:disabled) {
  background: var(--brand-dark) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-brand);
}

.secondary {
  background: white !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-strong) !important;
}

.secondary:hover:not(:disabled) {
  color: var(--text-primary) !important;
  border-color: var(--text-light) !important;
}

.upload-btn {
  background: white !important;
  color: var(--brand) !important;
  border-color: var(--brand) !important;
}

.upload-btn:hover:not(:disabled) {
  background: var(--brand-subtle) !important;
  transform: translateY(-1px);
}

#downloadArticleBtn {
  background: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
}

#downloadArticleBtn:hover:not(:disabled) {
  background: #0b8159 !important;
  transform: translateY(-1px);
}

/* OUTPUT */
.output {
  background: var(--bg-subtle) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--r) !important;
  padding: 16px !important;
  min-height: 260px !important;
  font-size: 15px !important;
  line-height: 1.7 !important;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  max-height: 600px;
}

/* STATUS */
.status {
  margin-top: 14px !important;
  font-size: 14px !important;
  padding: 12px 16px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.status:empty { display: none; }

.status.error { color: var(--danger) !important; background: var(--danger-bg); border: 1px solid rgba(224,36,36,0.2); }
.status.success { color: var(--success) !important; background: var(--success-bg); border: 1px solid rgba(14,159,110,0.2); }
.status.info { color: var(--info) !important; background: var(--info-bg); border: 1px solid rgba(26,86,219,0.2); }

/* STATS */
.stats {
  margin-top: 12px !important;
  font-size: 13px !important;
  color: var(--text-light);
  display: flex;
  gap: 20px;
  align-items: center;
}

.stats span { font-weight: 600; color: var(--text-secondary); }
.upload-hint { font-size: 12px !important; color: var(--text-light); margin-top: 10px; }
.controls { display: flex; gap: 10px !important; align-items: center; margin-top: 16px !important; flex-wrap: wrap; }

/* CHAT */
.chat-wrapper {
  background: white !important;
  border: 1px solid var(--border);
  border-radius: var(--r-lg) !important;
  box-shadow: var(--shadow-sm) !important;
  height: calc(100vh - 200px) !important;
  min-height: 500px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px !important;
  border-bottom: 1px solid var(--border) !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
}

.chat-header h2 { font-size: 16px !important; font-weight: 700 !important; color: var(--text-primary); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px !important;
  display: flex;
  flex-direction: column;
  gap: 16px !important;
  background: var(--bg-subtle);
}

.msg { display: flex; gap: 12px !important; max-width: 85% !important; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg .avatar {
  width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px !important;
  flex-shrink: 0;
  font-weight: 700;
}

.msg.user .avatar { background: var(--brand) !important; color: white !important; }
.msg.assistant .avatar { background: white !important; color: var(--brand) !important; border: 1px solid var(--border); }

.msg .bubble {
  background: white !important;
  padding: 12px 16px !important;
  border-radius: var(--r-lg) !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.msg.user .bubble { background: var(--brand) !important; color: white !important; border-color: var(--brand); }

.chat-input-bar {
  padding: 16px 20px !important;
  border-top: 1px solid var(--border) !important;
  display: flex;
  gap: 10px !important;
  align-items: flex-end;
  background: white;
}

#chatInput {
  flex: 1;
  min-height: 44px !important;
  max-height: 150px;
  resize: none;
  padding: 12px 16px !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--r) !important;
  font-size: 14px !important;
  font-family: var(--font);
  outline: none;
}

#chatInput:focus { border-color: var(--brand) !important; box-shadow: 0 0 0 3px rgba(99,91,255,0.12); }

.send-btn {
  background: var(--brand) !important;
  color: white !important;
  padding: 12px 20px !important;
  font-weight: 600 !important;
  border-radius: var(--r) !important;
}

.chat-welcome { text-align: center; color: var(--text-light) !important; padding: 48px 20px !important; }
.chat-welcome h3 { color: var(--text-primary) !important; margin-bottom: 12px !important; font-size: 20px !important; font-weight: 700 !important; }

.chat-suggestions { display: flex; gap: 8px !important; flex-wrap: wrap; justify-content: center; margin-top: 24px !important; }

.suggestion {
  background: white !important;
  border: 1px solid var(--border-strong) !important;
  padding: 8px 14px !important;
  border-radius: 999px !important;
  font-size: 13px !important;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-secondary);
}

.suggestion:hover {
  background: var(--brand) !important;
  border-color: var(--brand) !important;
  color: white !important;
  transform: translateY(-1px);
}

/* PROGRESS */
.progress-container {
  display: none;
  margin-top: 20px;
  padding: 20px;
  background: var(--brand-subtle);
  border: 1px solid rgba(99, 91, 255, 0.2);
  border-radius: var(--r-lg);
}

.progress-container.active { display: block; }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--brand-dark);
  font-weight: 600;
}

.progress-timer {
  font-family: var(--font-mono);
  font-size: 15px;
  background: white;
  padding: 4px 12px;
  border-radius: var(--r-sm);
  color: var(--brand);
  font-weight: 700;
  border: 1px solid var(--border);
}

.progress-bar-bg { height: 6px; background: rgba(99,91,255,0.15); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand) 0%, var(--brand-light) 100%); width: 0%; transition: width 0.5s ease; border-radius: 3px; }

.progress-step { font-size: 13px; color: var(--brand-dark); display: flex; align-items: center; gap: 8px; }
.progress-step .spinner { width: 14px; height: 14px; border: 2px solid rgba(99,91,255,0.2); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }

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

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* RESPONSIVE */
@media (max-width: 800px) {
  header {
    padding: 12px 16px !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .logo, header > div:first-child { justify-content: center; font-size: 17px !important; }

  .tabs, nav {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
  }

  .tab, button[onclick*="switchTab"] { padding: 9px 6px !important; font-size: 12px !important; text-align: center; }

  .container, main { padding: 24px 16px !important; }
  .hero h1, h1 { font-size: 28px !important; }
  .hero p { font-size: 15px !important; }
  .card { padding: 18px !important; }

  textarea { min-height: 180px !important; font-size: 14px !important; }
  .output { min-height: 180px !important; font-size: 14px !important; padding: 14px !important; }

  .controls { flex-direction: column !important; align-items: stretch !important; }
  .controls > * { width: 100% !important; }
  button { width: 100% !important; }

  .chat-wrapper { height: calc(100vh - 220px) !important; }
  .msg { max-width: 92% !important; }
  .chat-input-bar { padding: 12px !important; }
  .send-btn { width: auto !important; min-width: 60px; }
}
