@import url("https://fonts.googleapis.com/css2?family=Literata:opsz,wght@7..72,600;7..72,700&family=Manrope:wght@400;500;600;700&display=swap");

:root {
  --bg: #0f1419;
  --bg2: #172029;
  --ink: #e8eef4;
  --muted: #9aabbc;
  --accent: #3d9a7a;
  --accent2: #c4a35a;
  --line: #2a3644;
  --danger: #d4726a;
  --ok: #5fbf8f;
  --font-display: "Literata", "Iowan Old Style", Georgia, serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1d3a32 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #3a2f18 0%, transparent 50%),
    linear-gradient(180deg, #101820, #0c1116 60%);
}

.page {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 4rem;
}

.header { margin-bottom: 2rem; }
.brand {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0;
  letter-spacing: -0.02em;
}
.tagline { color: var(--muted); margin: 0.4rem 0 0; }

.create label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.start-row { margin-top: 1.25rem; }
input#topic,
input#siteUrl,
input#excludeKeywords,
textarea#businessContext {
  width: min(640px, 100%);
  display: block;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  font-size: 1.05rem;
  font-family: inherit;
}
textarea#businessContext {
  resize: vertical;
  min-height: 4rem;
}
select#mode.region-select {
  size: initial;
  height: auto;
  padding: 0.75rem 1rem;
}
.region-label { margin-top: 1rem; }
.region-picker { position: relative; width: min(420px, 100%); }
.region-filter {
  width: 100%;
  display: block;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  margin-top: 0.35rem;
}
.region-selected {
  margin-top: 0.45rem;
  font-size: 0.92rem;
  color: var(--ink);
}
.region-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.25rem;
  max-height: 240px;
  overflow: auto;
  background: #15202a;
  border: 1px solid var(--line);
  border-radius: 10px;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 30;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
}
.region-item {
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
.region-item:hover,
.region-item.is-selected {
  background: #2a5a8a;
}
.region-empty {
  padding: 0.65rem 0.7rem;
  color: var(--muted);
}
.region-select {
  width: min(420px, 100%);
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  font-size: 1rem;
  margin-top: 0.45rem;
}
.region-select option {
  padding: 0.35rem 0.4rem;
}
.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.45rem 0 0;
}
button#startBtn, .tabs button {
  border: 0;
  border-radius: 10px;
  padding: 0.9rem 1.2rem;
  background: var(--accent);
  color: #04140f;
  font-weight: 700;
  cursor: pointer;
}
.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}
.tabs button.active {
  background: #243249;
  color: var(--ink);
  border-color: #3b516a;
}
.msg { margin-top: 0.75rem; color: var(--accent2); }

.project { margin-top: 2rem; }
.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
#projectTopic {
  font-family: var(--font-display);
  font-size: 1.7rem;
  margin: 0;
}
.meta { color: var(--muted); margin: 0.35rem 0 0; }
.progress-wrap { min-width: min(320px, 100%); }
.progress {
  height: 10px;
  background: #1c2733;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7ed0b0);
  transition: width 0.35s ease;
}
#progressLabel { color: var(--muted); font-size: 0.9rem; margin: 0.4rem 0 0; }

.history {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.step {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  background: rgba(23, 32, 41, 0.7);
  font-size: 0.85rem;
}
.step.done { border-color: #2f6b52; }
.step.running { border-color: var(--accent2); }
.step.failed { border-color: var(--danger); }
.step .st { color: var(--muted); display: block; margin-top: 0.2rem; font-size: 0.75rem; }

.tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.55rem 0.4rem;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: #243249;
  font-size: 0.75rem;
}
pre, .report-preview {
  white-space: pre-wrap;
  background: rgba(23, 32, 41, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  line-height: 1.5;
  max-height: 65vh;
  overflow: auto;
}
.downloads {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.downloads a {
  color: #04140f;
  background: var(--accent2);
  text-decoration: none;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  font-weight: 700;
}
.recent { margin-top: 3rem; }
.recent h2 { font-family: var(--font-display); font-size: 1.3rem; }
.recent ul { list-style: none; padding: 0; margin: 0; }
.recent li {
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.recent button.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0;
}
.empty { color: var(--muted); }

a { color: #8fd4b8; }

.page-wide { width: min(1440px, calc(100% - 1.5rem)); }
.history-wrap { margin-bottom: 1rem; color: var(--muted); }
.history-wrap summary { cursor: pointer; margin-bottom: 0.5rem; }

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.6rem;
  margin: 0.75rem 0 1rem;
}
.kpi-card {
  background: rgba(23, 32, 41, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
}
.kpi-val {
  display: block;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
}
.kpi-label { color: var(--muted); font-size: 0.78rem; }

.workspace { margin-top: 0.5rem; }
.sticky-bar, .sticky-filters {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(12, 17, 22, 0.98), rgba(12, 17, 22, 0.92));
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem;
  margin-bottom: 0.65rem;
}
.sticky-filters { top: 58px; z-index: 19; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ws-toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; justify-content: space-between; }
.view-modes, .saved-views, .quick-actions, .card-actions, .bulk-bar {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center;
}
.view-modes button, .quick-actions button, .card-actions button, .bulk-bar button, .chip {
  border: 1px solid var(--line);
  background: #1a2430;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.view-modes button.active, .chip.active {
  border-color: var(--accent);
  background: #1e3a31;
  color: #b6ead4;
}
.filters input, .filters select, .mini-select, .url-input {
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-size: 0.85rem;
}
.filters input { min-width: 160px; }
.bulk-bar {
  margin-bottom: 0.65rem;
  padding: 0.5rem 0.65rem;
  border: 1px dashed #3b516a;
  border-radius: 10px;
}
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 12px; }
.kw-table { min-width: 1100px; }
.kw-table thead th {
  position: sticky;
  top: 0;
  background: #15202a;
  z-index: 5;
}
.kw-table tr.selected { background: rgba(61, 154, 122, 0.12); }
.kw-table tr.hl-cluster { box-shadow: inset 3px 0 0 var(--accent2); }
.kw-text { min-width: 220px; outline: none; }
.kw-text:focus { background: #1c2a36; }
.url-input { width: 110px; }
.trust { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.78rem; }
.muted, .small { color: var(--muted); }
.small { font-size: 0.82rem; }

.board-grid, .plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}
.cluster-card, .plan-card, .detail-card, .comp-row {
  background: rgba(23, 32, 41, 0.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
}
.cluster-card.active-card { border-color: var(--accent); }
.cluster-card h3, .plan-card h3, .detail-card h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.kw-mini { margin: 0.5rem 0; padding-left: 1.1rem; font-size: 0.85rem; }
.kw-mini li { cursor: grab; margin: 0.2rem 0; }
.cluster-detail { margin-top: 1rem; }
.detail-head { display: flex; justify-content: space-between; align-items: center; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
  margin: 0.75rem 0;
}
.gaps-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .gaps-layout { grid-template-columns: 1fr; }
  .sticky-filters { top: 0; position: relative; }
}
.comp-list { display: flex; flex-direction: column; gap: 0.55rem; }
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #243249;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  z-index: 50;
  max-width: min(360px, calc(100% - 2rem));
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
button.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.hint-inline { margin: 0.5rem 0; }
