/* ============================================================
   Sea Level SEO Command Center - Dashboard Theme
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2035;
  --bg-hover: #1e293b;
  --border: #1e293b;
  --border-light: #2d3a4f;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --accent-dim: rgba(14, 165, 233, 0.15);
  --cyan: #22d3ee;
  --cyan-dim: rgba(34, 211, 238, 0.12);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.12);
  --error: #ef4444;
  --error-dim: rgba(239, 68, 68, 0.12);
  --color-scan: #06b6d4;
  --color-scan-dim: rgba(6, 182, 212, 0.15);
  --color-queued: #4b5563;
  --gold: #fbbf24;
  --silver: #a8a29e;
  --bronze: #d97706;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 40px; /* status bar */
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

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

.header-icon {
  flex-shrink: 0;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-accent {
  color: var(--accent);
}

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

.header-version {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.brand-selector {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.85rem;
  font-family: var(--font-primary);
  cursor: pointer;
}

.brand-selector:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- Tab Bar --- */
.tab-bar {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  border-bottom: 2px solid transparent;
  position: relative;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-icon {
  opacity: 0.7;
}

.tab.active .tab-icon {
  opacity: 1;
}

/* --- Content --- */
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --- Cards --- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Grid Layout --- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .tab-bar { padding: 0 12px; overflow-x: auto; }
  .tab { padding: 10px 14px; font-size: 0.8rem; white-space: nowrap; }
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 12px rgba(14, 165, 233, 0.3);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Form Inputs --- */
.input {
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  transition: border-color var(--transition);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.input::placeholder {
  color: var(--text-muted);
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input {
  flex: 1;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* --- Tables --- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

thead th.sortable {
  cursor: pointer;
}
thead th.sortable:hover {
  color: var(--text-primary);
}
thead th.sorted-asc::after {
  content: ' \25B2';
  font-size: 0.6rem;
}
thead th.sorted-desc::after {
  content: ' \25BC';
  font-size: 0.6rem;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody tr.highlight-self {
  background: var(--accent-dim);
}
tbody tr.highlight-self:hover {
  background: rgba(14, 165, 233, 0.22);
}

tbody tr.highlight-rival {
  background: var(--warning-dim);
}

td {
  padding: 10px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

td.mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.875rem;
}

/* --- Rank Badges --- */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
}

.rank-badge.rank-1 {
  background: rgba(251, 191, 36, 0.18);
  color: var(--gold);
  border: 1px solid rgba(251, 191, 36, 0.35);
}
.rank-badge.rank-2 {
  background: rgba(168, 162, 158, 0.15);
  color: var(--silver);
  border: 1px solid rgba(168, 162, 158, 0.3);
}
.rank-badge.rank-3 {
  background: rgba(217, 119, 6, 0.15);
  color: var(--bronze);
  border: 1px solid rgba(217, 119, 6, 0.3);
}
.rank-badge.rank-top10 {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.rank-badge.rank-low {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.rank-badge.rank-none {
  background: rgba(100, 116, 139, 0.12);
  color: var(--text-muted);
  border: 1px solid rgba(100, 116, 139, 0.2);
  font-size: 0.7rem;
}

/* --- Change Arrows --- */
.change-up {
  color: var(--success);
  font-weight: 600;
}
.change-down {
  color: var(--error);
  font-weight: 600;
}
.change-same {
  color: var(--text-muted);
}

/* --- Star Rating --- */
.star-rating {
  display: inline-flex;
  gap: 1px;
  color: var(--gold);
  font-size: 0.875rem;
  line-height: 1;
}

.star-rating .star-empty {
  color: var(--text-muted);
  opacity: 0.3;
}

.star-rating-large {
  font-size: 1.25rem;
  gap: 2px;
}

.rating-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--text-primary);
}

.rating-value-sm {
  font-size: 0.875rem;
}

/* --- Progress Bar --- */
.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 600ms ease;
}

.progress-fill.fill-accent { background: var(--accent); }
.progress-fill.fill-success { background: var(--success); }
.progress-fill.fill-warning { background: var(--warning); }
.progress-fill.fill-error { background: var(--error); }

/* Circular Progress */
.circular-progress {
  width: 80px;
  height: 80px;
  position: relative;
}

.circular-progress svg {
  transform: rotate(-90deg);
}

.circular-progress .progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
}

/* --- Stat Cards --- */
.stat-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-success {
  background: var(--success-dim);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-dim);
  color: var(--warning);
}

.badge-error {
  background: var(--error-dim);
  color: var(--error);
}

.badge-info {
  background: var(--accent-dim);
  color: var(--accent);
}

/* --- Review Cards --- */
.review-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color var(--transition);
}

.review-card:hover {
  border-color: var(--border-light);
}

.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.review-author {
  font-weight: 600;
  font-size: 0.875rem;
}

.review-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.review-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-top: 8px;
}

.review-text.truncated {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.review-text.truncated:hover {
  color: var(--text-primary);
}

.review-text.expanded {
  -webkit-line-clamp: unset;
}

.review-response {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(14, 165, 233, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.review-response-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* --- Checklist --- */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.checklist-item:last-child {
  border-bottom: none;
}

.check-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.check-icon.pass {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.check-icon.fail {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.checklist-label {
  flex: 1;
  color: var(--text-secondary);
}

.checklist-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Comparison Bars --- */
.comparison-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.comparison-label {
  width: 80px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

.comparison-track {
  flex: 1;
  display: flex;
  gap: 4px;
  align-items: center;
}

.comparison-fill-left {
  height: 24px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--accent);
  transition: width 600ms ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  min-width: 30px;
}

.comparison-fill-right {
  height: 24px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--warning);
  transition: width 600ms ease;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  min-width: 30px;
}

/* --- Nested SERP Rows (inline in keywords table) --- */
tr.kw-serp-row,
tr.kw-serp-row:nth-child(even) {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
  font-size: 0.8rem;
  animation: serpRowIn 200ms ease;
  cursor: default;
}

tr.kw-serp-row:hover {
  background: var(--bg-hover);
}

tr.kw-serp-row td {
  padding: 6px 12px;
  color: var(--text-secondary);
}

tr.kw-serp-row.kw-serp-self,
tr.kw-serp-row.kw-serp-self:nth-child(even) {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent-hover);
}

tr.kw-serp-row.kw-serp-self:hover {
  background: rgba(14, 165, 233, 0.22);
}

tr.kw-serp-row.kw-serp-self td {
  color: var(--text-primary);
}

tr.kw-serp-row.kw-serp-info-row td {
  padding: 4px 12px;
  border-bottom: 2px solid var(--border-light);
}

@keyframes serpRowIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- SERP Drill-Down Panel (legacy) --- */
.serp-panel {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 8px 0 16px 0;
  animation: slideDown 200ms ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.serp-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--accent);
}

/* --- Canvas Chart Container --- */
.chart-container {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}

.chart-container canvas {
  width: 100%;
  height: 200px;
}

/* --- Section Headers --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.section-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

/* --- Skeleton Loading --- */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 0px,
    var(--bg-hover) 40px,
    var(--bg-tertiary) 80px
  );
  background-size: 200px 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--radius-sm);
}

