/* Ready App Admin - Unified Design System
   Ferrari Interior + Apple Design Language
   ======================================== */

:root {
  --bg: #F4F5F7;
  --card: #FFFFFF;
  --sidebar-bg: #0C0E14;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active: #045AFF;
  --text-primary: #1A1D26;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --accent: #045AFF;
  --accent-hover: #0347CC;
  --green: #22C55E;
  --green-bg: #ECFDF5;
  --amber: #F59E0B;
  --amber-bg: #FFFBEB;
  --red: #EF4444;
  --red-bg: #FEF2F2;
  --purple: #8B5CF6;
  --purple-bg: #F3F0FF;
  --teal: #0891B2;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --font: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 252px;
  --content-max: 1360px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 0 !important;
}

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

/* ---- Page Layout ---- */
.ra-page {
  margin-left: var(--sidebar-width);
  padding: 36px 40px 60px;
  max-width: calc(var(--content-max) + 80px);
  transition: margin-left 0.2s ease;
}
body.sidebar-collapsed .ra-page {
  margin-left: 68px;
}

@media (max-width: 900px) {
  .ra-page { margin-left: 0; padding: 64px 16px 60px; }
  .ra-page-title { text-align: center; }
  .ra-page-subtitle { text-align: center; }
  .ra-page-header { flex-direction: column; align-items: center; }
  .ra-page-header-left { align-items: center; }
}

