:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --green: #10b981;
  --green-bg: #d1fae5;
  --green-text: #065f46;
  --yellow: #d97706;
  --yellow-bg: #fef3c7;
  --yellow-text: #92400e;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --sidebar-w: 232px;
  --header-h: 56px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea20 0%, #764ba220 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 380px;
  border: 1px solid var(--border);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}

.login-logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), #764ba2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
  flex-shrink: 0;
}

.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo p { font-size: 12px; color: var(--text-2); }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}

.header-logo-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--accent), #764ba2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 15px;
}

.header-spacer { flex: 1; }

.app-body {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: fixed;
  top: var(--header-h);
  bottom: 0;
  left: 0;
  padding-bottom: 16px;
}

.sidebar-section {
  padding: 18px 16px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 7px;
  margin: 1px 8px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  transition: all 0.12s;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }

.sidebar-new-btn {
  margin: 8px 16px 0;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: calc(100vh - var(--header-h));
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }

input[type=text],
input[type=password],
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

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

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

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.12s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-danger { background: var(--red-bg); color: var(--red-text); border: 1px solid #fca5a5; }
.btn-danger:hover { background: #fca5a5; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Tags / Chips ───────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.tag-accent {
  background: var(--accent-light);
  color: var(--accent);
  border-color: #c7d2fe;
}

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

/* ── Chips input ────────────────────────────────────────────────────────────── */
.chips-input-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 42px;
  background: var(--surface);
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chips-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.chip-remove {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: #818cf8;
  margin-left: 2px;
}

.chip-remove:hover { color: var(--accent-hover); }

.chips-input {
  border: none;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  min-width: 120px;
  background: transparent;
  padding: 2px 4px;
  color: var(--text);
}

/* ── Region grid ────────────────────────────────────────────────────────────── */
.region-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.region-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
  transition: all 0.12s;
  user-select: none;
}

.region-check:hover { border-color: var(--accent); color: var(--text); background: var(--accent-light); }
.region-check.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); font-weight: 500; }
.region-check input { display: none; }

/* ── Score badges ───────────────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.score-high { background: var(--green-bg); color: var(--green-text); }
.score-mid { background: var(--yellow-bg); color: var(--yellow-text); }
.score-low { background: var(--red-bg); color: var(--red-text); }

/* ── Score bars ─────────────────────────────────────────────────────────────── */
.score-bar-wrap { margin: 5px 0; }
.score-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 4px;
}

.score-bar-label strong { color: var(--text); font-weight: 600; }
.score-bar-track { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.score-bar-fill.high { background: linear-gradient(90deg, #34d399, var(--green)); }
.score-bar-fill.mid  { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.score-bar-fill.low  { background: linear-gradient(90deg, #f87171, var(--red)); }

/* ── Status badges ──────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.status-pending   { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.status-analyzing { background: #ede9fe; color: #6d28d9; border: 1px solid #ddd6fe; }
.status-complete  { background: var(--green-bg); color: var(--green-text); border: 1px solid #a7f3d0; }
.status-error     { background: var(--red-bg); color: var(--red-text); border: 1px solid #fca5a5; }

/* ── Domain pills ───────────────────────────────────────────────────────────── */
.domain-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-weight: 600;
}

.domain-taken     { background: var(--red-bg); color: var(--red-text); border: 1px solid #fca5a5; }
.domain-available { background: var(--green-bg); color: var(--green-text); border: 1px solid #a7f3d0; }
.domain-unknown   { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ── Star rating ────────────────────────────────────────────────────────────── */
.stars { display: flex; gap: 3px; align-items: center; }
.star { font-size: 20px; cursor: pointer; color: #d1d5db; transition: color 0.1s, transform 0.1s; line-height: 1; }
.star.filled { color: #f59e0b; }
.star:hover { color: #f59e0b; transform: scale(1.15); }

/* ── Ranking table ──────────────────────────────────────────────────────────── */
.rank-table { width: 100%; border-collapse: collapse; }

.rank-table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  border-bottom: 2px solid var(--border);
  background: var(--surface-2);
}

.rank-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.rank-table tr:last-child td { border-bottom: none; }
.rank-table tr.top-rank { background: linear-gradient(to right, rgba(99,102,241,0.05), transparent); }

.rank-medal { font-size: 17px; line-height: 1; }
.rank-num { font-size: 12px; font-weight: 700; color: var(--text-2); }

/* ── Brand cards ────────────────────────────────────────────────────────────── */
.brand-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
  transition: box-shadow 0.15s;
}

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

.brand-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  cursor: pointer;
  user-select: none;
}

.brand-card-header:hover { background: var(--surface-2); }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.02em; flex: 1; }

.brand-card-body {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 14px 0;
}

.analysis-section h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  margin-bottom: 8px;
}

.bullet-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.bullet-list li { font-size: 12px; color: var(--text-2); padding-left: 14px; position: relative; line-height: 1.4; }
.bullet-list li::before { content: '·'; position: absolute; left: 0; font-weight: 700; color: var(--accent); }

/* ── Project grid ───────────────────────────────────────────────────────────── */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.project-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}

.project-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: #c7d2fe;
  transform: translateY(-2px);
}

.project-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.project-card p { font-size: 12px; color: var(--text-2); margin-bottom: 14px; line-height: 1.5; }

/* ── Split layout ───────────────────────────────────────────────────────────── */
.split {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

/* ── Inline form ────────────────────────────────────────────────────────────── */
.inline-form { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-form input { flex: 1; }

/* ── Loading / empty ────────────────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  color: var(--text-2);
  font-size: 13px;
}

.empty {
  text-align: center;
  padding: 52px 24px;
  color: var(--text-2);
}

.empty-icon { font-size: 36px; margin-bottom: 14px; opacity: 0.5; }
.empty h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 13px; max-width: 300px; margin: 0 auto 20px; line-height: 1.5; }

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.01em; }
.page-header p { font-size: 13px; color: var(--text-2); }

/* ── Alert ──────────────────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--red-bg); color: var(--red-text); border: 1px solid #fca5a5; }
.alert-success { background: var(--green-bg); color: var(--green-text); border: 1px solid #a7f3d0; }

/* ── Text callouts ──────────────────────────────────────────────────────────── */
.summary-box {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-left-color: var(--accent);
}

.recommendation-box {
  font-size: 13px;
  color: var(--text);
  line-height: 1.65;
  padding: 10px 14px;
  background: #f0fdf4;
  border-radius: 8px;
  border: 1px solid #a7f3d0;
  border-left: 3px solid var(--green);
  margin-top: 10px;
}

/* ── Misc helpers ───────────────────────────────────────────────────────────── */
.text-2  { color: var(--text-2); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.mt-1  { margin-top: 4px; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 12px; }
.mt-4  { margin-top: 16px; }
.mb-2  { margin-bottom: 8px; }
.mb-3  { margin-bottom: 12px; }
.mb-4  { margin-bottom: 16px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.flex-1 { flex: 1; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.w-full { width: 100%; }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ── Analyze status bar ─────────────────────────────────────────────────────── */
.analyze-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #ede9fe;
  border-top: 1px solid #ddd6fe;
  font-size: 13px;
  color: #6d28d9;
}

/* ── TM risk tag ────────────────────────────────────────────────────────────── */
.tm-low    { color: var(--green-text); background: var(--green-bg); border: 1px solid #a7f3d0; }
.tm-medium { color: var(--yellow-text); background: var(--yellow-bg); border: 1px solid #fcd34d; }
.tm-high   { color: var(--red-text); background: var(--red-bg); border: 1px solid #fca5a5; }
