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

:root {
  --blue:       #2563EB;
  --blue-light: #EFF6FF;
  --blue-dark:  #1D4ED8;
  --green:      #16A34A;
  --green-light:#DCFCE7;
  --amber:      #D97706;
  --amber-light:#FEF3C7;
  --red:        #DC2626;
  --bg:         #F1F5F9;
  --surface:    #FFFFFF;
  --border:     #E2E8F0;
  --text:       #0F172A;
  --muted:      #64748B;
  --radius:     10px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.1);
}

/* ── Dark mode overrides ───────────────────────────────────── */
[data-theme="dark"] {
  --blue:        #60A5FA;
  --blue-light:  #1E3A5F;
  --blue-dark:   #3B82F6;
  --green:       #4ADE80;
  --green-light: #14532D;
  --amber:       #FCD34D;
  --amber-light: #451A03;
  --red:         #F87171;
  --bg:          #0F172A;
  --surface:     #1E293B;
  --border:      #334155;
  --text:        #F1F5F9;
  --muted:       #94A3B8;
  --shadow:      0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md:   0 4px 12px rgba(0,0,0,.4);
}

[data-theme="dark"] .sync-bar        { background: #020617; }
[data-theme="dark"] .rank-delta-down { background: #450A0A; color: #F87171; }
[data-theme="dark"] .rank-1          { background: #422006; color: #FDE047; border-color: #854D0E; }
[data-theme="dark"] input, [data-theme="dark"] select { background: var(--surface); color: var(--text); }

/* ── Theme toggle button ───────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg); }

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

/* ── Header ────────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

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

.header-logo-img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: block;
  flex-shrink: 0;
}

.header-logo {
  width: 32px;
  height: 32px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.5px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.header-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
  transition: background .15s, color .15s;
}

.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--blue-light); color: var(--blue); }
.nav-link-manage { text-decoration: none; color: var(--blue); border: 1px solid var(--blue); }
.nav-link-manage:hover { background: var(--blue); color: white; }

/* ── Sync status bar ───────────────────────────────────────── */
.sync-bar {
  background: #1E293B;
  color: #94A3B8;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 24px;
  font-size: 12px;
}

.sync-bar-text { flex: 1; }

.sync-bar-btn {
  background: none;
  border: 1px solid #334155;
  color: #94A3B8;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sync-bar-btn:hover { background: #334155; color: white; }

.sync-bar-link {
  color: #60A5FA;
  font-size: 12px;
  text-decoration: none;
}
.sync-bar-link:hover { text-decoration: underline; }

/* ── Main layout ───────────────────────────────────────────── */
.main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.page-header p {
  color: var(--muted);
  margin-top: 2px;
  font-size: 13px;
}

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

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

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.kpi-value.green { color: var(--green); }
.kpi-value.blue  { color: var(--blue); }
.kpi-value.amber { color: var(--amber); }
.kpi-value.red   { color: #DC2626; }

.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.kpi-bar-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}

.kpi-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width .5s ease;
}

/* ── Filters ───────────────────────────────────────────────── */
.filters-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.search-input:focus { border-color: var(--blue); background: white; }

.filter-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}

.filter-select:focus { border-color: var(--blue); background: white; }

.result-count {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

thead th[data-sort] {
  cursor: pointer;
}

thead th[data-sort]:hover { color: var(--text); }
thead th.sort-active { color: var(--blue); }

.sort-icon {
  margin-left: 4px;
  font-size: 10px;
  opacity: .7;
}

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

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--blue-light); }

tbody td {
  padding: 12px 14px;
  vertical-align: middle;
}

.page-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.page-service {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

/* ── Rank badge ────────────────────────────────────────────── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -.2px;
}

.rank-delta {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}
.rank-delta-up   { background: var(--green-light); color: var(--green); }
.rank-delta-down { background: #FEE2E2; color: var(--red); }

.rank-1    { background: #FEF9C3; color: #854D0E; border: 1px solid #FDE047; }
.rank-top3 { background: var(--green-light); color: #14532D; border: 1px solid #86EFAC; }
.rank-other{ background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* ── Sparkline ─────────────────────────────────────────────── */
.sparkline { display: block; }
.spark-good polyline { stroke: var(--green); }
.spark-bad  polyline { stroke: var(--amber); }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
}

.badge-rented    { background: var(--green-light); color: var(--green); }
.badge-available { background: var(--amber-light); color: var(--amber); }
.badge-lg        { padding: 6px 14px; font-size: 13px; }

.tenant-name {
  font-size: 13px;
  color: var(--text);
}

.per-mo { font-size: 11px; color: var(--muted); margin-left: 1px; }

.leads-num { font-weight: 600; }
.leads-total { font-size: 11px; color: var(--muted); }

.muted { color: var(--muted); }

.btn-detail {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--blue);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.btn-detail:hover {
  background: var(--blue-light);
  border-color: var(--blue);
}

.btn-intake {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--green);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn-intake:hover {
  background: var(--green-light);
  border-color: var(--green);
}
.btn-intake-modal {
  margin-top: 12px;
  padding: 7px 16px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--blue);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-intake-modal:hover {
  background: var(--blue-light);
  border-color: var(--blue);
}

.empty-row {
  text-align: center;
  padding: 40px !important;
  color: var(--muted);
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.open { display: flex; }

/* modal-panel is an alias for modal, allowing max-width override via inline style */
.modal-panel {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: modal-in .18s ease;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modal-in .18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-section {
  margin-bottom: 24px;
}

.modal-section:last-child { margin-bottom: 0; }

.modal-section h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 12px;
}

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

.detail-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.detail-item span {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.detail-item span.highlight-green { color: var(--green); font-weight: 700; }

.url-text { font-family: monospace; font-size: 13px; }

.rank-inline { vertical-align: middle; }

.available-notice {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--amber-light);
  border: 1px solid #FCD34D;
  border-radius: 10px;
  padding: 14px 16px;
}

.available-notice p { font-size: 13px; color: #78350F; }

/* ── Rank history chart ────────────────────────────────────── */
.rank-history-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100px;
  padding-bottom: 4px;
}

.rh-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}

.rh-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.rh-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 8px;
  transition: height .3s;
}

.rh-bar-best { background: #FDE047; }
.rh-bar-good { background: var(--green); }
.rh-bar-ok   { background: var(--blue); opacity: .5; }

.rh-month {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}
