/* =====================================================================
   Admin Analytics Dashboard - core stylesheet
   Palette: white (dominant bg), black/near-black (text), red (accent only)
   ===================================================================== */

:root {
  --color-white: #ffffff;
  --color-bg: #f7f7f8;
  --color-surface: #ffffff;
  --color-black: #14141a;
  --color-text: #1a1a1f;
  --color-text-muted: #6b6b76;
  --color-border: #e7e7ea;
  --color-border-strong: #d8d8de;
  --color-red: #e0202f;
  --color-red-dark: #b81624;
  --color-red-soft: #fdecee;
  --color-green: #16a34a;
  --color-green-soft: #eafaf0;
  --color-amber: #d97706;
  --color-amber-soft: #fef6e8;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 26, 0.05);
  --shadow-md: 0 4px 16px rgba(20, 20, 26, 0.07);
  --sidebar-width: 260px;
  --header-height: 64px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
img { max-width: 100%; }

/* ---------------------------------------------------------------------
   App shell
   --------------------------------------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-black);
  color: #f2f2f4;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .brand-mark {
  width: 30px; height: 30px;
  background: var(--color-red);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}
.brand-logo {
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-logo-lg {
    width: 220px;
    height: auto;
    object-fit: contain;
}

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.72);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-nav .nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav .nav-item.active {
  background: var(--color-red);
  color: #fff;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-footer .nav-item { color: rgba(255,255,255,0.6); }
.sidebar-footer .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

/* Main column */
.main-column {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top header */
.top-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
  gap: 16px;
}
.top-header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.top-header-titles h1 {
  font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em;
}
.top-header-titles .subtitle { font-size: 12.5px; color: var(--color-text-muted); }
.top-header-right { display: flex; align-items: center; gap: 10px; }

.hamburger-btn {
  display: none;
  background: none; border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--color-text);
}

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 35;
}
.sidebar-overlay.visible { display: block; }

.page-content {
  padding: 24px;
  flex: 1;
}

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--color-red); color: #fff; }
.btn-primary:hover { filter: brightness(0.92); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: #fafafa; }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-danger { background: var(--color-red-soft); color: var(--color-red-dark); }
.btn-danger:hover { filter: brightness(0.97); }

/* ---------------------------------------------------------------------
   Cards / KPIs
   --------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card { display: flex; flex-direction: column; gap: 6px; }
.kpi-label {
  font-size: 12.5px; font-weight: 600; color: var(--color-text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.kpi-value { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; }
.kpi-value.is-loading { color: var(--color-text-muted); }
.kpi-footnote { font-size: 12px; color: var(--color-text-muted); }
.kpi-change { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; }
.kpi-change.up { color: var(--color-green); }
.kpi-change.down { color: var(--color-red); }
.kpi-snapshot-tag {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--color-text-muted); background: var(--color-bg);
  border: 1px solid var(--color-border); border-radius: 5px; padding: 2px 6px; width: fit-content;
}
.kpi-sparkline { height: 32px; margin-top: 4px; }

.section-title {
  font-size: 15px; font-weight: 700; margin: 28px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.chart-card { min-height: 300px; display: flex; flex-direction: column; }
.chart-card h3 { font-size: 13.5px; font-weight: 700; margin: 0 0 12px; }
.chart-canvas-wrap { flex: 1; position: relative; min-height: 220px; }

/* ---------------------------------------------------------------------
   Empty / loading / error states
   --------------------------------------------------------------------- */
.empty-state, .error-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 40px 20px; text-align: center; color: var(--color-text-muted);
}
.empty-state .icon-circle, .error-state .icon-circle {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg); font-size: 20px; margin-bottom: 4px;
}
.error-state .icon-circle { background: var(--color-red-soft); color: var(--color-red); }
.empty-state h4, .error-state h4 { margin: 0; color: var(--color-text); font-size: 14px; }
.empty-state p, .error-state p { margin: 0; font-size: 13px; max-width: 320px; }

.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f4f4f4 37%, #eee 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: 6px;
}
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.skeleton-kpi-value { height: 26px; width: 70%; margin-bottom: 6px; }
.skeleton-kpi-label { height: 11px; width: 45%; margin-bottom: 10px; }
.skeleton-chart { height: 220px; width: 100%; }
.skeleton-row { height: 14px; width: 100%; margin-bottom: 8px; }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
table.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--color-text-muted); font-weight: 700; padding: 10px 12px;
  border-bottom: 1px solid var(--color-border); white-space: nowrap; cursor: pointer;
  user-select: none;
}
table.data-table th .sort-arrow { opacity: 0.4; margin-left: 3px; }
table.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
table.data-table tbody tr:hover { background: var(--color-bg); }

.table-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.table-pagination { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: var(--color-text-muted); }

