/* ═══════════════════════════════════════════════════════════════
   Presence Controller — Dark Theme, Sharp Corners, Minimal
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  /* Colors */
  --bg-primary: #08080d;
  --bg-secondary: #0e0e15;
  --bg-card: #12121b;
  --bg-card-hover: #181824;
  --bg-input: #0c0c14;
  --border: #1e1e2e;
  --border-hover: #2a2a3e;
  --text-primary: #e4e4ef;
  --text-secondary: #7a7a95;
  --text-muted: #4a4a62;
  --accent: #5865f2;
  --accent-dim: rgba(88, 101, 242, 0.15);
  --accent-glow: rgba(88, 101, 242, 0.3);

  /* Status Colors */
  --status-online: #3ba55d;
  --status-idle: #faa81a;
  --status-dnd: #ed4245;
  --status-offline: #4a4a62;

  /* Layout */
  --header-h: 56px;
  --footer-h: 36px;
  --sidebar-w: 320px;
  --gap: 16px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

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

/* ── Header ───────────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  color: var(--accent);
  display: flex;
  align-items: center;
}

#app-header h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.header-badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 8px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(88, 101, 242, 0.25);
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 4px;
}

.header-badge.connected {
  background: rgba(59, 165, 93, 0.15);
  color: var(--status-online);
  border-color: rgba(59, 165, 93, 0.25);
}

.header-badge.live::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: var(--status-online);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--status-online);
  animation: pulse-live 1.8s infinite ease-in-out;
}

@keyframes pulse-live {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 12px var(--status-online); }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Search ───────────────────────────────────────────────────── */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px 6px 32px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  width: 220px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* ── Icon Button ──────────────────────────────────────────────── */
.icon-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Main Layout ──────────────────────────────────────────────── */
#app-main {
  flex: 1;
  padding: var(--gap) 24px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ── Stat Cards ───────────────────────────────────────────────── */
#stats-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 18px 20px;
  transition: border-color 0.2s, transform 0.15s;
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat-value-sm {
  font-size: 1.1rem;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: normal;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Content Grid ─────────────────────────────────────────────── */
#content-grid {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: var(--gap);
  flex: 1;
  min-height: 400px;
}

/* ── Panels ───────────────────────────────────────────────────── */
#user-list-panel,
#chart-panel,
#log-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.count-badge {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 2px 8px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(88, 101, 242, 0.2);
}

/* ── User List ────────────────────────────────────────────────── */
.scrollable {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

#user-list-panel .scrollable {
  padding: 4px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.user-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.user-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.user-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--bg-card);
}

.status-dot.online { background: var(--status-online); }
.status-dot.idle { background: var(--status-idle); }
.status-dot.dnd { background: var(--status-dnd); }
.status-dot.offline { background: var(--status-offline); }

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status tag shown next to username in user list */
.user-status-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  padding: 1px 6px;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.user-status-tag.online {
  background: rgba(59, 165, 93, 0.15);
  color: var(--status-online);
  border: 1px solid rgba(59, 165, 93, 0.25);
}

.user-status-tag.idle {
  background: rgba(250, 168, 26, 0.15);
  color: var(--status-idle);
  border: 1px solid rgba(250, 168, 26, 0.25);
}

.user-status-tag.dnd {
  background: rgba(237, 66, 69, 0.15);
  color: var(--status-dnd);
  border: 1px solid rgba(237, 66, 69, 0.25);
}

.user-status-tag.offline {
  background: rgba(74, 74, 98, 0.15);
  color: var(--status-offline);
  border: 1px solid rgba(74, 74, 98, 0.25);
}

.user-change-count {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Timeline Chart ───────────────────────────────────────────── */
#chart-panel {
  min-height: 0;
}

.chart-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ctrl-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.ctrl-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ctrl-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 8px;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.ctrl-select:focus {
  border-color: var(--accent);
}

.ctrl-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

#chart-container {
  flex: 1;
  position: relative;
  min-height: 220px;
  overflow: hidden;
}

