:root {
  --app-bg: #dfe5e7;
  --surface: #f3f4f6;
  --surface-alt: #eef2f7;
  --surface-card: rgba(255, 255, 255, 0.74);
  --surface-strong: #ffffff;
  --surface-muted: rgba(255, 255, 255, 0.75);
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.32);
  --sidebar-bg: #f5f7f8;
  --sidebar-text: #42536a;
  --sidebar-text-active: #1f2937;
  --primary: #2d78ff;
  --primary-strong: #2f5ef5;
  --primary-soft: rgba(45, 120, 255, 0.12);
  --success: #0f9f6e;
  --success-soft: rgba(15, 159, 110, 0.12);
  --warning: #ffb347;
  --danger: #e05252;
  --text-heading: #111827;
  --text-body: #1f2937;
  --text-muted: #536173;
  --text-light: #77859a;
  --shadow-soft: 0 14px 28px rgba(15, 23, 42, 0.06);
  --shadow-strong: 0 24px 65px rgba(15, 23, 42, 0.12);
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--app-bg);
  color: var(--text-body);
  margin: 0;
}

img { max-width: 100%; }

a { transition: all 0.2s ease; }

button, input, select {
  font: inherit;
}

/* ---------- Layout ---------- */
.app-layout { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 270px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 24px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: inset -1px 0 0 rgba(148, 163, 184, 0.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 22px;
  margin-bottom: 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #36c7ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: white;
  box-shadow: 0 12px 24px rgba(45, 120, 255, 0.2);
}

.brand-name {
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
  color: var(--text-heading);
}

.nav-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(83, 97, 115, 0.85);
  padding: 10px 12px 8px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 2px;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.side-link i {
  width: 18px;
  text-align: center;
}

.side-link:hover {
  background: rgba(45, 120, 255, 0.06);
  color: var(--sidebar-text-active);
  border-color: rgba(45, 120, 255, 0.08);
  transform: translateX(1px);
}

.side-link.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  box-shadow: 0 10px 22px rgba(45, 120, 255, 0.2);
}

.logout-form { margin-top: auto; }

.logout-btn {
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.18);
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #fecaca;
}

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-header {
  height: 78px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-title {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text-heading);
}

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

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #36c7ff);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(45, 120, 255, 0.2);
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-heading);
}

.user-role-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  padding: 5px 8px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.role-admin {
  background: rgba(45, 120, 255, 0.12);
  color: var(--primary-strong);
}

.role-viewer {
  background: rgba(15, 159, 110, 0.12);
  color: var(--success);
}

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

/* ---------- Form controls ---------- */
.form-label {
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.form-control,
.form-select {
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 12px;
  min-height: 42px;
  padding: 0.7rem 0.9rem;
  box-shadow: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(79, 70, 229, 0.5);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
  background: white;
}

.btn {
  border-radius: 12px;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  border: none;
  box-shadow: 0 10px 22px rgba(45, 120, 255, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
}

/* ---------- Cards ---------- */
.card-panel {
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 18px;
}

.kpi-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary), #36c7ff);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.kpi-sub {
  font-size: 0.7rem;
  color: var(--text-light);
  display: block;
  margin-top: 4px;
}

.kpi-value {
  font-size: clamp(1.7rem, 2vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-top: 8px;
  color: var(--text-heading);
}

.gradient-banner {
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #2d78ff 0%, #1f5bd9 32%, #2f5ef5 68%, #36c7ff 100%);
  color: white;
  padding: 18px 22px;
  font-weight: 700;
  font-size: 1.08rem;
  margin-bottom: 20px;
  box-shadow: 0 18px 28px rgba(45, 120, 255, 0.18);
}

.section-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.list-group { --bs-list-group-border-color: rgba(148, 163, 184, 0.14); }

.list-group-item {
  border-color: rgba(148,163,184,0.14) !important;
  font-size: 0.9rem;
  padding: 0.72rem 0.9rem;
  background: rgba(248,250,252,0.3);
}

.list-group-item .badge {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.4rem 0.6rem;
}

.last-updated-note {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Login ---------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--app-bg);
  padding: 30px;
}

.login-shell {
  width: min(1180px, 100%);
  min-height: 760px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: grid;
  grid-template-columns: 52% 48%;
  box-shadow: var(--shadow-strong);
  border: 1px solid var(--border);
}

.login-visual {
  background: rgba(232, 236, 239, 0.92);
  padding: 36px 42px 30px;
  position: relative;
}

