/* ─────────────────────────────────────────
   PixelTrack — Design System
   Aesthetic: Industrial terminal meets
   precision analytics dashboard.
   Palette: Near-black, stark white,
   electric amber accent.
   ───────────────────────────────────────── */

:root {
  --bg:       #0d0d0f;
  --surface:  #15151a;
  --surface2: #1c1c23;
  --border:   #2a2a35;
  --text:     #e8e8f0;
  --muted:    #6b6b80;
  --accent:   #f5a623;
  --accent2:  #ff6b35;
  --green:    #34d399;
  --red:      #f87171;
  --blue:     #60a5fa;
  --radius:   4px;
  --font-ui:  'Syne', sans-serif;
  --font-mono:'DM Mono', monospace;
  --sidebar-w:220px;
  --header-h: 64px;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  line-height: 1.6;
}

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

/* ─────────────── Sidebar ─────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  color: var(--accent);
  font-size: 1.4rem;
  animation: spin-slow 8s linear infinite;
}
@keyframes spin-slow { to { transform: rotate(360deg); } }

.brand-name {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #000; font-weight: 600; }

.nav-icon { font-size: 0.8rem; width: 1rem; text-align: center; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.status-dot {
  font-size: 0.75rem;
  color: var(--muted);
}
.status-dot.ok   { color: var(--green); }
.status-dot.err  { color: var(--red); }

/* ─────────────── Main Layout ─────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.page-body {
  padding: 2rem;
  flex: 1;
}

/* ─────────────── Buttons ─────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-color: var(--accent);
}
.btn-primary:hover { background: #e09415; border-color: #e09415; }

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-secondary:hover { background: rgba(245,166,35,0.1); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-full { width: 100%; justify-content: center; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover { background: rgba(248,113,113,0.1); }

/* ─────────────── Stats Grid ─────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content:'';
  position:absolute;
  top:0; left:0;
  width:3px; height:100%;
  background: var(--border);
}
.stat-card.accent::before { background: var(--accent); }

.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.stat-value {
  font-family: var(--font-ui);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.stat-card.accent .stat-value { color: var(--accent); }

/* ─────────────── Filter Bar ─────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-field { flex: 1; min-width: 200px; }

.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.filter-btn {
  padding: 0.35rem 0.85rem;
  border: none;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn.active { background: var(--accent); color: #000; font-weight: 600; }
.filter-btn:hover:not(.active) { color: var(--text); }

/* ─────────────── Table ─────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  white-space: nowrap;
}

.data-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

.loading-row { text-align: center; color: var(--muted); padding: 2rem !important; }

/* Status Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.badge-open   { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-closed { background: rgba(107,107,128,0.15); color: var(--muted); }

/* Pagination */
.pagination {
  display: flex;
  gap: 0.4rem;
  margin-top: 1rem;
  justify-content: flex-end;
}
.page-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  transition: all 0.15s;
}
.page-btn:hover { color: var(--text); border-color: var(--muted); }
.page-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight:600; }

/* ─────────────── Modal ─────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 640px;
  max-width: 95vw;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 1rem;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

/* ─────────────── Cards ─────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.card-header h2 {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.card-icon { color: var(--accent); }

.card-body { padding: 1.25rem; }

/* ─────────────── Forms ─────────────── */
.field-group { margin-bottom: 1rem; }

.field-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.input-field {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  transition: border-color 0.15s;
  outline: none;
}
.input-field:focus { border-color: var(--accent); }

.textarea-field { resize: vertical; min-height: 140px; }

select.input-field option { background: var(--surface); }

/* Editor toolbar */
.editor-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.toolbar-btn {
  padding: 0.3rem 0.65rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.toolbar-btn:hover { color: var(--text); border-color: var(--muted); }

.email-preview {
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  background: #fff;
  color: #111;
  font-family: sans-serif;
  font-size: 0.9rem;
  min-height: 100px;
  margin-top: 8px;
}

/* File drop */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  transition: border-color 0.15s;
}
.file-drop:hover { border-color: var(--accent); color: var(--text); }

/* Progress bar */
.progress-wrap { margin-top: 1rem; }
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}
.progress-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.4rem;
}

/* ─────────────── Alerts ─────────────── */
.alert {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.82rem;
  margin-bottom: 1rem;
  border-left: 3px solid;
}
.alert-success { background: rgba(52,211,153,0.1); border-color: var(--green); color: var(--green); }
.alert-error   { background: rgba(248,113,113,0.1); border-color: var(--red);   color: var(--red);   }
.alert-info    { background: rgba(96,165,250,0.1);  border-color: var(--blue);  color: var(--blue);  }

/* ─────────────── Compose Layout ─────────────── */
.compose-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) { .compose-layout { grid-template-columns: 1fr; } }

.compose-right { display: flex; flex-direction: column; gap: 1rem; }

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.hint code {
  background: var(--surface2);
  padding: 0.1em 0.35em;
  border-radius: 2px;
  color: var(--accent);
}

/* ─────────────── Analytics ─────────────── */
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.analytics-stats {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.chart-card.wide { grid-column: 1 / -1; }

.chart-title {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 1rem;
}

.chart-wrap { position: relative; height: 220px; }
.donut-wrap { height: 200px; display: flex; align-items: center; justify-content: center; }

/* ─────────────── Detail modal content ─────────────── */
.detail-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.detail-label {
  width: 120px;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 2px;
}
.detail-value { color: var(--text); word-break: break-all; }

.opens-list { margin-top: 1rem; }
.opens-list h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.open-event {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.open-event strong { color: var(--text); }
