:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-alt: #fafbff;
  --border: #e6e8f2;
  --border-strong: #d8dbec;
  --text: #1c1e2b;
  --text-soft: #6b6f8a;
  --text-faint: #9498b0;
  --accent: #6d5ef7;
  --accent-2: #a855f7;
  --accent-soft: #efecfe;
  --ok: #16a34a;
  --ok-soft: #e9fbef;
  --warn: #d97706;
  --warn-soft: #fff6e6;
  --danger: #e0335f;
  --danger-soft: #fdeaf0;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(28, 30, 43, 0.04), 0 10px 30px -14px rgba(28, 30, 43, 0.12);
  --shadow-pop: 0 20px 45px -12px rgba(28, 30, 43, 0.28);
  --font-head: "Plus Jakarta Sans", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-head); margin: 0; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px -8px rgba(109, 94, 247, 0.6);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: var(--font-head); font-size: 15.5px; }
.brand-text span { font-size: 12px; color: var(--text-soft); }

.pill {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Dashboard grid ---------- */

.dashboard {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 20px 24px 40px;
  align-items: start;
}

.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.col-left, .col-right { position: sticky; top: 78px; }
.col-center { min-height: 0; }

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

.card-title { font-size: 15.5px; font-weight: 700; }
.card-sub { margin: 4px 0 14px; font-size: 12.5px; color: var(--text-soft); }

/* ---------- Fields ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.field span em { font-weight: 400; font-style: normal; color: var(--text-faint); }

.field input, .field textarea, select {
  font-family: var(--font-body);
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.field-inline { margin-bottom: 14px; }

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--text-soft);
  cursor: pointer;
}
.checkbox-field input { margin-top: 2px; cursor: pointer; accent-color: var(--accent); }
.checkbox-field span { font-weight: 600; }
.checkbox-field em { font-weight: 400; font-style: normal; color: var(--text-faint); }

select {
  cursor: pointer;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 10px 24px -10px rgba(109, 94, 247, 0.65);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-ghost {
  background: var(--surface-alt);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Tone chips ---------- */

.tone-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.tone-chip {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 100px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tone-chip:hover { border-color: var(--accent); color: var(--accent); }
.tone-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: white;
  box-shadow: 0 6px 16px -8px rgba(109, 94, 247, 0.7);
}

.usage-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-faint); }

/* ---------- Tabs / generator ---------- */

.card-generator { display: flex; flex-direction: column; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; background: var(--surface-alt); padding: 4px; border-radius: 100px; width: fit-content; border: 1px solid var(--border); }

.tab {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 100px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-card); }

.selected-trends {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--surface-alt);
}
.selected-trends-label { font-size: 12px; font-weight: 700; color: var(--text-soft); }
.selected-trends-empty { font-size: 12px; color: var(--text-faint); margin-left: 6px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px 6px 12px;
  border-radius: 100px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}
.chip button {
  background: rgba(109, 94, 247, 0.15);
  border: none;
  border-radius: 50%;
  width: 16px; height: 16px;
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.chip-static { background: var(--surface-alt); color: var(--text-soft); border: 1px solid var(--border-strong); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.output-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  min-height: 140px;
  font-size: 14.5px;
  line-height: 1.65;
  margin-bottom: 16px;
  white-space: pre-wrap;
}
.output-box p { margin: 0; }
.output-placeholder { color: var(--text-faint); font-size: 13px; margin: 0; }

.platform-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }

.platform-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.platform-head { display: flex; align-items: center; justify-content: space-between; }
.platform-name { font-size: 12.5px; font-weight: 700; }
.char-count { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }
.char-count.over { color: var(--danger); font-weight: 700; }
.platform-text { font-size: 13px; line-height: 1.55; margin: 0; white-space: pre-wrap; flex: 1; }
.btn-copy {
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 100px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent); }

.hashtag-row { display: flex; flex-wrap: wrap; gap: 6px; }

.generator-actions { margin-top: auto; padding-top: 6px; }
.secondary-actions { display: flex; gap: 10px; margin-top: 10px; }
.secondary-actions .btn { flex: 1; }

/* ---------- History ---------- */

.card-history { max-height: 480px; display: flex; flex-direction: column; }
.history-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.history-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }

.history-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface-alt);
  transition: border-color 0.15s ease, transform 0.1s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.history-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.history-item-title { font-size: 13px; font-weight: 700; }
.history-item-date { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.history-item-snippet { font-size: 12.5px; color: var(--text-soft); margin: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-item-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.history-item-meta .chip-static { font-size: 10.5px; padding: 3px 8px; }

/* ---------- Trends ---------- */

.card-trends { max-height: calc(100vh - 100px); display: flex; flex-direction: column; }
.trends-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.trends-head select { padding: 6px 8px; font-size: 12px; }

.source-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 100px;
  background: var(--warn-soft);
  color: var(--warn);
  margin: 8px 0 0;
}

.trends-actions { display: flex; gap: 8px; margin-top: 10px; }
.trends-actions .btn { flex: 1; }
.trends-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-top: 12px; padding-right: 2px; }

.trend-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--surface-alt);
}
.trend-card:hover { border-color: var(--accent); }
.trend-card.selected {
  background: linear-gradient(135deg, var(--accent-soft), #f6f0ff);
  border-color: var(--accent);
}
.trend-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.trend-title { font-size: 13px; font-weight: 700; line-height: 1.35; }
.trend-traffic { font-size: 10.5px; font-weight: 700; color: var(--ok); background: var(--ok-soft); padding: 3px 7px; border-radius: 100px; white-space: nowrap; }
.trend-articles { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.trend-articles li { font-size: 11px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  box-shadow: var(--shadow-pop);
  border-left: 4px solid var(--accent);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in 0.25s ease;
  font-size: 13px;
}
.toast.hide { animation: toast-out 0.2s ease forwards; }
.toast-icon { font-size: 16px; line-height: 1.3; }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; margin: 0 0 2px; font-size: 13px; }
.toast-msg { margin: 0; color: var(--text-soft); font-size: 12.5px; line-height: 1.45; }
.toast-close { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 14px; padding: 0; }

.toast-error { border-left-color: var(--danger); }
.toast-error .toast-title { color: var(--danger); }
.toast-success { border-left-color: var(--ok); }
.toast-success .toast-title { color: var(--ok); }
.toast-warning { border-left-color: var(--warn); }
.toast-warning .toast-title { color: var(--warn); }
.toast-info { border-left-color: var(--accent); }
.toast-info .toast-title { color: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(24px); }
}

/* ---------- Loading / spinner ---------- */

.spin { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- History detail page ---------- */

.detail-page {
  max-width: 900px;
  margin: 24px auto 60px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 12px; }
.detail-grid p { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; }

/* ---------- Scrollbars ---------- */

.history-list::-webkit-scrollbar, .trends-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-thumb, .trends-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .dashboard { grid-template-columns: 280px minmax(0, 1fr) 300px; }
}

@media (max-width: 920px) {
  .dashboard { grid-template-columns: 1fr; }
  .col-left, .col-right { position: static; }
  .platform-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
}