.brand-inline {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 0.9rem;
  background: linear-gradient(135deg, var(--primary), #25c2ff);
  box-shadow: 0 0 0 3px rgba(45, 120, 255, 0.12);
}

.brand-stack {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-label {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-heading);
}

.brand-sub {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: #4f6b8a;
  text-transform: uppercase;
}

.analytics-preview {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 430px;
  margin: 0 auto;
}

.analytics-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-soft);
}

.ga-card {
  width: 100%;
}

.analytics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.analytics-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.platform-marker {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.platform-marker.google { background: linear-gradient(135deg, #4285F4, #34A853); }
.platform-marker.android { background: linear-gradient(135deg, #34C759, #1FBF73); }
.platform-marker.apple { background: linear-gradient(135deg, #111827, #4b5563); }

.platform-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.platform-copy strong {
  font-size: 0.9rem;
  color: var(--text-body);
}

.platform-copy small {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.analytics-kpi {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.analytics-kpi em {
  font-style: normal;
  color: var(--success);
  font-weight: 700;
}

.mini-chart {
  width: 100%;
  height: 92px;
  display: block;
}

.mini-chart path {
  fill: none;
  stroke: var(--primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-chart .chart-fill {
  fill: rgba(45, 120, 255, 0.12);
  stroke: none;
}

.bars-visual {
  display: flex;
  align-items: end;
  gap: 8px;
  height: 88px;
  padding-top: 6px;
}

.bars-visual span {
  flex: 1;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, rgba(45,120,255,0.9), rgba(96,165,250,0.4));
  min-height: 18px;
}

.ios-bars span {
  background: linear-gradient(180deg, rgba(17,24,39,0.98), rgba(75,85,99,0.7));
}

.login-panel {
  background: var(--surface);
  padding: 54px 72px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.panel-header-wrap {
  margin-bottom: 20px;
}

.analytics-brand-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 22px;
}

.mini-brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  background: white;
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: var(--primary-strong);
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.06);
}

.mini-brand-icon.android { color: #2bb673; }
.mini-brand-icon.apple { color: #111827; }

.panel-title {
  font-size: clamp(2rem, 2.6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.06em;
  color: var(--text-heading);
  margin: 0 0 12px;
}

.panel-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.login-form {
  margin-top: 28px;
}

.field-wrap {
  display: flex;
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px 0 16px;
  margin-bottom: 18px;
  height: 58px;
}

.field-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 1.05rem;
}

.field-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-body);
  font-size: 1rem;
  padding: 0 12px;
  outline: none;
}

.field-wrap input::placeholder {
  color: var(--text-light);
}

.end-icon {
  color: var(--text-light);
  font-size: 0.9rem;
}

.password-toggle {
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: rgba(45, 120, 255, 0.08);
  color: var(--primary-strong);
  outline: none;
}

.form-action-row {
  margin-top: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  border: none;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 22px rgba(45, 120, 255, 0.22);
  font-size: 1.05rem;
}

.password-link {
  margin-top: 18px;
  text-align: right;
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 0.92rem;
}

@media (max-width: 980px) {
  .login-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .login-visual {
    padding-bottom: 20px;
  }

  .analytics-preview {
    max-width: 100%;
  }

  .login-panel {
    padding: 32px 22px 36px;
  }
}

@media (max-width: 560px) {
  .login-wrapper {
    padding: 18px;
  }

  .brand-inline {
    margin-bottom: 18px;
  }

  .analytics-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Misc ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.table-compact td,
.table-compact th {
  padding: 0.7rem 0.8rem;
  font-size: 0.88rem;
  vertical-align: middle;
}

.table-compact thead th {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid rgba(148,163,184,0.22) !important;
}

.badge-status-active {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.badge-status-inactive {
  background: rgba(239, 68, 68, 0.08);
  color: #b91c1c;
}

.modal-content {
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
}

.modal-header,
.modal-footer {
  border-color: rgba(148,163,184,0.18);
}

@media (max-width: 991px) {
  .app-layout {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding-bottom: 12px;
  }

  .app-header {
    padding-inline: 18px;
  }

  .page-content {
    padding: 18px;
  }
}

@media (max-width: 575px) {
  .app-header {
    height: auto;
    padding: 16px 18px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .header-user {
    width: 100%;
    justify-content: space-between;
  }

  .login-card {
    padding: 24px 18px;
  }
}
