/* ═══════════════════════════════════════════════════════════
   mPower Web App Template — Standard Design System
   Light + Dark theme. Base for all mPower Analytics apps.
   Import this CSS + app.js = branded, themed, ready.
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design Tokens: Light (default) ── */
:root, [data-theme="light"] {
  /* Surfaces */
  --bg-page: #f0f4f8;
  --bg-card: #ffffff;
  --bg-sidebar: #f8fafc;
  --bg-sidebar-hover: #f1f5f9;
  --bg-header: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* Blue accent */
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --accent-muted: #dbeafe;
  --accent-subtle: rgba(37, 99, 235, 0.08);

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* Grid overlay */
  --grid-color: #e2e8f0;
  --grid-opacity: 0.4;

  /* Badges */
  --badge-live-bg: #dcfce7;
  --badge-live-text: #166534;
  --badge-coming-bg: #dbeafe;
  --badge-coming-text: #2563eb;
}

/* ── Design Tokens: Dark (ThomOS-style) ── */
[data-theme="dark"] {
  /* Surfaces */
  --bg-page: #0a0a0f;
  --bg-card: #12121a;
  --bg-sidebar: #0f0f17;
  --bg-sidebar-hover: #1a1a26;
  --bg-header: #0f0f17;
  --border: #1e1e2a;
  --border-light: #16161f;

  /* Blue accent — slightly lighter for dark bg */
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-muted: rgba(59, 130, 246, 0.15);
  --accent-subtle: rgba(59, 130, 246, 0.08);

  /* Text */
  --text-primary: #f0f0f5;
  --text-secondary: #9498a8;
  --text-muted: #5c6078;
  --text-inverse: #0a0a0f;

  /* Grid overlay */
  --grid-color: rgba(255, 255, 255, 0.03);
  --grid-opacity: 1;

  /* Badges */
  --badge-live-bg: rgba(34, 197, 94, 0.15);
  --badge-live-text: #4ade80;
  --badge-coming-bg: rgba(59, 130, 246, 0.15);
  --badge-coming-text: #60a5fa;
}

/* ── Shared Layout Tokens (theme-independent) ── */
:root {
  /* Sidebar */
  --sidebar-width: 256px;
  --sidebar-collapsed: 64px;
  --sidebar-active-border: 3px solid var(--accent);
  --sidebar-active-bg: var(--accent-subtle);

  /* Header */
  --header-height: 56px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 20px;

  /* Font */
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Smooth theme transitions on key elements */
.sidebar, .topnav, .card, .tool-card, .input, .btn-secondary {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.theme-toggle:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  width: 18px;
  height: 18px;
}

[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: inline; }
:root .theme-toggle .icon-sun { display: none; }
:root .theme-toggle .icon-moon { display: inline; }

/* ── Grid Background Texture ── */
.grid-bg {
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  opacity: var(--grid-opacity);
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ── Top Navigation ── */
.topnav {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
}

.topnav-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.topnav-brand {
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}

.brand-mpower {
  color: var(--accent);
}

.brand-analytics {
  color: var(--text-primary);
  font-weight: 500;
}

.topnav-center {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.topnav-link {
  padding: 6px var(--space-lg);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}

.topnav-link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.topnav-link.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.topnav-env {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Layout Shell ── */
.app {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-height);
  position: relative;
  z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  z-index: 10;
  transition: width 0.2s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

/* sidebar-header removed — brand is in topnav */

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
}

.nav-section {
  margin-bottom: var(--space-lg);
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-sm) var(--space-sm) var(--space-xs);
}

.sidebar.collapsed .nav-section-label {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--accent);
  border-left-color: var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar.collapsed .nav-item span {
  display: none;
}

/* Nested nav items */
.nav-children {
  margin-left: 32px;
  display: none;
}

.nav-children.open {
  display: block;
}

.nav-children .nav-item {
  font-size: 13px;
  padding: 6px var(--space-md);
}

.nav-toggle {
  margin-left: auto;
  transition: transform 0.2s;
}

.nav-toggle.open {
  transform: rotate(90deg);
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer p {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.sidebar-footer .brand {
  color: var(--accent);
  font-weight: 600;
}

/* ── Main Content ── */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.2s ease;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar.collapsed ~ .main {
  margin-left: var(--sidebar-collapsed);
}

/* ── Header ── */
.header {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.collapse-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.collapse-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

/* ── Content Area ── */
.content {
  flex: 1;
  padding: var(--space-xl);
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
}

/* Tool cards — clickable */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}

.tool-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.tool-card-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-muted);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
  color: var(--accent);
}

.tool-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.tool-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.tool-card-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-top: var(--space-md);
}

.badge-live {
  background: var(--badge-live-bg);
  color: var(--badge-live-text);
}

.badge-coming {
  background: var(--badge-coming-bg);
  color: var(--badge-coming-text);
}

/* ── Forms ── */
.input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color 0.15s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

/* ── Tables ── */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
}

td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
}

tr:hover {
  background: var(--accent-subtle);
}

/* ── Account Menu ── */
.account-menu {
  position: relative;
}

.account-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: box-shadow 0.15s;
}

.account-btn:hover {
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.account-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: 600;
  background-size: cover;
  background-position: center;
}

.account-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 30;
  overflow: hidden;
}

.account-dropdown.open {
  display: block;
}

.account-info {
  padding: var(--space-lg);
}

.account-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.account-email {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.account-divider {
  height: 1px;
  background: var(--border);
}

.account-option {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.account-option:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

/* ── Responsive — disabled until layout is stable ── */