#chart-container canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#chart-container canvas:active {
  cursor: grabbing;
}

#chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

#chart-empty.hidden {
  display: none;
}

/* Timeline Tooltip */
.tl-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-hover);
  padding: 10px 14px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.12s;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.tl-tooltip.visible {
  opacity: 1;
}

.tl-tooltip-status {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.tl-tooltip-time {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.tl-tooltip-dur {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Legend bar */
.legend-bar {
  display: flex;
  gap: 20px;
  justify-content: center;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
}

.legend-dot.online { background: var(--status-online); }
.legend-dot.idle { background: var(--status-idle); }
.legend-dot.dnd { background: var(--status-dnd); }
.legend-dot.offline { background: var(--status-offline); }

.hint-bar {
  display: flex;
  gap: 24px;
  justify-content: center;
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ── Empty State ──────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 12px;
}

.empty-state .empty-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.empty-state.hidden {
  display: none;
}

/* ── Log Table ────────────────────────────────────────────────── */
#log-panel {
  max-height: 350px;
}

#log-table-wrap {
  position: relative;
}

#log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

#log-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

#log-table th {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

#log-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

#log-table tbody tr {
  transition: background 0.1s;
}

#log-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.log-user-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.log-avatar {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  overflow: hidden;
}

.log-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 500;
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.status-badge.online {
  background: rgba(59, 165, 93, 0.12);
  color: var(--status-online);
  border: 1px solid rgba(59, 165, 93, 0.2);
}

.status-badge.idle {
  background: rgba(250, 168, 26, 0.12);
  color: var(--status-idle);
  border: 1px solid rgba(250, 168, 26, 0.2);
}

.status-badge.dnd {
  background: rgba(237, 66, 69, 0.12);
  color: var(--status-dnd);
  border: 1px solid rgba(237, 66, 69, 0.2);
}

.status-badge.offline {
  background: rgba(74, 74, 98, 0.12);
  color: var(--status-offline);
  border: 1px solid rgba(74, 74, 98, 0.2);
}

.activity-text {
  font-size: 0.7rem;
  color: var(--text-muted);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

#log-empty {
  position: absolute;
  inset: 0;
  top: 40px;
}

#log-empty.hidden {
  display: none;
}

/* ── Footer ───────────────────────────────────────────────────── */
#app-footer {
  height: var(--footer-h);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Animations ───────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.user-item {
  animation: fadeIn 0.2s ease-out;
}

.stat-card {
  animation: fadeIn 0.3s ease-out;
}

#log-table tbody tr {
  animation: fadeIn 0.15s ease-out;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
  #content-grid {
    grid-template-columns: 1fr;
  }
  #user-list-panel {
    max-height: 250px;
  }
  #stats-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  #app-header {
    padding: 0 12px;
  }
  #app-main {
    padding: var(--gap) 12px;
  }
  #stats-section {
    grid-template-columns: 1fr 1fr;
  }
  #search-input {
    width: 140px;
  }
  .hint-bar, .legend-bar {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }
}

/* ── Password Auth Modal ─────────────────────────────────────── */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(6, 6, 10, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.auth-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(88, 101, 242, 0.2);
  animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-icon {
  color: var(--accent);
  margin: 0 auto 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: var(--accent-dim);
  border: 1px solid rgba(88, 101, 242, 0.3);
}

.auth-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.auth-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.auth-input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-password {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-radius: 0;
}

#auth-password:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

#auth-submit-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #ffffff;
  padding: 12px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 0;
}

#auth-submit-btn:hover {
  background: #4752c4;
  border-color: #4752c4;
  box-shadow: 0 0 16px var(--accent-glow);
}

.auth-error-msg {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--status-dnd);
  background: rgba(237, 66, 69, 0.1);
  border: 1px solid rgba(237, 66, 69, 0.25);
  padding: 8px 12px;
  font-weight: 500;
}

.auth-error-msg.hidden {
  display: none;
}

