/* ─────────────────────────────────────────────────────────────
   TRA Admin — Global responsive + a11y + animation layer
   ───────────────────────────────────────────────────────────── */

:root {
  --tra-sidebar-w: 220px;
  --tra-content-pad: 32px;
  /* Theme colors - will be set by JavaScript */
  --tra-bg: #FFFFFF;
  --tra-surface: #F9FAFB;
  --tra-surface2: #F3F4F6;
  --tra-border: #E5E7EB;
  --tra-borderHi: #D1D5DB;
  --tra-text: #111827;
  --tra-textDim: #374151;
  --tra-textMuted: #6B7280;
  --tra-textFaint: #9CA3AF;
  --tra-accent: #FF4444;
  --tra-accentHi: #FF6B6B;
}

html, body, #root { margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--tra-bg);
  color: var(--tra-textDim);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ── Accessibility: focus rings ─────────────────────────────── */
*:focus { outline: none; }
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid #FF6B6B;
  outline-offset: 2px;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes tra-spin { to { transform: rotate(360deg); } }
@keyframes tra-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.4); }
}
@keyframes tra-skeleton {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}
@keyframes tra-toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.tra-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: tra-spin 0.7s linear infinite;
  vertical-align: middle;
}

.tra-skeleton {
  background: linear-gradient(90deg, #13131F 0%, #1F1F2E 50%, #13131F 100%);
  background-size: 400px 100%;
  animation: tra-skeleton 1.2s infinite;
  border-radius: 6px;
}

/* ── Layout: sidebar + main content ──────────────────────────── */
.tra-app-shell { display: flex; min-height: 100vh; }

.tra-sidebar { transition: transform 0.25s ease; }

.tra-main {
  margin-left: var(--tra-sidebar-w);
  flex: 1;
  padding: var(--tra-content-pad);
  min-height: 100vh;
}

/* Hamburger button — hidden on desktop */
.tra-hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--tra-surface);
  border: 1px solid var(--tra-borderHi);
  color: var(--tra-textDim);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.tra-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

/* ── Responsive grids ───────────────────────────────────────── */
.tra-grid-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.tra-grid-charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
.tra-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.tra-grid-map {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
}
.tra-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.tra-filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Tablet ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .tra-grid-stats { grid-template-columns: repeat(2, 1fr); }
  .tra-grid-charts, .tra-grid-2, .tra-grid-map { grid-template-columns: 1fr; }
}

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --tra-content-pad: 16px;
  }
  .tra-hamburger { display: flex; }

  .tra-sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }
  .tra-sidebar.tra-sidebar-open { transform: translateX(0); }
  .tra-sidebar.tra-sidebar-open + .tra-sidebar-backdrop { display: block; }

  .tra-main { margin-left: 0; padding-top: 64px; }

  .tra-grid-stats { grid-template-columns: 1fr; }

  .tra-page-header h1 { font-size: 20px !important; }

  /* Make data tables horizontally scroll cleanly */
  .tra-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Reduce table cell padding */
  .tra-table-wrap th, .tra-table-wrap td { padding: 8px 10px !important; }
}

/* ── Larger touch targets on mobile ─────────────────────────── */
@media (max-width: 768px) {
  button, a[role="button"] {
    min-height: 40px;
  }
}

/* ── Toast container ────────────────────────────────────────── */
.tra-toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.tra-toast {
  pointer-events: auto;
  min-width: 240px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--tra-surface);
  border: 1px solid var(--tra-borderHi);
  color: var(--tra-text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: tra-toast-in 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.tra-toast-success { border-left: 3px solid #22C55E; }
.tra-toast-error { border-left: 3px solid #EF4444; }
.tra-toast-info { border-left: 3px solid #3B82F6; }
.tra-toast-warn { border-left: 3px solid #F59E0B; }

@media (max-width: 480px) {
  .tra-toast-stack { left: 16px; right: 16px; bottom: 16px; }
  .tra-toast { min-width: 0; max-width: none; }
}

/* ── Empty state helper ─────────────────────────────────────── */
.tra-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--tra-textFaint);
}
.tra-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}