.skeleton-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.skeleton-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.skeleton-text {
  height: 14px;
  flex: 1;
}

.skeleton-text-short {
  height: 14px;
  width: 80px;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toastIn 300ms ease;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.toast.removing {
  animation: toastOut 200ms ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 1px;
}

.toast-success .toast-icon {
  background: var(--success-dim);
  color: var(--success);
}
.toast-success { border-left: 3px solid var(--success); }

.toast-error .toast-icon {
  background: var(--error-dim);
  color: var(--error);
}
.toast-error { border-left: 3px solid var(--error); }

.toast-info .toast-icon {
  background: var(--accent-dim);
  color: var(--accent);
}
.toast-info { border-left: 3px solid var(--accent); }

.toast-message {
  flex: 1;
  color: var(--text-secondary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  margin-left: 4px;
}
.toast-close:hover { color: var(--text-primary); }

/* --- Loading Overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(10, 14, 23, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 200ms ease;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
  letter-spacing: 0.02em;
}

/* --- Status Bar --- */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-item strong {
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

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

.status-divider {
  color: var(--border);
  margin: 0 4px;
}

/* --- Head-to-Head Cards --- */
.h2h-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
}

.h2h-card.self-card {
  border-color: rgba(14, 165, 233, 0.3);
}

.h2h-card.rival-card {
  border-color: rgba(245, 158, 11, 0.3);
}

.h2h-name {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.h2h-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.h2h-rating {
  margin: 12px 0;
}

/* --- Expandable Rows --- */
.expandable-row {
  cursor: pointer;
}

.expand-icon {
  display: inline-block;
  transition: transform 200ms ease;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-right: 4px;
}

.expand-icon.expanded {
  transform: rotate(90deg);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.9rem;
  margin-bottom: 16px;
}

/* --- Clickable Row --- */
.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  color: var(--accent);
}

/* --- Misc Utility --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.font-mono { font-family: var(--font-mono); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }

/* --- Stats Row --- */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.stats-row .stat-card {
  flex: 1;
}

/* --- Panel --- */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.panel-body {
  padding: 16px;
  max-height: 600px;
  overflow-y: auto;
}

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

/* ========== Keyword Selection Checkboxes ========== */
.kw-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-light);
  border-radius: 3px;
  background: var(--bg-tertiary);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  transition: border-color var(--transition), background var(--transition);
  accent-color: #0ea5e9;
}

