/* ================================================
   AI Copywriter — Styles
   ================================================ */

:root {
  --primary:        #6366f1;
  --primary-light:  #eef2ff;
  --primary-dark:   #4f46e5;
  --accent:         #f59e0b;
  --accent-light:   #fffbeb;
  --success:        #10b981;
  --success-light:  #ecfdf5;
  --error:          #ef4444;
  --error-light:    #fef2f2;

  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --surface-hover:  #f8fafc;
  --border:         #e2e8f0;
  --border-focus:   #6366f1;

  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      20px;

  --shadow-sm:      0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:         0 4px 12px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg:      0 10px 30px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.06);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.18s ease;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== LAYOUT ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 24px;
  align-items: start;
  padding: 24px 0 48px;
}

/* ===== HEADER ===== */
.header {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4c1d95 100%);
  color: #fff;
  padding: 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,.25);
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  font-size: 28px;
  line-height: 1;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}

.header-sub {
  font-size: 13px;
  color: rgba(255,255,255,.65);
  margin-top: 2px;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap;
}

.badge-dot {
  width: 7px;
  height: 7px;
  background: #34d399;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== MAIN ===== */
.main { min-height: calc(100vh - 70px - 48px); }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.form-panel { display: flex; flex-direction: column; gap: 16px; }

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.card-icon { font-size: 18px; }

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.card-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: 14px;
}

/* ===== LANGUAGE TABS ===== */
.lang-tabs {
  display: flex;
  gap: 8px;
}

.lang-btn {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
}

.lang-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}

/* ===== FORM ELEMENTS ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group:last-child { margin-bottom: 0; }

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

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.req { color: var(--error); margin-left: 2px; }

.input,
.textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input:focus,
.textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

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

.textarea { resize: vertical; min-height: 70px; }

.select-wrap { position: relative; }

.select-wrap::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 13px;
}

.select {
  width: 100%;
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* ===== OLLAMA CUSTOM ===== */
.ollama-custom {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.ollama-custom .input { flex: 1; }

.btn-sm {
  padding: 8px 12px;
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all var(--transition);
}

.btn-sm:hover {
  background: var(--primary);
  color: #fff;
}

/* ===== TONE GRID ===== */
.tone-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tone-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.tone-card input[type="radio"] { display: none; }

.tone-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.tone-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(99,102,241,.18);
}

.tone-icon { font-size: 20px; }

.tone-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.3;
}

.tone-card:has(input:checked) .tone-label {
  color: var(--primary);
  font-weight: 600;
}

/* ===== GENERATE BUTTON ===== */
.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 15px 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  transition: all var(--transition);
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
}

.btn-generate:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99,102,241,.45);
}

.btn-generate:active { transform: translateY(0); }

.btn-generate:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.btn-generate-icon { font-size: 18px; }

/* ===== ERROR MESSAGE ===== */
.error-msg {
  padding: 12px 16px;
  background: var(--error-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #b91c1c;
  font-size: 13px;
  line-height: 1.5;
}

/* ===== OUTPUT PANEL ===== */
.output-panel {
  min-height: 500px;
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  border-radius: var(--radius-lg);
}

/* ===== PLACEHOLDER ===== */
.output-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
  padding: 48px 32px;
}

.placeholder-inner { max-width: 380px; }

.placeholder-emoji {
  font-size: 52px;
  margin-bottom: 16px;
  display: block;
}

.placeholder-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.placeholder-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.placeholder-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}

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

.stat-num {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.stat-desc {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-plus {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-light);
}

.provider-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.chip {
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* ===== LOADING ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  gap: 16px;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3.5px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

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

/* ===== OUTPUT CONTENT ===== */
.output-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.output-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #fafbff;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.meta-badges { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-model { background: #ede9fe; color: #5b21b6; }
.badge-lang  { background: #dbeafe; color: #1e40af; }
.badge-tone  { background: #fef9c3; color: #92400e; }

.btn-regen {
  padding: 6px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
}

.btn-regen:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ===== OUTPUT TABS ===== */
.output-tabs {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
}

.tab-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.tab-chip {
  background: rgba(255,255,255,.25);
  padding: 1px 7px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.tab-btn:not(.active) .tab-chip {
  background: var(--primary-light);
  color: var(--primary);
}

.btn-copy-all {
  margin-left: auto;
  padding: 7px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
}

.btn-copy-all:hover {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

/* ===== TAB PANELS ===== */
.tab-panel { display: none; padding: 20px; }
.tab-panel.active { display: block; }

/* ===== SEGMENTS ===== */
.segments-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.segment-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.segment-card:hover {
  border-color: #c7d2fe;
  box-shadow: var(--shadow-sm);
}

.segment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--primary-light) 0%, #f5f3ff 100%);
  border-bottom: 1px solid #e0e7ff;
}

.segment-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segment-num {
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.segment-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
}

.btn-copy {
  padding: 5px 12px;
  background: var(--surface);
  border: 1.5px solid #c7d2fe;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-copy:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-copy.copied {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.segment-body {
  padding: 16px;
  background: var(--surface);
}

.segment-content {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== FOOTER ===== */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 0;
  text-align: center;
}

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

.footer span { color: var(--primary); font-weight: 600; }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== SCROLLBAR ===== */
.output-panel::-webkit-scrollbar { width: 6px; }
.output-panel::-webkit-scrollbar-track { background: transparent; }
.output-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.output-panel::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 380px 1fr;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px 0 32px;
  }

  .output-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  .header-title { font-size: 17px; }
  .header-sub { display: none; }
}

@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .layout { gap: 16px; }

  .placeholder-stats { gap: 10px; }
  .stat-num { font-size: 28px; }

  .form-row { grid-template-columns: 1fr; }
  .tone-grid { grid-template-columns: 1fr 1fr; }

  .output-tabs { flex-wrap: wrap; }
  .btn-copy-all { margin-left: 0; width: 100%; justify-content: center; }
  .btn-copy-all { display: flex; }

  .header-badge { display: none; }
}
