/* ============================================================
   trq dashboard — dark theme
   ============================================================ */

:root {
  --bg:        #0d0f17;
  --surface:   #161929;
  --surface2:  #1e2235;
  --border:    #2a2f47;
  --text:      #e2e8f0;
  --text2:     #8892a4;
  --accent:    #4a6cf7;
  --cyan:      #22d3ee;
  --purple:    #a78bfa;
  --red:       #ef4444;
  --orange:    #f59e0b;
  --green:     #10b981;
  --teal:      #14b8a6;
  --radius:    8px;
  --shadow:    0 4px 20px rgba(0,0,0,.4);
}

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

html, body { height: 100%; }

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

/* ── Login ─────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.overlay[hidden] { display: none; }

.login-box {
  display: flex; flex-direction: column; gap: 16px;
  width: 360px; padding: 48px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); text-align: center;
}
.login-box h1 { font-size: 32px; letter-spacing: .2em; color: var(--accent); }
.login-box input {
  padding: 10px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
  padding: 10px; background: var(--accent); border: none;
  border-radius: var(--radius); color: #fff; font-size: 14px; cursor: pointer;
}
.login-box button:hover { opacity: .85; }
.login-error { color: var(--red); font-size: 13px; }

/* ── Layout ─────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; }
.app[hidden] { display: none; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-logo { font-size: 22px; font-weight: 700; letter-spacing: .15em; color: var(--accent); }

.live-badge {
  display: flex; align-items: center; gap: 7px;
  margin-top: 8px; font-size: 12px; color: var(--text2);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text2);
}
.live-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; color: var(--text2);
  text-decoration: none; font-size: 13.5px;
  transition: color .15s, background .15s;
}
.nav-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--accent); background: rgba(74,108,247,.1); }

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.last-updated { font-size: 11px; color: var(--text2); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none; background: none; border: none;
  color: var(--text2); cursor: pointer; padding: 4px;
}
.sidebar-toggle svg { width: 22px; height: 22px; fill: currentColor; }

.date-range-picker { position: relative; }
.date-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; font-size: 13px;
}
.date-btn svg { width: 16px; height: 16px; fill: currentColor; }
.date-btn .caret { width: 14px; height: 14px; opacity: .6; }
.date-btn:hover { border-color: var(--accent); }

.date-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 200;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; min-width: 280px;
}
.date-dropdown[hidden] { display: none; }

.date-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.date-presets button {
  padding: 7px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text2); cursor: pointer; font-size: 12px;
}
.date-presets button:hover { border-color: var(--accent); color: var(--text); }

.date-custom { display: flex; flex-direction: column; gap: 8px; }
.date-custom label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
.date-custom input[type="date"] {
  flex: 1; padding: 6px 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 12px;
  color-scheme: dark;
}
.date-custom #date-apply {
  align-self: flex-end; padding: 7px 16px;
  background: var(--accent); border: none; border-radius: 6px;
  color: #fff; cursor: pointer; font-size: 12px;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.toggle-bots { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); cursor: pointer; }

.btn-icon {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2); cursor: pointer;
}
.btn-icon svg { width: 16px; height: 16px; fill: currentColor; }
.btn-icon:hover { border-color: var(--accent); color: var(--text); }
.btn-icon.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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

.section { display: none; }
.section.active { display: block; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-head h2 { font-size: 18px; font-weight: 600; }

/* ── Stat Cards ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 20px;
}

.stat-card {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; fill: #fff; }
.stat-icon.blue   { background: rgba(74,108,247,.2); color: var(--accent); }
.stat-icon.cyan   { background: rgba(34,211,238,.15); }
.stat-icon.purple { background: rgba(167,139,250,.15); }
.stat-icon.red    { background: rgba(239,68,68,.15); }
.stat-icon.orange { background: rgba(245,158,11,.15); }
.stat-icon.teal   { background: rgba(20,184,166,.15); }
.stat-icon.green  { background: rgba(16,185,129,.15); }

.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 2px; text-transform: uppercase; letter-spacing: .06em; }

/* ── Cards ──────────────────────────────────────────────────── */
.card-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card.wide { grid-column: 1 / -1; }
.card.full { grid-column: 1 / -1; margin-bottom: 16px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h3 { font-size: 14px; font-weight: 600; }

.chart-wrap { position: relative; }
.chart-wrap canvas { width: 100% !important; }
.h220 { height: 220px; }
.h280 { height: 280px; }
.h300 { height: 300px; }
.h320 { height: 320px; }
.h400 { height: 400px; }

/* ── Period Tabs ─────────────────────────────────────────────── */
.period-tabs { display: flex; gap: 4px; }
.period-tab {
  padding: 4px 10px; font-size: 12px;
  background: none; border: 1px solid var(--border);
  border-radius: 5px; color: var(--text2); cursor: pointer;
}
.period-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.period-tab:not(.active):hover { border-color: var(--accent); color: var(--text); }

/* ── Map ─────────────────────────────────────────────────────── */
.map-container { border-radius: 6px; overflow: hidden; background: var(--surface2); }
.leaflet-container { background: #1a1d26 !important; }

/* ── Live Feed ───────────────────────────────────────────────── */
.live-feed {
  display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100vh - 180px); overflow-y: auto;
}
.live-empty { color: var(--text2); text-align: center; padding: 40px; }

.live-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } }

