/* GeoRev Engine — Square-inspired UI */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafafa;
  --border: #e3e5e8;
  --border-light: #eceef0;
  --text: #1a1a1a;
  --text-2: #5c5c5c;
  --muted: #8b8b8b;
  --accent: #006aff;
  --accent-hover: #0052cc;
  --accent-bg: #e8f1ff;
  --danger: #cd3c3c;
  --ok: #00875a;
  --warn: #b86e00;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.logo-img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}
.login-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
}
.login-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.login-brand p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 16px 0 6px;
}
.login-card input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}
.login-card button {
  width: 100%;
  margin-top: 24px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.login-card button:hover { background: #333; }
.login-card button:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 12px; }

/* ---------- layout ---------- */
.layout { display: flex; height: 100vh; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .logo-img { margin: 0; }
.brand-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.nav-links {
  flex: 1;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-label {
  display: block;
  padding: 12px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-links a svg { flex-shrink: 0; opacity: 0.7; }
.nav-links a:hover {
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
}
.nav-links a.active {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}
.nav-links a.active svg { opacity: 1; }
.sidebar-foot {
  padding: 14px 12px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.whoami {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  min-width: 0;
  background: var(--bg);
}

/* ---------- typography & buttons ---------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.page-head .sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 400;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background 0.15s;
}
.btn:hover { background: #333; }
.btn.ghost {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--danger);
}
.btn.danger:hover { background: #fef2f2; border-color: #f5c6c6; }
.btn.small { padding: 7px 12px; font-size: 13px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left;
  padding: 11px 16px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--panel-2); }
td .title-link { font-weight: 600; color: var(--text); }
tr.clickable:hover td .title-link { color: var(--accent); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 6px; }
.cell-muted { color: var(--muted); font-size: 13px; }
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 4px;
  padding: 3px 8px;
}
.pill.draft { background: #f0f0f0; color: var(--muted); }
.pill.staged { background: var(--accent-bg); color: var(--accent); }
.pill.scheduled { background: #fff8e6; color: var(--warn); }
.pill.published { background: #e6f4ed; color: var(--ok); }
.pill.revoked { background: #fdeaea; color: var(--danger); }
.pill.active { background: #e6f4ed; color: var(--ok); }

.token {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  word-break: break-all;
}

/* ---------- detail / tabs ---------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.crumbs a { font-weight: 600; color: var(--text-2); }
.crumbs a:hover { color: var(--accent); }
.detail-meta { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.tabs {
  display: flex;
  gap: 0;
  margin: 24px 0 16px;
  border-bottom: 1px solid var(--border);
}
.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 16px;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 600;
}

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px 24px; }
.modal-body .field { margin-bottom: 16px; }
.modal-body label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.modal-body input,
.modal-body select,
.modal-body textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-body textarea { resize: vertical; min-height: 80px; }
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}
.modal-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* ---------- data table ---------- */
.dt-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.dt-search {
  flex: 1;
  min-width: 180px;
  max-width: 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}
.dt-search:focus { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.dt-perpage {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
}
.dt-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  flex-wrap: wrap;
  gap: 8px;
}
.dt-info { font-size: 13px; color: var(--muted); }
.dt-paging { display: flex; align-items: center; gap: 6px; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); background: #f0f0f0; }
.sort-ind { font-size: 10px; opacity: 0.5; margin-left: 4px; }

/* ---------- section head ---------- */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 28px 0 14px;
  gap: 12px;
}
.section-head h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------- KPI cards (overview) ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.kpi-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 8px;
  color: var(--text);
}
.kpi-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.chart-card { padding: 20px 24px; margin-bottom: 20px; }
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.chart-head-left { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chart-head h2 { font-size: 15px; font-weight: 700; }
.chart-sub { font-size: 12px; color: var(--muted); }
.chart-days { display: inline-flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.chart-day-btn, .chart-day-link {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  line-height: 1;
}
.chart-day-btn:hover, .chart-day-link:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.chart-day-btn.active, .chart-day-link.active { background: var(--text); color: #fff; }
.chart-wrap { position: relative; }
.chart-tooltip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  background: var(--text);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  min-width: 140px;
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip strong { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.chart-tooltip span { display: block; color: rgba(255, 255, 255, 0.88); }
.chart-tooltip .tt-visits::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 2px; background: #fff; margin-right: 6px; vertical-align: middle; }
.chart-tooltip .tt-clicks::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.chart { cursor: crosshair; }
.ch-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.ch-dot { pointer-events: none; transition: r 0.1s; }
.ch-dot.active { r: 3.5; }
.chart-note { font-size: 12px; color: var(--warn); margin-top: 8px; }
.chart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--border-light); stroke-width: 1; }
.ch-tick { font-size: 10px; fill: var(--muted); }
.ch-line-a {
  fill: none;
  stroke: var(--text);
  stroke-width: 1;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.ch-line-b {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.ch-dot-a { fill: var(--text); }
.ch-dot-b { fill: var(--accent); }
.ch-legend { display: flex; gap: 20px; padding: 12px 0 0; font-size: 13px; color: var(--text-2); }
.ch-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.ch-legend .dot-a { background: var(--text); }
.ch-legend .dot-b { background: var(--accent); }

.hbars { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.hbar {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr auto;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}
a.hbar:hover .hbar-label { color: var(--accent); }
.hbar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hbar-track { height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 4px; min-width: 2px; background: var(--text); }
.hbar-value { font-size: 13px; font-weight: 600; white-space: nowrap; }
.hbar-value em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- microsite editor ---------- */
.microsite-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  min-height: 560px;
  margin-top: 20px;
}
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-tabs { display: flex; border-bottom: 1px solid var(--border); }
.editor-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  padding: 12px 18px;
  margin-bottom: -1px;
}
.editor-tab:hover { color: var(--text); }
.editor-tab.active { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
.editor-body { padding: 20px; flex: 1; overflow-y: auto; }
.editor-actions {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
}
.save-status { font-size: 13px; color: var(--ok); font-weight: 600; }
.editor-field { margin-bottom: 16px; }
.editor-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field-hint { font-weight: 500; color: var(--muted); }
.editor-field input,
.editor-field select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.editor-field input:focus,
.editor-field select:focus { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.editor-field input[type="color"] { height: 40px; width: 56px; padding: 4px; cursor: pointer; }
.editor-colors { display: flex; gap: 16px; flex-wrap: wrap; }
.editor-colors > div { display: flex; flex-direction: column; gap: 6px; }

.qa-list { display: flex; flex-direction: column; gap: 8px; }
.qa-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--panel);
}
.qa-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel-2);
}
.qa-item-header:hover { background: #f0f0f0; }
.qa-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
  width: 18px;
}
.qa-item-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qa-item-actions { display: flex; gap: 4px; }
.qa-item-body { padding: 16px; border-top: 1px solid var(--border); }

.wysiwyg-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--panel-2);
}
.wysiwyg-toolbar button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}
.wysiwyg-toolbar button:hover { background: var(--border-light); }
.wysiwyg-editor {
  min-height: 100px;
  padding: 12px;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--panel);
}
.wysiwyg-editor:focus { border-color: var(--text); }

.preview-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.preview-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.preview-frame { flex: 1; overflow-y: auto; max-height: 700px; background: #fafafa; }

.save-indicator {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ok);
  box-shadow: var(--shadow-md);
}
.save-indicator.hidden { opacity: 0; pointer-events: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .microsite-editor { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 12px 14px; }
  .nav-links { flex-direction: row; padding: 0 8px; overflow-x: auto; }
  .nav-label { display: none; }
  .sidebar-foot { border-top: none; margin-left: auto; }
  .main { padding: 20px 16px; }
}