/* ---- Page Header (replaces hero bars) ---- */
.ra-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.ra-page-header-left {
  display: flex;
  flex-direction: column;
}
.ra-page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.ra-page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 4px;
}
.ra-page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Live badge */
.ra-badge-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-bg);
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
}
.ra-badge-live::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: ra-pulse 2s infinite;
}
@keyframes ra-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Metric Cards ---- */
.ra-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) { .ra-metrics { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .ra-metrics { grid-template-columns: 1fr; } }

.ra-metric {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.ra-metric:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.ra-metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.ra-metric-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.ra-metric-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 400;
}
.ra-metric-icon {
  position: absolute;
  top: 18px; right: 18px;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ra-metric-icon svg { width: 18px; height: 18px; }

/* Metric color variants */
.ra-metric.blue .ra-metric-value { color: var(--accent); }
.ra-metric.blue .ra-metric-icon { background: rgba(4,90,255,0.08); color: var(--accent); }
.ra-metric.green .ra-metric-value { color: var(--green); }
.ra-metric.green .ra-metric-icon { background: rgba(34,197,94,0.08); color: var(--green); }
.ra-metric.amber .ra-metric-value { color: var(--amber); }
.ra-metric.amber .ra-metric-icon { background: rgba(245,158,11,0.08); color: var(--amber); }
.ra-metric.red .ra-metric-value { color: var(--red); }
.ra-metric.red .ra-metric-icon { background: rgba(239,68,68,0.08); color: var(--red); }
.ra-metric.purple .ra-metric-value { color: var(--purple); }
.ra-metric.purple .ra-metric-icon { background: rgba(139,92,246,0.08); color: var(--purple); }
.ra-metric.teal .ra-metric-value { color: var(--teal); }
.ra-metric.teal .ra-metric-icon { background: rgba(8,145,178,0.08); color: var(--teal); }

/* Clickable metric card (link wrapper) */
a.ra-metric-link {
  text-decoration: none;
  color: inherit;
  display: block;
  border-radius: var(--radius);
}
a.ra-metric-link:hover { text-decoration: none; }
a.ra-metric-link:hover .ra-metric {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ---- Cards ---- */
.ra-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.ra-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ra-card-title svg { width: 18px; height: 18px; color: var(--text-muted); }

/* ---- Grid Layouts ---- */
.ra-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}
.ra-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.ra-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) {
  .ra-grid-2, .ra-grid-3 { grid-template-columns: 1fr; }
  .ra-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Chart Container ---- */
.ra-chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.ra-chart-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.ra-chart-wrap {
  position: relative;
  height: 300px;
}

/* ---- Tables ---- */
.ra-table-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}
.ra-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.ra-table-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.ra-table-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

table.ra-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.ra-table thead th {
  padding: 12px 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: #FAFBFC;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
table.ra-table thead th:hover { color: var(--accent); }
table.ra-table thead th .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.3;
}
table.ra-table thead th.sorted .sort-arrow { opacity: 1; color: var(--accent); }
table.ra-table thead th.no-sort { cursor: default; }
table.ra-table thead th.no-sort:hover { color: var(--text-muted); }

table.ra-table tbody td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  color: var(--text-primary);
}
table.ra-table tbody tr:last-child td { border-bottom: none; }
table.ra-table tbody tr:hover td { background: #FAFBFC; }
table.ra-table tfoot td {
  padding: 14px 20px;
  font-weight: 600;
  border-top: 1px solid var(--border);
}

/* ---- Filter Row ---- */
.ra-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.ra-filters input,
.ra-filters select {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ra-filters input:focus,
.ra-filters select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(4,90,255,0.08);
}
.ra-filters input { min-width: 220px; }

/* ---- Buttons ---- */
.ra-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ra-btn-primary {
  background: var(--accent);
  color: #fff;
}
.ra-btn-primary:hover { background: var(--accent-hover); }
.ra-btn-secondary {
  background: var(--border-light);
  color: var(--text-primary);
}
.ra-btn-secondary:hover { background: var(--border); }

/* ---- Pill Tabs ---- */
.ra-pills {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ra-pill {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.ra-pill:hover { border-color: var(--accent); color: var(--accent); }
.ra-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---- Status Badges ---- */
.ra-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.ra-badge.delivered { background: #DCFCE7; color: #166534; }
.ra-badge.sent { background: #E0F2FE; color: #0C4A6E; }
.ra-badge.failed { background: #FEE2E2; color: #991B1B; }
.ra-badge.active { background: #ECFDF5; color: #22C55E; }
.ra-badge.canceled { background: #FEF2F2; color: #EF4444; }
.ra-badge.past-due { background: #FFFBEB; color: #F59E0B; }
.ra-badge.new { background: #E8F2FF; color: #045AFF; }

/* ---- Section (collapsible) ---- */
.ra-section {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
}
.ra-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.ra-section-header:hover { background: #FAFBFC; }
.ra-section-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}
.ra-section-header .chevron {
  width: 18px; height: 18px;
  color: var(--text-muted);
  transition: transform 0.25s;
}
.ra-section.collapsed .chevron { transform: rotate(-90deg); }
.ra-section-body {
  padding: 0 24px 24px;
  transition: max-height 0.35s ease, opacity 0.25s ease;
  max-height: 4000px;
  opacity: 1;
  overflow: hidden;
}
.ra-section.collapsed .ra-section-body {
  max-height: 0;
  opacity: 0;
  padding: 0 24px;
}

/* ---- Fade-in animation ---- */
@keyframes ra-fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ra-animate { animation: ra-fadeInUp 0.35s ease both; }

/* ---- Toast ---- */
.ra-toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--text-primary);
  color: #fff;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  box-shadow: var(--shadow-lg);
  transform: translateY(60px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 5000;
}
.ra-toast.show { transform: translateY(0); opacity: 1; }

/* ---- Empty State ---- */
.ra-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .ra-page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .ra-metrics { grid-template-columns: 1fr; }
  .ra-grid-2, .ra-grid-3, .ra-grid-4 { grid-template-columns: 1fr; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ---- Footer ---- */
.ra-footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ==================================================================
   DARK MODE
   System default via prefers-color-scheme, manual via [data-theme]
   ================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --card: #1A1D26;
    --text-primary: #E5E7EB;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --border: #2A2D37;
    --border-light: #1F222B;
    --shadow: 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
    --green-bg: rgba(34,197,94,0.12);
    --amber-bg: rgba(245,158,11,0.12);
    --red-bg: rgba(239,68,68,0.12);
    --purple-bg: rgba(139,92,246,0.12);
  }
}
[data-theme="dark"] {
  --bg: #111318;
  --card: #1A1D26;
  --text-primary: #E5E7EB;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --border: #2A2D37;
  --border-light: #1F222B;
  --shadow: 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
  --green-bg: rgba(34,197,94,0.12);
  --amber-bg: rgba(245,158,11,0.12);
  --red-bg: rgba(239,68,68,0.12);
  --purple-bg: rgba(139,92,246,0.12);
}

/* Dark mode overrides for elements with hardcoded colors */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) table.ra-table thead th { background: #14171F; }
  :root:not([data-theme="light"]) table.ra-table tbody tr:hover td { background: #14171F; }
  :root:not([data-theme="light"]) .ra-section-header:hover { background: #14171F; }
  :root:not([data-theme="light"]) .ra-badge.delivered { background: rgba(34,197,94,0.15); color: #4ADE80; }
  :root:not([data-theme="light"]) .ra-badge.sent { background: rgba(4,90,255,0.15); color: #60A5FA; }
  :root:not([data-theme="light"]) .ra-badge.failed { background: rgba(239,68,68,0.15); color: #F87171; }
  :root:not([data-theme="light"]) .ra-badge.active { background: rgba(34,197,94,0.15); color: #4ADE80; }
  :root:not([data-theme="light"]) .ra-badge.canceled { background: rgba(239,68,68,0.15); color: #F87171; }
  :root:not([data-theme="light"]) .ra-badge.past-due { background: rgba(245,158,11,0.15); color: #FBBF24; }
  :root:not([data-theme="light"]) .ra-badge.new { background: rgba(4,90,255,0.15); color: #60A5FA; }
  :root:not([data-theme="light"]) .ra-btn-secondary { background: #2A2D37; }
  :root:not([data-theme="light"]) .ra-btn-secondary:hover { background: #353840; }
  :root:not([data-theme="light"]) .ra-pill { border-color: #2A2D37; }
  :root:not([data-theme="light"]) ::-webkit-scrollbar-thumb { background: #3A3D47; }
}
[data-theme="dark"] table.ra-table thead th { background: #14171F; }
[data-theme="dark"] table.ra-table tbody tr:hover td { background: #14171F; }
[data-theme="dark"] .ra-section-header:hover { background: #14171F; }
[data-theme="dark"] .ra-badge.delivered { background: rgba(34,197,94,0.15); color: #4ADE80; }
[data-theme="dark"] .ra-badge.sent { background: rgba(4,90,255,0.15); color: #60A5FA; }
[data-theme="dark"] .ra-badge.failed { background: rgba(239,68,68,0.15); color: #F87171; }
[data-theme="dark"] .ra-badge.active { background: rgba(34,197,94,0.15); color: #4ADE80; }
[data-theme="dark"] .ra-badge.canceled { background: rgba(239,68,68,0.15); color: #F87171; }
[data-theme="dark"] .ra-badge.past-due { background: rgba(245,158,11,0.15); color: #FBBF24; }
[data-theme="dark"] .ra-badge.new { background: rgba(4,90,255,0.15); color: #60A5FA; }
[data-theme="dark"] .ra-btn-secondary { background: #2A2D37; }
[data-theme="dark"] .ra-btn-secondary:hover { background: #353840; }
[data-theme="dark"] .ra-pill { border-color: #2A2D37; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #3A3D47; }

/* ── Reusable tooltips ────────────────────────────────────────────────
   Any element with a data-tip="..." attribute gets a hover explanation.
   Use the .tip-i info badge for inline "?" hints next to labels/headers. */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 9px); left: 50%; transform: translateX(-50%);
  background: #1A1B23; color: #fff; padding: 9px 11px; border-radius: 8px;
  font-size: 12px; font-weight: 400; line-height: 1.45; letter-spacing: normal;
  text-transform: none; white-space: normal; width: max-content; max-width: 260px;
  text-align: left; z-index: 5000; pointer-events: none;
  box-shadow: 0 8px 26px rgba(0,0,0,0.28);
}
[data-tip]:hover::before {
  content: ''; position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #1A1B23; z-index: 5000; pointer-events: none;
}
[data-tip-pos="below"]:hover::after { bottom: auto; top: calc(100% + 9px); }
[data-tip-pos="below"]:hover::before { bottom: auto; top: calc(100% + 3px); border-top-color: transparent; border-bottom-color: #1A1B23; }
.tip-i {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--text-muted); color: var(--text-muted);
  font-size: 9px; font-weight: 700; font-style: normal; font-family: inherit;
  margin-left: 5px; cursor: help; vertical-align: middle;
  text-transform: none; letter-spacing: normal; line-height: 1; flex: none;
}
.tip-i:hover { border-color: var(--accent); color: var(--accent); }
