:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232733;
  --border: #2e3345;
  --text: #e4e6f0;
  --text-dim: #8b8fa3;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --green: #00cec9;
  --orange: #fdcb6e;
  --red: #ff7675;
  --blue: #74b9ff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--text-dim); }
a { color: var(--accent2); }

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #1a1d27 0%, #2d1f5e 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 16px;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 40px; height: 40px; background: var(--accent); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.header h1 span { color: var(--accent2); }
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status-badge {
  display: flex; align-items: center; gap: 6px; background: var(--surface2);
  padding: 6px 14px; border-radius: 20px; font-size: 13px; color: var(--text-dim);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Account menu ── */
.acct-menu { position: relative; }
.acct-btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px; font-size: 13px; font-weight: 500;
}
.acct-btn .caret { color: var(--text-dim); font-size: 11px; }
.acct-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 50;
  width: 320px; max-width: 86vw; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0,0,0,.5); overflow: hidden;
}
.acct-panel-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }
.acct-panel-head { padding: 16px; border-bottom: 1px solid var(--border); }
.acct-panel-email { font-weight: 600; margin-top: 3px; word-break: break-all; }
.acct-panel-section { padding: 16px; border-bottom: 1px solid var(--border); }
.menu-devices { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow-y: auto; }
.menu-devices li {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.menu-devices li:last-child { border-bottom: none; }
.dev-thumb {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 8px; object-fit: cover;
  background: var(--surface2); border: 1px solid var(--border);
}
.dev-thumb-ph {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.dev-info { min-width: 0; flex: 1; }
.dev-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-type { font-size: 11px; color: var(--text-dim); }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge.online { background: rgba(0,206,201,.15); color: var(--green); }
.badge.offline { background: rgba(253,203,110,.15); color: var(--orange); }
.badge.unknown { background: rgba(139,143,163,.15); color: var(--text-dim); }
.acct-signout {
  display: block; width: 100%; text-align: left; cursor: pointer; background: none;
  border: none; color: var(--red); font-size: 14px; font-weight: 600; padding: 15px 16px;
}
.acct-signout:hover { background: var(--surface2); }

/* ── Buttons ── */
.btn {
  background: var(--accent); color: #fff; border: none; padding: 9px 20px;
  border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s;
}
.btn:hover { background: var(--accent2); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-outline:hover { border-color: var(--accent); color: var(--text); background: transparent; }

/* ── Controls ── */
.controls { padding: 20px 32px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.control-group { display: flex; align-items: center; gap: 8px; }
.control-group label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
select, input[type="email"], input[type="text"] {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; outline: none;
}
select { cursor: pointer; }
select:hover { border-color: var(--accent); }
input:focus, select:focus { border-color: var(--accent); }
.last-updated { font-size: 11px; color: var(--text-dim); }

/* ── KPI cards ── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; padding: 0 32px 20px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-card:nth-child(1)::before { background: var(--green); }
.kpi-card:nth-child(2)::before { background: var(--blue); }
.kpi-card:nth-child(3)::before { background: var(--orange); }
.kpi-card:nth-child(4)::before { background: var(--accent); }
.kpi-card:nth-child(5)::before { background: var(--accent2); }
.kpi-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.kpi-value { font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.kpi-sub { font-size: 12px; color: var(--text-dim); }
.trend-up { color: var(--green); }
.trend-down { color: var(--orange); }

/* ── Charts ── */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 0 32px 20px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.chart-card.full-width { grid-column: 1 / -1; }
.chart-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.chart-subtitle { font-size: 12px; color: var(--text-dim); margin-bottom: 16px; }

/* Info icon + tooltip (used on the Event breakdown title) */
.info { position: relative; display: inline-flex; margin-left: 6px; color: var(--text-dim); cursor: help; font-size: 13px; outline: none; }
.info:hover, .info:focus { color: var(--accent2); }
.info-tip {
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  width: 280px; max-width: 70vw; z-index: 60;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 12px; font-weight: 400; line-height: 1.5;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  opacity: 0; visibility: hidden; transition: opacity .15s;
  pointer-events: none;
}
.info-tip::before {
  content: ""; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom-color: var(--surface2);
}
.info:hover .info-tip, .info:focus .info-tip { opacity: 1; visibility: visible; }
.info-tip strong { color: var(--accent2); font-weight: 600; }
.chart-container { position: relative; width: 100%; height: 280px; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); max-width: 560px; margin: 0 auto; }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

/* ── Upsell ── */
.upsell-card {
  margin: 0 32px 32px; background: rgba(108,92,231,.08);
  border: 1px dashed var(--accent); border-radius: 12px; padding: 20px;
}
.upsell-card h3 { font-size: 15px; margin-bottom: 6px; }
.upsell-card p { font-size: 13px; color: var(--text-dim); }

/* ── Auth (signed-out) ── */
.auth-wrap { display: flex; justify-content: center; padding: 48px 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 460px; }
.auth-card h2 { font-size: 22px; margin-bottom: 8px; }
.auth-lead { color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }
.auth-row { display: flex; gap: 10px; }
.auth-row input { flex: 1 1 auto; min-width: 0; }
.auth-error { color: var(--red); font-size: 13px; margin-top: 10px; }

/* ── Loading overlay ── */
.loading-overlay { position: fixed; inset: 0; background: rgba(15,17,23,.85); display: flex; align-items: center; justify-content: center; z-index: 100; transition: opacity .3s; }
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .header, .controls, .kpi-row, .charts-grid, .upsell-card { padding-left: 16px; padding-right: 16px; }
  .upsell-card { margin-left: 16px; margin-right: 16px; }
}
