/* ═══════════════════════════════════════════════════════════════════
   Pulse Dashboard — Modern Minimalist Dark Theme
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg:         #0b0e14;
  --bg-card:    #12161e;
  --bg-hover:   #1a1f2b;
  --bg-input:   #161b26;
  --border:     #1e2533;
  --border-light:#2a3040;
  --text:       #e0e4ec;
  --text-muted: #6b7a94;
  --text-dim:   #4a5568;
  --accent:     #6c5ce7;
  --accent-h:   #7c6df7;
  --blue:       #3b82f6;
  --green:      #22c55e;
  --orange:     #f59e0b;
  --red:        #ef4444;
  --purple:     #a855f7;
  --teal:       #14b8a6;
  --cyan:       #06b6d4;
  --radius:     10px;
  --radius-sm:  6px;
  --radius-lg:  14px;
  --shadow:     0 2px 12px rgba(0,0,0,.35);
  --sidebar-w:  240px;
  --transition: .2s ease;
  --font:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
.hidden { display: none !important; }

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

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

/* ═══════════════════ LOGIN ═══════════════════ */

.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,92,231,.12) 0%, transparent 60%), var(--bg);
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2.5rem 2rem; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { margin: .5rem 0 .25rem; font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
.login-subtitle { color: var(--text-muted); font-size: .85rem; }
.login-error { color: var(--red); font-size: .8rem; margin-top: .75rem; text-align: center; min-height: 1rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"], textarea, select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .6rem .75rem; color: var(--text);
  font-family: var(--font); font-size: .9rem; transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }

.input-sm { padding: .4rem .6rem; font-size: .8rem; max-width: 200px; }
.input-lg { padding: .75rem 1rem; font-size: 1rem; }
.select-sm { padding: .35rem .5rem; font-size: .75rem; max-width: 120px; cursor: pointer; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-weight: 500; font-size: .85rem;
  padding: .55rem 1.1rem; transition: all var(--transition);
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .78rem; }

/* ═══════════════════ LAYOUT ═══════════════════ */

.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform .3s ease;
}
.sidebar-header {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.25rem 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.sidebar-nav { flex: 1; padding: .5rem 0; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1rem; margin: 0 .5rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .85rem; font-weight: 500; transition: all var(--transition);
}
.nav-item:hover { color: var(--text); background: var(--bg-hover); }
.nav-item.active { color: var(--accent-h); background: rgba(108,92,231,.12); }

.sidebar-footer {
  padding: .75rem 1rem; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

/* WebSocket indicator */
.ws-status { display: flex; align-items: center; gap: .4rem; font-size: .72rem; color: var(--text-muted); }
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); transition: background var(--transition); }
.ws-status.connected .ws-dot { background: var(--green); }
.ws-status.connected .ws-label { color: var(--green); }

/* ── Mobile Header ── */
.mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: .6rem 1rem; align-items: center; gap: .75rem;
}
.hamburger { background: none; border: none; color: var(--text); cursor: pointer; padding: .25rem; }
.mobile-brand { font-weight: 700; font-size: 1.05rem; }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w); flex: 1; padding: 1.5rem 2rem; min-width: 0;
}

.page-header {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header h2 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.header-actions { display: flex; gap: .5rem; margin-left: auto; flex-wrap: wrap; }

.live-badge {
  font-size: .65rem; font-weight: 600; padding: .2rem .5rem; border-radius: 3px;
  background: rgba(34,197,94,.15); color: var(--green); letter-spacing: .06em;
  animation: pulse-badge 2s ease-in-out infinite;
}
@keyframes pulse-badge { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ═══════════════════ CARDS ═══════════════════ */

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 1.25rem; overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: .9rem; font-weight: 600; }
.card-body { padding: 1.1rem; }
.card-compact { padding: 1rem 1.1rem; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; display: flex; align-items: center; gap: .85rem;
  transition: border-color var(--transition);
}
.kpi-card:hover { border-color: var(--border-light); }
.kpi-icon {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); flex-shrink: 0;
}
.kpi-icon.blue   { background: rgba(59,130,246,.12); color: var(--blue);   }
.kpi-icon.green  { background: rgba(34,197,94,.12);  color: var(--green);  }
.kpi-icon.orange { background: rgba(245,158,11,.12); color: var(--orange); }
.kpi-icon.purple { background: rgba(168,85,247,.12); color: var(--purple); }
.kpi-icon.teal   { background: rgba(20,184,166,.12); color: var(--teal);   }
.kpi-icon.red    { background: rgba(239,68,68,.12);  color: var(--red);    }
.kpi-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.kpi-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ═══════════════════ CHARTS ═══════════════════ */

.chart-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem; margin-bottom: 1.25rem;
}
.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.chart-card.chart-wide { grid-column: span 2; }
.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border);
}
.chart-header h3 { font-size: .85rem; font-weight: 600; }
.chart-body { padding: .75rem 1rem; position: relative; height: 260px; }
.chart-body-sm { height: 220px; }
.chart-body canvas { width: 100% !important; height: 100% !important; }

