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

:root {
  --navy:      #0f172a;
  --navy2:     #1e293b;
  --blue:      #3b82f6;
  --blue2:     #2563eb;
  --green:     #10b981;
  --red:       #f43f5e;
  --amber:     #f59e0b;
  --purple:    #8b5cf6;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --bg:        #f8fafc;
  --white:     #ffffff;
  --panel-w:   420px;
  --sidebar-w: 300px;
  --bar-h:     52px;
  --filter-h:  84px;
  --content-top: calc(var(--bar-h) + var(--filter-h));
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.10), 0 1px 4px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; color: var(--text); background: var(--navy); }

/* ── Top bar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--bar-h);
  background: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: rgba(59,130,246,.18);
  display: flex; align-items: center; justify-content: center;
  color: var(--blue);
}
.topbar-title { color: #f1f5f9; font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.topbar-count {
  font-size: 12px; color: rgba(255,255,255,.35);
  background: rgba(255,255,255,.06);
  padding: 3px 9px; border-radius: 20px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.powered-by {
  font-size: 11px; font-weight: 500;
  color: rgba(255,255,255,.35);
  letter-spacing: .01em;
  padding-left: 4px;
}
.powered-brand {
  font-weight: 700;
  background: linear-gradient(90deg, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
}

/* Layer toggle */
.layer-toggle {
  display: flex; gap: 2px; background: rgba(255,255,255,.07);
  border-radius: 7px; padding: 3px;
}
.toggle-btn {
  padding: 5px 14px; border: none; border-radius: 5px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  color: rgba(255,255,255,.5); background: transparent;
  transition: all .15s;
}
.toggle-btn.active { background: var(--blue); color: #fff; }
.toggle-btn:hover:not(.active) { color: rgba(255,255,255,.85); }

.icon-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 13px; border: 1px solid rgba(255,255,255,.12);
  border-radius: 7px; background: transparent;
  color: rgba(255,255,255,.6); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  position: fixed;
  top: var(--bar-h); left: 0; right: 0;
  height: var(--filter-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center;
  padding: 5px 14px;
  z-index: 950;
  gap: 5px;
}
.filter-row { display: flex; align-items: center; gap: 8px; }
.filter-select {
  height: 30px; padding: 0 28px 0 10px;
  border: 1.5px solid var(--border); border-radius: 7px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 8px center;
  -webkit-appearance: none; appearance: none;
  font-family: inherit; font-size: 12px; font-weight: 500;
  color: var(--text); cursor: pointer; outline: none;
  transition: border-color .15s; white-space: nowrap;
}
.filter-select:focus { border-color: var(--blue); }
.filter-select.active { border-color: var(--blue); background-color: #eff6ff; color: var(--blue2); }

.filter-search-wrap {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border: 1.5px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--muted);
  transition: border-color .15s;
  min-width: 148px;
}
.filter-search-wrap:focus-within { border-color: var(--blue); color: var(--blue); }
.filter-search-wrap.active { border-color: var(--blue); background: #eff6ff; }
.filter-search-input {
  border: none; background: transparent;
  font-family: inherit; font-size: 12px; font-weight: 500;
  color: var(--text); outline: none; width: 100%;
}
.filter-search-input::placeholder { color: var(--muted); }


.filter-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.filter-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.filter-count strong { color: var(--text); }
.filter-clear-left {
  padding: 5px 12px; border-radius: 7px;
  border: 1.5px solid #fca5a5;
  background: #fff1f2; color: var(--red);
  font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
  flex-shrink: 0;
}
.filter-clear-left:hover { background: #fee2e2; border-color: var(--red); }

/* ── Left sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--content-top); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 900;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w) + 36px));
}
.sidebar-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 13px; font-weight: 700; color: var(--text);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 2px;
}
.sidebar-facility { font-size: 12px; color: var(--muted); max-width: 220px; line-height: 1.3; }
.sidebar-toggle {
  width: 26px; height: 26px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* Empty state */
.sidebar-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px; gap: 14px; text-align: center;
  color: var(--muted);
}
.sidebar-empty p { font-size: 13px; line-height: 1.5; }

/* Active content */
.sidebar-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Composer */
.composer {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.type-tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.type-tab {
  padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  font-size: 11px; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.type-tab:hover { background: var(--bg); color: var(--text); }
.type-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.type-tab[data-type="call"].active  { background: var(--green);  border-color: var(--green); }
.type-tab[data-type="sms"].active   { background: var(--blue);   border-color: var(--blue); }
.type-tab[data-type="email"].active { background: var(--purple); border-color: var(--purple); }

.composer-textarea {
  width: 100%; padding: 9px 11px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 13px; color: var(--text);
  resize: vertical; outline: none; transition: border-color .15s;
  min-height: 72px;
}
.composer-textarea:focus { border-color: var(--blue); }
.composer-footer {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.composer-date {
  flex: 1; padding: 8px 10px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 12px; color: var(--text);
  outline: none; transition: border-color .15s;
}
.composer-date:focus { border-color: var(--blue); }
.composer-save {
  padding: 9px 16px; background: var(--blue); color: #fff;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s; white-space: nowrap;
}
.composer-save:hover { background: var(--blue2); }
.composer-save:disabled { background: #94a3b8; cursor: not-allowed; }

/* Feed */
.activity-feed {
  flex: 1; overflow-y: auto;
  padding: 10px 12px 24px;
}
.feed-loading { padding: 20px 0; text-align: center; color: var(--muted); font-size: 13px; }

.feed-empty   { padding: 20px 0; text-align: center; color: var(--muted); font-size: 13px; }

.activity-item {
  display: flex; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 5px; flex-shrink: 0;
}
.dot-note  { background: var(--amber); }
.dot-call  { background: var(--green); }
.dot-sms   { background: var(--blue); }
.dot-email { background: var(--purple); }

.activity-body { flex: 1; min-width: 0; }
.activity-header {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.activity-type-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em;
}
.label-note  { color: var(--amber); }
.label-call  { color: var(--green); }
.label-sms   { color: var(--blue); }
.label-email { color: var(--purple); }

.activity-time   { font-size: 10px; color: var(--muted); margin-left: auto; }
.activity-author { font-size: 10px; color: var(--muted); margin-left: 4px; }
.activity-text   { font-size: 12px; color: var(--text); line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.activity-delete {
  display: none; padding: 2px 6px;
  border: none; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
  border-radius: 4px; line-height: 1;
}
.activity-item:hover .activity-delete { display: inline-flex; }
.activity-delete:hover { background: #fee2e2; color: var(--red); }

/* ── Map ───────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--content-top); left: var(--sidebar-w); right: 0; bottom: 0;
  z-index: 1;
  transition: left .28s cubic-bezier(.4,0,.2,1);
}
#map.sidebar-collapsed { left: 36px; }

/* ── Cluster styles ────────────────────────────────────────────────────────── */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(59,130,246,.18) !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--blue) !important;
  color: #fff !important;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
}

/* ── Facility panel ────────────────────────────────────────────────────────── */
.panel {
  position: fixed;
  top: var(--content-top); right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--white);
  box-shadow: -4px 0 32px rgba(0,0,0,.14);
  z-index: 900;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.panel.open { transform: translateX(0); }

.panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--white);
}
.panel-title {
  font-size: 16px; font-weight: 700; color: var(--text);
  line-height: 1.3; margin-bottom: 4px;
  max-width: 330px;
}
.panel-subtitle { font-size: 12px; color: var(--muted); line-height: 1.4; max-width: 330px; }

.close-btn {
  flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.close-btn:hover { background: var(--bg); color: var(--text); }

.panel-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px 32px;
}

/* Info grid */
.info-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 16px;
}
.info-cell {
  background: var(--bg); border-radius: 8px;
  padding: 10px 12px;
}
.info-cell-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 3px; }
.info-cell-value { font-size: 13px; font-weight: 500; color: var(--text); }

/* Analyze button */
.analyze-btn {
  width: 100%; padding: 11px 16px;
  background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s, transform .1s;
}
.analyze-btn:hover { background: var(--blue2); }
.analyze-btn:active { transform: scale(.98); }
.analyze-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* Status */
.status-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; color: var(--muted); font-size: 13px;
}
.spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Section labels */
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
  margin-top: 20px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.section-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.confidence-badge {
  font-weight: 500; text-transform: none; letter-spacing: 0;
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
}
.confidence-high { background: #d1fae5; color: #065f46; }
.confidence-medium { background: #fef3c7; color: #92400e; }
.confidence-low { background: #fee2e2; color: #991b1b; }

/* Price table */
.price-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.price-table th {
  text-align: left; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.price-table td { padding: 8px 8px; border-bottom: 1px solid var(--border); }
.price-table tr:last-child td { border-bottom: none; }
.price-table tr:hover td { background: var(--bg); }
.cc-badge {
  display: inline-flex; align-items: center;
  font-size: 10px; color: var(--blue); font-weight: 500;
  background: #eff6ff; padding: 2px 6px; border-radius: 4px;
}

/* Competitor list */
.competitor-item {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin-bottom: 8px;
}
.competitor-name { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.competitor-meta { font-size: 11px; color: var(--muted); display: flex; gap: 10px; margin-bottom: 8px; }
.competitor-prices { display: flex; flex-wrap: wrap; gap: 5px; }
.competitor-price-tag {
  font-size: 11px; padding: 3px 8px; border-radius: 5px;
  background: var(--bg); color: var(--text);
  font-weight: 500;
}

/* Comparison table */
.comparison-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.comparison-table th {
  text-align: left; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.comparison-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.comparison-table tr:last-child td { border-bottom: none; }

.upside-pill {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 20px;
}
.upside-positive { background: #d1fae5; color: #065f46; }
.upside-negative { background: #fee2e2; color: #991b1b; }
.upside-neutral  { background: #f1f5f9; color: var(--muted); }

.upside-bar-wrap { margin-top: 3px; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.upside-bar { height: 100%; border-radius: 2px; transition: width .4s; }
.bar-green { background: var(--green); }
.bar-red   { background: var(--red); }

/* Fetch timestamp */
.fetch-timestamp {
  font-size: 11px; color: var(--muted);
  background: var(--bg); border-radius: 6px;
  padding: 6px 10px; margin-top: 12px;
  display: flex; align-items: center; gap: 5px;
}
.fetch-timestamp::before {
  content: '';
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--green); flex-shrink: 0;
}

/* Refresh button */
.refresh-btn {
  margin-top: 20px; width: 100%;
  padding: 9px; border: 1px solid var(--border);
  border-radius: var(--radius); background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.refresh-btn:hover { background: var(--bg); color: var(--text); }

/* Error box */
.error-box {
  background: #fff1f2; border: 1px solid #fecdd3;
  border-radius: 8px; padding: 12px 14px;
  color: #be123c; font-size: 13px; line-height: 1.5;
  margin-top: 12px;
}

/* ── Logs modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--white); border-radius: 14px;
  width: 780px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
}
.modal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; flex: 1; }
.modal-stats { display: flex; gap: 12px; }
.modal-stat {
  font-size: 11px; color: var(--muted); background: var(--bg);
  padding: 4px 10px; border-radius: 6px;
}
.modal-stat strong { color: var(--text); font-weight: 600; }

.modal-body { flex: 1; overflow-y: auto; padding: 0; }

.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table th {
  text-align: left; padding: 10px 14px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  position: sticky; top: 0;
}
.log-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: var(--bg); }
.log-type { padding: 2px 7px; border-radius: 4px; font-weight: 600; font-size: 10px; }
.type-prices { background: #eff6ff; color: #1d4ed8; }
.type-nearby { background: #f0fdf4; color: #166534; }
.token-count { font-weight: 600; color: var(--text); }
.log-preview { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

/* ── Map panel push ─────────────────────────────────────────────────────────── */
#map.panel-open { right: var(--panel-w); }

/* ── User badge ─────────────────────────────────────────────────────────────── */
.user-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 22px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--blue);
  color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; gap: 1px; }
.user-email { font-size: 11px; color: rgba(255,255,255,.75); font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role  { font-size: 10px; color: rgba(255,255,255,.4); }
.user-role.is-admin { color: #fbbf24; }

.quota-badge {
  font-size: 10px; color: rgba(255,255,255,.45);
  padding-left: 8px; border-left: 1px solid rgba(255,255,255,.12);
  white-space: nowrap;
}

/* ── Users modal ────────────────────────────────────────────────────────────── */
.modal-hint { font-size: 12px; color: var(--muted); flex: 1; margin-left: 4px; }

.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th {
  text-align: left; padding: 10px 14px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  position: sticky; top: 0;
}
.users-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg); }

.role-badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.role-admin { background: #eff6ff; color: #1d4ed8; }
.role-user  { background: #f1f5f9; color: var(--muted); }

.role-toggle {
  padding: 5px 11px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  font-size: 12px; color: var(--muted); cursor: pointer;
  transition: all .15s;
}
.role-toggle:hover { background: var(--bg); color: var(--text); }
.me-tag {
  display: inline-block; font-size: 10px;
  background: #f0fdf4; color: #166534;
  padding: 1px 6px; border-radius: 4px;
  margin-left: 6px; font-weight: 500;
}