.live-item-flag { font-size: 22px; line-height: 1; }
.live-item-info { flex: 1; min-width: 0; }
.live-item-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.live-item-ip   { font-family: monospace; font-size: 13px; }
.live-item-loc  { color: var(--text2); font-size: 12px; }
.live-item-ua   { color: var(--text2); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-item-ts   { font-size: 11px; color: var(--text2); flex-shrink: 0; }

/* ── Data Table ─────────────────────────────────────────────── */
.table-controls { display: flex; align-items: center; gap: 10px; }
.table-controls input {
  padding: 7px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; width: 200px;
}
.table-controls input:focus { outline: none; border-color: var(--accent); }

.filter-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 100;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; min-width: 260px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.filter-panel[hidden] { display: none; }
.filter-panel label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text2);
}
.filter-panel input[type="text"],
.filter-panel select {
  flex: 1; padding: 5px 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); font-size: 12px;
}
.filter-actions { display: flex; gap: 8px; }
.filter-actions button {
  flex: 1; padding: 7px; background: var(--accent); border: none;
  border-radius: 5px; color: #fff; cursor: pointer; font-size: 12px;
}

.section-head { position: relative; }

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 600;
  color: var(--text2); border-bottom: 1px solid var(--border);
  background: var(--surface2); cursor: pointer; white-space: nowrap;
  user-select: none;
}
.data-table th:hover { color: var(--text); }
.data-table td {
  padding: 10px 12px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis;
}
.data-table tbody tr:hover { background: var(--surface2); }
.data-table td:last-child { max-width: none; }

.flag-badge {
  display: inline-flex; align-items: center;
  gap: 3px; padding: 2px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}
.flag-tor     { background: rgba(239,68,68,.15); color: var(--red); }
.flag-vpn     { background: rgba(245,158,11,.15); color: var(--orange); }
.flag-incog   { background: rgba(167,139,250,.15); color: var(--purple); }
.flag-bot     { background: rgba(136,146,164,.15); color: var(--text2); }
.flag-leaked  { background: rgba(239,68,68,.2); color: var(--red); }

.btn-detail {
  padding: 4px 10px; background: none;
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text2); cursor: pointer; font-size: 12px;
}
.btn-detail:hover { border-color: var(--accent); color: var(--text); }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 16px 0;
}
.pagination button {
  padding: 6px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); cursor: pointer; font-size: 13px;
}
.pagination button:hover:not(:disabled) { border-color: var(--accent); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination-info { font-size: 12px; color: var(--text2); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 680px; max-width: 95vw;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-head h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; color: var(--text2);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }

.detail-section { margin-bottom: 20px; }
.detail-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text2); margin-bottom: 10px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-label { font-size: 11px; color: var(--text2); }
.detail-value { font-size: 13px; word-break: break-all; }
.detail-value.mono { font-family: monospace; }
.detail-map { height: 200px; margin-top: 10px; border-radius: 6px; overflow: hidden; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-ghost {
  padding: 7px 12px; background: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text2); cursor: pointer; font-size: 12px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -220px; top: 0; height: 100%; z-index: 300; transition: left .25s; }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: flex; }
  .sidebar-close  { display: flex; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .card-row { grid-template-columns: 1fr; }
}

/* ── Sidebar Overlay (mobile) ───────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,.5);
}
.sidebar-overlay.visible { display: block; }

/* ── Sidebar Brand Row ──────────────────────────────────────── */
.brand-row {
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-close {
  display: none;
  background: none; border: none; color: var(--text2);
  cursor: pointer; padding: 4px; align-items: center;
  border-radius: 5px;
}
.sidebar-close svg { width: 20px; height: 20px; fill: currentColor; }
.sidebar-close:hover { color: var(--text); background: var(--surface2); }

/* ── Property Selector (in Sidebar) ────────────────────────── */
.property-selector {
  position: relative; margin-top: 10px;
}
.prop-sel-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; font-size: 12px; text-align: left;
}
.prop-sel-btn svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
.prop-sel-btn:hover { border-color: var(--accent); }

.prop-sel-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 400;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.prop-sel-dropdown[hidden] { display: none; }
.prop-sel-item {
  display: block; width: 100%; padding: 9px 12px; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--border);
  color: var(--text2); cursor: pointer; font-size: 12px;
}
.prop-sel-item:last-child { border-bottom: none; }
.prop-sel-item:hover { background: var(--surface); color: var(--text); }
.prop-sel-item.active { color: var(--accent); background: rgba(74,108,247,.08); }

/* ── Properties Section ─────────────────────────────────────── */
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}
.status-active   { background: rgba(16,185,129,.15); color: var(--green); }
.status-inactive { background: rgba(136,146,164,.15); color: var(--text2); }

.prop-form {
  display: flex; flex-direction: column; gap: 12px;
}
.prop-form label {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--text2);
  min-width: 0;
}
.prop-form label > span,
.prop-form label:first-child { flex-shrink: 0; min-width: 56px; }
.prop-form input {
  flex: 1; padding: 7px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px;
}
.prop-form input:focus { outline: none; border-color: var(--accent); }
.prop-form input:disabled { opacity: .5; cursor: not-allowed; }
.prop-form-actions { display: flex; gap: 10px; margin-top: 4px; }
.prop-form-actions button:first-child {
  padding: 8px 20px; background: var(--accent); border: none;
  border-radius: var(--radius); color: #fff; cursor: pointer; font-size: 13px;
}
.prop-form-actions button:first-child:hover { opacity: .85; }

.prop-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-danger { border-color: rgba(239,68,68,.4) !important; color: var(--red) !important; }
.btn-danger:hover { background: rgba(239,68,68,.08) !important; }

/* ── User info in sidebar footer ────────────────────────────── */
.user-info {
  font-size: 12px; color: var(--text2);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ── Embed Code Modal ───────────────────────────────────────── */
.embed-section { margin-bottom: 20px; }
.embed-section h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text2); margin-bottom: 8px;
}
.embed-code {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  font-family: monospace; font-size: 12px; color: var(--cyan);
  white-space: pre; overflow-x: auto; line-height: 1.6;
}