/* ═══════════════════ TABLES ═══════════════════ */

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th {
  text-align: left; padding: .6rem .85rem; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  background: var(--bg-hover); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.data-table td {
  padding: .55rem .85rem; border-bottom: 1px solid var(--border); font-size: .82rem;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
}
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr.highlight { animation: row-flash .6s ease; }
@keyframes row-flash { 0% { background: rgba(108,92,231,.2); } 100% { background: transparent; } }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .85rem 1rem; border-top: 1px solid var(--border);
}
.pagination button {
  background: var(--bg-hover); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: .3rem .6rem; font-size: .78rem; cursor: pointer;
  transition: all var(--transition);
}
.pagination button:hover { border-color: var(--accent); color: var(--accent); }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:disabled { opacity: .3; cursor: not-allowed; }

/* ═══════════════════ BADGES ═══════════════════ */

.badge {
  display: inline-flex; align-items: center; padding: .15rem .45rem;
  border-radius: 3px; font-size: .7rem; font-weight: 600;
}
.badge-green  { background: rgba(34,197,94,.15);  color: var(--green);  }
.badge-orange { background: rgba(245,158,11,.15); color: var(--orange); }
.badge-red    { background: rgba(239,68,68,.15);  color: var(--red);    }
.badge-blue   { background: rgba(59,130,246,.15); color: var(--blue);   }
.badge-purple { background: rgba(168,85,247,.15); color: var(--purple); }

.score-badge {
  display: inline-block; padding: .2rem .5rem; border-radius: 3px;
  font-size: .75rem; font-weight: 600;
}
.score-low    { background: rgba(34,197,94,.15);  color: var(--green);  }
.score-medium { background: rgba(245,158,11,.15); color: var(--orange); }
.score-high   { background: rgba(239,68,68,.15);  color: var(--red);    }

/* ═══════════════════ MODALS ═══════════════════ */

.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.show { display: flex; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 780px;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.modal.modal-sm { max-width: 420px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg-card); z-index: 1;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1.5rem; line-height: 1; padding: .25rem; transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; }

/* ── Visitor detail sections ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1.25rem; }
.detail-item { display: flex; flex-direction: column; gap: .1rem; }
.detail-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.detail-value { font-size: .85rem; font-weight: 500; word-break: break-all; }

.detail-section { margin-bottom: 1.25rem; }
.detail-section h4 { font-size: .82rem; font-weight: 600; margin-bottom: .5rem; padding-bottom: .35rem; border-bottom: 1px solid var(--border); }

.signal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .4rem; }
.signal-item { font-size: .78rem; padding: .35rem .5rem; background: var(--bg-hover); border-radius: var(--radius-sm); display: flex; justify-content: space-between; gap: .5rem; }
.signal-key { color: var(--text-muted); }
.signal-val { color: var(--text); font-weight: 500; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═══════════════════ SITES ═══════════════════ */

.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.site-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem; transition: border-color var(--transition);
}
.site-card:hover { border-color: var(--border-light); }
.site-card h4 { font-size: .95rem; font-weight: 600; margin-bottom: .5rem; }
.site-meta { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: .75rem; }
.site-meta span { font-size: .78rem; color: var(--text-muted); }
.site-meta strong { color: var(--text); }
.site-key {
  font-family: 'Courier New', monospace; font-size: .72rem;
  background: var(--bg-hover); padding: .35rem .6rem; border-radius: var(--radius-sm);
  word-break: break-all; color: var(--text-muted); margin-bottom: .65rem;
}
.site-actions { display: flex; gap: .5rem; }

/* ═══════════════════ ML ═══════════════════ */

.ml-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }

/* ═══════════════════ IP LOOKUP ═══════════════════ */

.ip-lookup-form { display: flex; gap: .75rem; }
.ip-lookup-form input { flex: 1; }

.ip-result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.ip-result-item { padding: .5rem; background: var(--bg-hover); border-radius: var(--radius-sm); }
.ip-result-item .key { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; }
.ip-result-item .val { font-size: .85rem; font-weight: 500; }

/* ═══════════════════ UTILITIES ═══════════════════ */

.text-muted { color: var(--text-muted); }
.text-xs { font-size: .72rem; }
.mt-2 { margin-top: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mono { font-family: 'Courier New', monospace; font-size: .8rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tab-content { display: none; }
.tab-content.active { display: block; animation: tab-fade .25s ease; }
@keyframes tab-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 600; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .65rem 1rem; font-size: .82rem; box-shadow: var(--shadow);
  animation: toast-in .3s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ═══════════════════ RESPONSIVE ═══════════════════ */

@media (max-width: 1024px) {
  .chart-card.chart-wide { grid-column: span 1; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; padding: 4rem 1rem 1.5rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .ip-result-grid { grid-template-columns: 1fr; }
  .sites-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
  .header-actions input { max-width: none; flex: 1; }
}
