/* ============================================================
   LeafPulse — Base Stylesheet
   Extracted from base.html for modularity (UI-01)
   ============================================================ */

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

:root {
  --bg-primary:   #0d1117;
  --bg-surface:   #161b22;
  --bg-surface2:  #1c2128;
  --border:       #30363d;
  --accent-green: #2ea043;
  --accent-yellow:#d29922;
  --accent-red:   #f85149;
  --accent-blue:  #388bfd;
  --text-primary: #e6edf3;
  --text-muted:   #8b949e;
  --radius:       8px;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

/* ---- Flash messages ---- */
.flash-list { list-style: none; padding: 0; margin: 0; }
.flash { padding: 12px 18px; border-radius: var(--radius); margin-bottom: 8px;
         border-left: 4px solid; font-size: 13px; }
.flash.success { background: #1a2e1a; border-color: var(--accent-green); color: #6fd672; }
.flash.danger  { background: #2e1a1a; border-color: var(--accent-red);   color: #ff8080; }
.flash.warning { background: #2e2a1a; border-color: var(--accent-yellow); color: #e8c96d; }
.flash.info    { background: #1a222e; border-color: var(--accent-blue);  color: #80b4ff; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary  { background: var(--accent-green); color: #fff; border-color: var(--accent-green); }
.btn-danger   { background: var(--accent-red);   color: #fff; border-color: var(--accent-red); }
.btn-ghost    { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- Form fields ---- */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600;
        color: var(--text-muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; padding: 9px 12px;
  background: var(--bg-surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary); font-size: 14px;
}
input:focus { outline: none; border-color: var(--accent-blue); }
.field-error { color: var(--accent-red); font-size: 12px; margin-top: 4px; }

/* ---- Cards ---- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text-muted);
              text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px;
         font-size: 11px; font-weight: 600; }
.badge-green  { background: #1a2e1a; color: #6fd672; }
.badge-yellow { background: #2e2a1a; color: #e8c96d; }
.badge-red    { background: #2e1a1a; color: #ff8080; }
.badge-gray   { background: #21262d; color: var(--text-muted); }
.badge-blue   { background: #1a222e; color: #80b4ff; }

/* ---- App layout (sidebar + content) ---- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: width 0.2s ease, min-width 0.2s ease;
  z-index: 200;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  color: var(--accent-green);
  font-size: 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo svg {
  flex-shrink: 0;
}

.sidebar-location-switcher {
  padding: 8px 12px 12px;
}
.sidebar-location-switcher select {
  width: 100%; padding: 8px 10px;
  background: var(--bg-surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.sidebar-location-switcher select:focus {
  outline: none; border-color: var(--accent-green);
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 16px 4px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-primary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.sidebar-nav-item:hover {
  background: rgba(255,255,255,0.04);
  text-decoration: none;
  color: var(--text-primary);
}
.sidebar-nav-item.active {
  border-left-color: var(--accent-green);
  background: rgba(46,160,67,0.08);
  color: var(--accent-green);
}

.sidebar-icon {
  font-size: 15px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  margin-top: auto;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-locked {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.45;
  cursor: not-allowed;
  border-left: 3px solid transparent;
  user-select: none;
}
.sidebar-locked:hover { opacity: 0.55; }

.sidebar-logout {
  color: var(--text-muted);
  border-left-color: transparent;
  font-size: 13px;
  padding-bottom: 14px;
}

/* ---- Main content area ---- */
.main-content {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

/* ---- Content top bar (title + location dropdown) ---- */
.content-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.content-topbar h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.content-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.content-topbar select {
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}
.content-topbar .user-pill {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- Responsive base ---- */
.page-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px;
}

@media (max-width: 1024px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }
  .sidebar-logo-text,
  .sidebar-section-label,
  .sidebar-label {
    display: none;
  }
  .sidebar-logo {
    justify-content: center;
    padding: 18px 8px 14px;
  }
  .sidebar-nav-item {
    justify-content: center;
    padding: 12px 8px;
    gap: 0;
  }
  .sidebar-icon {
    width: auto;
  }
  .sidebar-user {
    justify-content: center;
    padding: 8px;
  }
  .sidebar-logout {
    justify-content: center;
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* ---- Shared Dashboard Components (DRY — defined once) ---- */

/* Filter bar */
.filter-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--bg-surface2);
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { margin: 0; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.filter-group select, .filter-group input[type=date] {
  padding: 5px 10px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary); font-size: 13px;
}
.filter-sep { color: var(--text-muted); font-size: 12px; }
.filter-presets { display: flex; gap: 4px; }
.filter-meta { font-size: 12px; color: var(--text-muted); margin-left: auto; }

/* KPI grid */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted);
             text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.kpi-green  { color: var(--accent-green); }
.kpi-red    { color: var(--accent-red); }
.kpi-yellow { color: var(--accent-yellow); }

/* Charts */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 20px; }
.chart-card { margin-bottom: 14px; }
.chart-wrap { position: relative; }

/* Data tables */
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* Section headings */
.section-heading {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; margin: 24px 0 12px;
}
.section-subtitle { font-size: 12px; color: var(--text-muted); font-weight: 400; }

/* Empty state */
.empty-state {
  text-align: center; padding: 60px 24px; color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.empty-message { font-size: 14px; }

/* KPI icon/body layout (used by kpi_card macro with icon/trend) */
.kpi-card .kpi-icon { font-size: 20px; margin-bottom: 6px; }
.kpi-card .kpi-body { flex: 1; }
.kpi-card .kpi-trend { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 768px) {
  .page-content { padding: 12px 8px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .charts-grid, .chart-grid { grid-template-columns: 1fr !important; }
  .card { padding: 14px; }
  .data-table-wrap { overflow-x: auto; }
  .data-table { min-width: 500px; }
  .filter-bar { flex-wrap: wrap; gap: 6px; }
  canvas { max-width: 100%; }
  .hide-mobile { display: none !important; }
  .kpi-value { font-size: 22px !important; }
  .content-topbar { padding: 12px 16px; }
  .content-topbar h1 { font-size: 14px; }
}

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