.kw-checkbox:hover {
  border-color: var(--accent);
}

.kw-checkbox:checked {
  background: #0ea5e9;
  border-color: #0ea5e9;
}

.kw-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.kw-checkbox:indeterminate {
  background: #0ea5e9;
  border-color: #0ea5e9;
}

.kw-checkbox:indeterminate::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 6px;
  width: 8px;
  height: 0;
  border: solid #fff;
  border-width: 0 0 2px 0;
}

.kw-select-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.kw-select-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.kw-select-toggle:hover {
  color: var(--accent);
}

/* ========== Per-Keyword Loading & WebSocket Updates ========== */
.kw-spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid #1e293b; border-top-color: #0ea5e9;
  border-radius: 50%; animation: kw-spin 0.6s linear infinite;
}
@keyframes kw-spin { to { transform: rotate(360deg); } }

tr.kw-loading { opacity: 0.7; }
tr.kw-updated {
  animation: kw-flash 0.6s ease-out;
}
tr.kw-error .kw-rank-cell {
  color: var(--error);
}
@keyframes kw-flash {
  0% { background-color: rgba(14, 165, 233, 0.2); }
  100% { background-color: transparent; }
}

.kw-add-form {
  display: flex; gap: 8px; padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.kw-add-form .input {
  flex: 1; padding: 8px 12px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-primary); font-size: 0.875rem;
}
.kw-add-form .input:focus {
  outline: none; border-color: var(--accent);
}
.kw-actions { display: flex; gap: 4px; }
.btn-danger {
  background: transparent; color: var(--error); border: 1px solid var(--error);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

/* ========== Grid Map ========== */
.grid-map-container { display: flex; height: calc(100vh - 160px); position: relative; }
.grid-map-main { flex: 1; position: relative; }
.grid-map-sidebar { width: 380px; position: absolute; right: 0; top: 0; height: 100%; z-index: 10;
  background: rgba(17,24,39,0.92); border-left: 1px solid #1e293b;
  overflow-y: auto; transition: transform 0.3s; backdrop-filter: blur(8px); }
.grid-map-sidebar.collapsed { transform: translateX(100%); overflow: hidden; }

#grid-map { width: 100%; height: 100%; }

.grid-map-controls { position: absolute; top: 16px; left: 16px; z-index: 10;
  background: rgba(17,24,39,0.9); border-radius: 8px; padding: 16px;
  backdrop-filter: blur(8px); border: 1px solid #1e293b; max-width: 320px; }

.sidebar-header { padding: 16px; border-bottom: 1px solid #1e293b; display: flex;
  align-items: center; justify-content: space-between; }
.sidebar-pin-info { padding: 12px 16px; background: #0a0e17; }
.sidebar-ranking-list { list-style: none; padding: 0; margin: 0; }
.sidebar-ranking-item { padding: 12px 16px; border-bottom: 1px solid #1e293b;
  display: flex; align-items: center; gap: 12px; }
.sidebar-ranking-item.is-self { background: rgba(14,165,233,0.1);
  border-left: 3px solid #0ea5e9; }
.sidebar-rank-num { min-width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; background: #1e293b; color: #94a3b8; }

.scan-progress { background: #1e293b; border-radius: 4px; margin-top: 8px; }
.scan-progress-bar { height: 4px; background: #0ea5e9; border-radius: 4px; transition: width 0.3s; }
.scan-progress-text { font-size: 11px; color: #94a3b8; margin-top: 4px; }

.grid-stats-bar { display: flex; gap: 16px; padding: 12px 16px;
  background: #111827; border-top: 1px solid #1e293b; position: absolute;
  bottom: 0; left: 0; right: 0; z-index: 10; }
.grid-stat { text-align: center; flex: 1; }
.grid-stat-value { font-size: 20px; font-weight: 700; color: #f1f5f9; }
.grid-stat-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; }

.device-toggle { display: flex; background: #1e293b; border-radius: 6px; overflow: hidden; }
.device-toggle button { padding: 6px 14px; border: none; background: transparent;
  color: #94a3b8; cursor: pointer; font-size: 12px; font-family: inherit; }
.device-toggle button.active { background: #0ea5e9; color: #fff; }

.grid-controls-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.grid-controls-label { font-size: 11px; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 4px; }
.grid-controls-section { margin-bottom: 12px; }

/* Grid Map Controls - form and layout */
.grid-control-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.grid-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em;
  min-width: 70px; flex-shrink: 0; }
.grid-control-divider { height: 1px; background: #1e293b; margin: 12px 0; }
.grid-config-form { margin-top: 12px; }
.scan-progress-text { font-size: 11px; color: #94a3b8; margin-top: 4px; }

/* Grid Map Sidebar (JS class names) */
.grid-sidebar-header { padding: 16px; border-bottom: 1px solid #1e293b; display: flex;
  align-items: center; justify-content: space-between; }
.grid-sidebar-title { font-size: 14px; font-weight: 600; color: #f1f5f9; }
.grid-sidebar-info { padding: 12px 16px; background: #0a0e17; }
.grid-sidebar-rank { margin-top: 8px; }
.grid-sidebar-rankings { padding: 0; }
.grid-ranking-item { padding: 12px 16px; border-bottom: 1px solid #1e293b;
  display: flex; align-items: flex-start; gap: 12px; }
.grid-ranking-item.is-self { background: rgba(14,165,233,0.1); border-left: 3px solid #0ea5e9; }
.grid-ranking-rank { flex-shrink: 0; }
.grid-ranking-details { flex: 1; min-width: 0; }
.grid-ranking-name { font-weight: 600; font-size: 13px; color: #f1f5f9; margin-bottom: 2px; }
.grid-ranking-rating { font-size: 12px; margin-bottom: 2px; }
.grid-ranking-address { font-size: 11px; }
.grid-ranking-category { font-size: 11px; font-style: italic; }

/* --- Management Pages --- */

.manage-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.breadcrumb-link {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  color: var(--text-muted);
}

.breadcrumb-current {
  color: var(--text-secondary);
}

.manage-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.manage-card-title {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 12px;
  font-weight: 600;
}

.manage-detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 12px;
  font-size: 0.85rem;
}

.manage-detail-list dt {
  color: var(--text-muted);
  font-weight: 500;
}

.manage-detail-list dd {
  color: var(--text-primary);
}

.manage-nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.manage-nav-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-primary);
  font-family: inherit;
  font-size: inherit;
}

.manage-nav-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.manage-nav-icon {
  font-size: 1.5rem;
}

.manage-nav-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.manage-nav-count {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.manage-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.manage-section-header h3 {
  font-size: 1rem;
  color: var(--text-primary);
}

.manage-sub-header {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 16px 0 8px;
  font-weight: 600;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.manage-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

.manage-list-item:hover {
  background: var(--bg-hover);
}

.manage-list-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
}

.manage-list-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.manage-list-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

.manage-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.manage-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  margin-right: 4px;
}

.manage-badge-primary {
  background: var(--success-dim);
  color: var(--success);
}

.manage-badge-location {
  background: var(--cyan-dim);
  color: var(--cyan);
}

.manage-badge-scope {
  background: var(--warning-dim);
  color: var(--warning);
}

.manage-keyword-item {
  flex-wrap: wrap;
}

.manage-keyword-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Grid Map - Boundary Search (Geospatial Mode) */
.boundary-search-wrap { position: relative; flex: 1; min-width: 0; }
.boundary-search-wrap .input { width: 100%; }
.boundary-search-results {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: #1e293b; border: 1px solid #334155; border-radius: 0 0 6px 6px;
  max-height: 200px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.boundary-result-item {
  padding: 8px 12px; font-size: 13px; color: #e2e8f0; cursor: pointer;
  border-bottom: 1px solid #334155;
}
.boundary-result-item:last-child { border-bottom: none; }
.boundary-result-item:hover { background: #334155; }
.boundary-result-item.text-muted { cursor: default; color: #64748b; }

.boundary-selected-name {
  font-size: 13px; font-weight: 600; color: #0ea5e9;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}

/* Grid Map - Draw Mode */
.draw-instructions {
  font-size: 12px; color: #94a3b8; line-height: 1.5; margin-bottom: 10px;
  padding: 8px 10px; background: rgba(168,85,247,0.08); border-radius: 6px;
  border: 1px solid rgba(168,85,247,0.2);
}

/* --- Cost Panel --- */
.cost-panel {
  position: fixed;
  bottom: 32px;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.2s ease;
}
.cost-panel.hidden {
  transform: translateY(100%);
  pointer-events: none;
}
.cost-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
}
.cost-panel-header h3 { margin: 0; font-size: 14px; }
.cost-panel-controls { display: flex; gap: 8px; align-items: center; }
.cost-date-select, .cost-brand-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
}
.cost-panel-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.cost-panel-close:hover { color: var(--text-primary); }
.cost-panel-body { padding: 16px; }
.cost-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.cost-card {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.cost-card-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cost-card-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 4px;
}
.cost-chart-container {
  margin-bottom: 16px;
  padding: 8px;
}
.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.cost-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.cost-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--bg-tertiary);
}
.status-cost-trigger { cursor: pointer; }
.status-cost-trigger:hover { opacity: 0.8; }