/* ---------------------------------------------------------------------
   Badges / status pills
   --------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.badge-active, .badge-connected { background: var(--color-green-soft); color: var(--color-green); }
.badge-inactive { background: var(--color-bg); color: var(--color-text-muted); }
.badge-warning, .badge-demo { background: var(--color-amber-soft); color: var(--color-amber); }
.badge-danger { background: var(--color-red-soft); color: var(--color-red-dark); }
.badge-role { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border-strong); }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-input, .form-select {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong); font-size: 14px; background: #fff; color: var(--color-text);
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--color-red); box-shadow: 0 0 0 3px var(--color-red-soft); }
.form-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.form-error-text { font-size: 12.5px; color: var(--color-red); margin-top: 4px; }

/* ---------------------------------------------------------------------
   Date range control
   --------------------------------------------------------------------- */
.date-range-control { position: relative; }
.date-range-trigger {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  padding: 9px 12px; background: #fff; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.date-range-panel {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); z-index: 50; display: none; width: max-content; max-width: 92vw;
  overflow: hidden;
}
.date-range-panel.open { display: flex; }
.date-range-panel.wide { width: 640px; }
.date-range-presets {
  width: 190px; border-right: 1px solid var(--color-border); padding: 8px; flex-shrink: 0;
  max-height: 360px; overflow-y: auto;
}
.date-range-presets button {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: var(--radius-sm);
  border: none; background: none; font-size: 13.5px; cursor: pointer; color: var(--color-text);
}
.date-range-presets button:hover { background: var(--color-bg); }
.date-range-presets button.active { background: var(--color-red-soft); color: var(--color-red-dark); font-weight: 700; }
.date-range-custom { padding: 16px; flex: 1; }
.date-range-custom .form-group { margin-bottom: 12px; }
.date-range-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------------------------------------------------------------------
   Tabs / segmented control (Overview / Google Play / App Store)
   --------------------------------------------------------------------- */
.segmented-control {
  display: inline-flex; background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.segmented-control button {
  border: none; background: transparent; padding: 7px 16px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--color-text-muted); cursor: pointer;
}
.segmented-control button.active { background: #fff; color: var(--color-text); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------------
   Provider status strip
   --------------------------------------------------------------------- */
.provider-status-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.provider-status-pill {
  display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--color-border); background: #fff;
}
.provider-status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-green { background: var(--color-green); }
.dot-amber { background: var(--color-amber); }
.dot-red { background: var(--color-red); }

/* ---------------------------------------------------------------------
   Login page
   --------------------------------------------------------------------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--color-bg); padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 34px 30px; box-shadow: var(--shadow-md);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 22px;
    justify-content: center;
}
.login-brand .brand-mark {
  width: 34px; height: 34px; background: var(--color-red); border-radius: 9px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800;
}
.login-card h2 { font-size: 19px; margin: 0 0 4px; }
.login-card .subtitle { font-size: 13px; color: var(--color-text-muted); margin-bottom: 22px; }
.login-alert {
  background: var(--color-red-soft); color: var(--color-red-dark); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; margin-bottom: 16px; display: none;
}
.login-alert.visible { display: block; }
.login-submit { width: 100%; padding: 11px; margin-top: 6px; }
.login-demo-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 18px; text-align: center; }

/* ---------------------------------------------------------------------
   Modal (used by user management add/edit)
   --------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,20,26,0.45); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius-lg); width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; max-height: 60vh; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--color-text-muted); }

.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); min-width: 180px; z-index: 45; display: none; overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
  display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; padding: 10px 14px;
  border: none; background: none; font-size: 13.5px; cursor: pointer; color: var(--color-text);
}
.dropdown-menu button:hover { background: var(--color-bg); }
.dropdown-menu button.danger { color: var(--color-red); }
.dropdown-menu .divider { height: 1px; background: var(--color-border); margin: 4px 0; }

.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--color-black); color: #fff; padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; box-shadow: var(--shadow-md); min-width: 220px;
}
.toast.toast-error { background: var(--color-red-dark); }
.toast.toast-success { background: #14231a; }

.avatar-circle {
  width: 34px; height: 34px; border-radius: 50%; background: var(--color-black); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0;
}

.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-column { margin-left: 0; }
  .hamburger-btn { display: flex; }
}

@media (max-width: 640px) {
  .top-header { padding: 0 14px; }
  .top-header-titles h1 { font-size: 15px; }
  .page-content { padding: 14px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 21px; }
  .chart-grid { grid-template-columns: 1fr; }
  .date-range-panel { flex-direction: column; width: 300px; right: -14px; }
  .date-range-presets { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); max-height: 180px; }
  .top-header-right .btn span.btn-label { display: none; }
  .login-card { padding: 26px 20px; }
}

@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
