/*
 * Identidad visual de Beehive.
 *
 * - Oscuro es el modo principal (templates/base.html lo aplica antes de pintar);
 *   el claro es opcional. Cada modo tiene sus propios valores: no es un flip.
 * - Tokens --bh-*. Tambien se pisan los --cf-* de la plantilla para que login,
 *   callback y los componentes heredados usen la misma paleta. Los selectores
 *   llevan :root.dark / :root:not(.dark) para ganarle a la marca de la empresa
 *   (app/brand.py), que se inyecta antes.
 * - El amarillo miel es acento: acciones, seleccion y la serie de los graficos.
 *   El texto nunca va en amarillo sobre claro (no contrasta).
 */

:root.dark {
  --bh-bg: #16191F;
  --bh-surface: #222730;
  --bh-surface-2: #2A303B;
  --bh-border: #343A46;
  --bh-text: #E8EAED;
  --bh-text-2: #A4ADBB;
  --bh-text-3: #7A8494;
  --bh-accent: #FFCA28;
  --bh-accent-hover: #F5A623;
  --bh-accent-ink: #FFCA28;          /* acento usado como texto o linea */
  --bh-on-accent: #16191F;
  --bh-accent-wash: rgba(255, 202, 40, 0.12);
  --bh-success: #75D8AB;
  --bh-error: #F87171;
  --bh-error-wash: rgba(248, 113, 113, 0.12);
  --bh-series: #FFCA28;              /* serie del grafico (validada vs. superficie) */
  --bh-series-muted: #8B93A1;        /* periodo anterior */
  --bh-grid: #2E3440;
  --bh-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root:not(.dark) {
  --bh-bg: #F6F7F9;
  --bh-surface: #FFFFFF;
  --bh-surface-2: #F1F3F6;
  --bh-border: #E1E5EB;
  --bh-text: #16191F;
  --bh-text-2: #566070;
  --bh-text-3: #7C8696;
  --bh-accent: #FFCA28;
  --bh-accent-hover: #F5A623;
  --bh-accent-ink: #8A5A00;
  --bh-on-accent: #16191F;
  --bh-accent-wash: rgba(245, 166, 35, 0.16);
  --bh-success: #1B7F52;
  --bh-error: #C53030;
  --bh-error-wash: rgba(197, 48, 48, 0.08);
  --bh-series: #B7791F;
  --bh-series-muted: #8792A2;
  --bh-grid: #E9ECF1;
  --bh-shadow: 0 8px 24px rgba(22, 25, 31, 0.10);
  color-scheme: light;
}

/* Tokens de la plantilla, alineados a Beehive. */
:root.dark, :root:not(.dark) {
  --cf-green: var(--bh-accent);
  --cf-green-hover: var(--bh-accent-hover);
  --cf-green-text: var(--bh-accent-ink);
  --cf-green-light: var(--bh-accent-wash);
  --cf-bg-white: var(--bh-surface);
  --cf-bg-gray: var(--bh-bg);
  --cf-text-primary: var(--bh-text);
  --cf-text-secondary: var(--bh-text-2);
  --cf-border: var(--bh-border);
  --cf-blue: var(--bh-accent-ink);
  --cf-error: var(--bh-error);
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bh-bg);
  color: var(--bh-text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.cf-btn-green { color: var(--bh-on-accent) !important; }

.bh-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.bh-hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--bh-accent-ink); outline-offset: 2px; border-radius: 6px; }

/* ---------- Estructura ---------- */

.bh-header {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 50;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bh-surface); border-bottom: 1px solid var(--bh-border);
}
.bh-brand { display: flex; align-items: center; gap: 10px; color: var(--bh-text); text-decoration: none; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.bh-brand img { width: 28px; height: 28px; display: block; }
.bh-header-sep { width: 1px; height: 24px; background: var(--bh-border); }
.bh-header-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bh-header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.bh-hub-link { color: var(--bh-text-2); text-decoration: none; font-size: 13px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; }
.bh-hub-link:hover { color: var(--bh-text); background: var(--bh-surface-2); }

.bh-sidebar {
  position: fixed; top: 56px; bottom: 0; left: 0; width: 224px; z-index: 40;
  padding: 16px 12px; overflow-y: auto;
  background: var(--bh-bg); border-right: 1px solid var(--bh-border);
  transition: transform 0.18s ease;
}
.bh-nav { display: flex; flex-direction: column; gap: 2px; }
.bh-nav-label { margin: 18px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--bh-text-3); }
.bh-nav-item {
  display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px;
  border-radius: 8px; color: var(--bh-text-2); text-decoration: none; font-weight: 500;
  border-left: 2px solid transparent; transition: background 0.12s, color 0.12s;
}
.bh-nav-item svg { flex: none; }
a.bh-nav-item:hover { background: var(--bh-surface); color: var(--bh-text); }
.bh-nav-item[aria-current="page"] { background: var(--bh-accent-wash); color: var(--bh-text); border-left-color: var(--bh-accent); }
.bh-nav-item[aria-current="page"] svg { color: var(--bh-accent-ink); }
.bh-nav-item.is-planned { color: var(--bh-text-3); cursor: default; }
.bh-tag {
  margin-left: auto; font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 6px; border-radius: 999px; color: var(--bh-text-3); border: 1px solid var(--bh-border);
}
.bh-tagline { margin: 24px 12px 0; font-size: 12px; color: var(--bh-text-3); }

.bh-main { margin-left: 224px; padding: 80px 28px 56px; min-height: 100vh; box-sizing: border-box; }
.bh-page { max-width: 1280px; margin: 0 auto; }
.bh-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.bh-page-head h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.015em; }
.bh-page-head p { margin: 4px 0 0; color: var(--bh-text-2); }
.bh-scope { color: var(--bh-text-3); font-size: 12px; margin-top: 2px; }

.bh-btn.bh-menu-btn { display: none; }
.bh-overlay { position: fixed; inset: 56px 0 0 0; z-index: 39; background: rgba(0, 0, 0, 0.45); }

@media (max-width: 900px) {
  .bh-sidebar { transform: translateX(-100%); background: var(--bh-surface); }
  .bh-sidebar.is-open { transform: translateX(0); }
  .bh-main { margin-left: 0; padding: 72px 16px 40px; }
  .bh-btn.bh-menu-btn { display: inline-flex; }
  .bh-hub-link, .bh-header-sep.bh-optional, .bh-user-name, .bh-brand span { display: none; }
  .bh-header { gap: 8px; padding: 0 12px; }
  /* Proyecto y ambiente bajan a su propia fila bajo el header. */
  .bh-header-controls:not([hidden]) {
    position: fixed; top: 56px; left: 0; right: 0; height: 52px; padding: 0 12px; box-sizing: border-box;
    background: var(--bh-surface); border-bottom: 1px solid var(--bh-border);
  }
  .bh-header-controls .bh-select { flex: 1 1 0; max-width: none; min-width: 0; }
  .bh-header:has(.bh-header-controls:not([hidden])) ~ .bh-main { padding-top: 124px; }
  .bh-header:has(.bh-header-controls:not([hidden])) ~ .bh-sidebar,
  .bh-header:has(.bh-header-controls:not([hidden])) ~ .bh-overlay { top: 108px; }
  .bh-drawer { top: 0; z-index: 70; }
  .bh-pop-panel { max-width: calc(100vw - 24px); }
}

/* ---------- Controles ---------- */

.bh-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--bh-border);
  background: var(--bh-surface); color: var(--bh-text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.bh-btn:hover { background: var(--bh-surface-2); }
.bh-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.bh-btn-primary { background: var(--bh-accent); border-color: var(--bh-accent); color: var(--bh-on-accent); font-weight: 600; }
.bh-btn-primary:hover { background: var(--bh-accent-hover); border-color: var(--bh-accent-hover); }
.bh-btn-danger { color: var(--bh-error); }
.bh-btn-danger:hover { background: var(--bh-error-wash); border-color: var(--bh-error); }
.bh-btn-ghost { border-color: transparent; background: transparent; color: var(--bh-text-2); }
.bh-btn-ghost:hover { color: var(--bh-text); background: var(--bh-surface-2); }
.bh-btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.bh-icon-btn { width: 36px; padding: 0; }

.bh-input, .bh-select {
  height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--bh-border);
  background: var(--bh-surface); color: var(--bh-text); font: inherit; min-width: 0; box-sizing: border-box;
}
.bh-input::placeholder { color: var(--bh-text-3); }
.bh-input:hover, .bh-select:hover { border-color: var(--bh-text-3); }
.bh-select { padding-right: 28px; cursor: pointer; max-width: 220px; }
.bh-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bh-field > span { font-size: 12px; font-weight: 500; color: var(--bh-text-2); }
.bh-field small { color: var(--bh-text-3); }
.bh-form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.bh-form-row .bh-field { flex: 1 1 180px; }

.bh-seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--bh-surface-2); border: 1px solid var(--bh-border); }
.bh-seg button { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--bh-text-2); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.bh-seg button[aria-pressed="true"] { background: var(--bh-surface); color: var(--bh-text); box-shadow: 0 0 0 1px var(--bh-border); }

.bh-pop { position: relative; }
.bh-pop-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; min-width: 260px;
  padding: 8px; border-radius: 12px; background: var(--bh-surface); border: 1px solid var(--bh-border); box-shadow: var(--bh-shadow);
}
.bh-pop-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--bh-text); font: inherit; text-align: left; cursor: pointer; text-decoration: none; box-sizing: border-box;
}
.bh-pop-row:hover { background: var(--bh-surface-2); }
.bh-pop-row[aria-checked="true"] { font-weight: 600; }
.bh-pop-row .bh-check { color: var(--bh-accent-ink); font-weight: 700; visibility: hidden; }
.bh-pop-row[aria-checked="true"] .bh-check { visibility: visible; }
.bh-pop-sep { height: 1px; margin: 8px 2px; background: var(--bh-border); }
.bh-pop-foot { padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 10px; }
.bh-pop-note { padding: 6px 10px; color: var(--bh-text-3); font-size: 12px; }

.bh-avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--bh-accent-wash); color: var(--bh-accent-ink); font-size: 12px; font-weight: 700; }
.bh-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tarjetas ---------- */

.bh-card { background: var(--bh-surface); border: 1px solid var(--bh-border); border-radius: 12px; padding: 20px; min-width: 0; }
.bh-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bh-card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.bh-card-head p { margin: 2px 0 0; color: var(--bh-text-2); font-size: 13px; }
.bh-card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bh-grid { display: grid; gap: 16px; }
.bh-grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bh-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.bh-stack { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1100px) { .bh-grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .bh-grid-kpi, .bh-grid-2 { grid-template-columns: minmax(0, 1fr); } }
.is-refreshing { opacity: 0.55; transition: opacity 0.15s; }

/* KPI */
.bh-kpi { display: flex; flex-direction: column; gap: 6px; }
.bh-kpi-label { color: var(--bh-text-2); font-size: 13px; font-weight: 500; }
.bh-kpi-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; min-height: 34px; }
.bh-kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; white-space: nowrap; }
.bh-kpi-foot { display: flex; align-items: center; gap: 8px; min-height: 20px; flex-wrap: wrap; }
.bh-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--bh-text-2); white-space: nowrap; }
.bh-delta.is-up { color: var(--bh-success); }
.bh-delta.is-down { color: var(--bh-error); }
.bh-delta-note { color: var(--bh-text-3); font-size: 12px; font-weight: 400; }
.bh-spark { width: 96px; height: 28px; flex: 0 1 96px; min-width: 0; overflow: visible; }

/* Grafico */
.bh-chart { position: relative; height: 300px; }
.bh-legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--bh-text-2); font-size: 12px; }
.bh-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bh-key { width: 16px; height: 0; border-top: 2px solid var(--bh-series); }
.bh-key.is-prev { border-top: 2px dashed var(--bh-series-muted); }
.bh-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px; padding: 10px 12px; border-radius: 10px;
  background: var(--bh-surface-2); border: 1px solid var(--bh-border); box-shadow: var(--bh-shadow); font-size: 12px;
  transition: opacity 0.1s;
}
.bh-tip-title { color: var(--bh-text-2); margin-bottom: 6px; }
.bh-tip-row { display: flex; align-items: center; gap: 8px; }
.bh-tip-row strong { font-size: 14px; font-weight: 600; margin-right: auto; font-variant-numeric: tabular-nums; }
.bh-tip-row span { color: var(--bh-text-2); }

/* Barras de distribucion */
.bh-bars { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.bh-bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.bh-bar-top span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bh-bar-top span:last-child { color: var(--bh-text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bh-bar-track { height: 8px; margin-top: 6px; border-radius: 4px; background: var(--bh-surface-2); overflow: hidden; }
.bh-bar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--bh-series); min-width: 2px; }

/* ---------- Tablas ---------- */

.bh-table-wrap { overflow-x: auto; margin: 0 -20px -20px; border-top: 1px solid var(--bh-border); }
.bh-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bh-table th { text-align: left; padding: 10px 20px; font-size: 12px; font-weight: 500; color: var(--bh-text-2); white-space: nowrap; border-bottom: 1px solid var(--bh-border); }
.bh-table td { padding: 12px 20px; border-bottom: 1px solid var(--bh-border); vertical-align: middle; }
.bh-table tr:last-child td { border-bottom: 0; }
.bh-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.bh-table tbody tr.is-clickable { cursor: pointer; }
.bh-table tbody tr.is-clickable:hover, .bh-table tbody tr.is-clickable:focus-visible { background: var(--bh-surface-2); }
.bh-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.bh-muted { color: var(--bh-text-2); }
.bh-dim { color: var(--bh-text-3); }
.bh-truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bh-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--bh-surface-2); border: 1px solid var(--bh-border); color: var(--bh-text-2); white-space: nowrap; }
.bh-pill.is-accent { background: var(--bh-accent-wash); border-color: transparent; color: var(--bh-accent-ink); }
.bh-pill.is-error { background: var(--bh-error-wash); border-color: transparent; color: var(--bh-error); }

/* ---------- Estados ---------- */

.bh-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 20px; }
.bh-empty img { width: 104px; height: auto; margin-bottom: 4px; }
.bh-empty h3 { margin: 0; font-size: 16px; font-weight: 600; }
.bh-empty p { margin: 0 0 8px; max-width: 440px; color: var(--bh-text-2); }
.bh-empty.is-compact { padding: 20px; }
.bh-empty.is-compact img { width: 64px; }

.bh-skel { border-radius: 8px; background: linear-gradient(90deg, var(--bh-surface-2) 25%, var(--bh-border) 37%, var(--bh-surface-2) 63%); background-size: 400% 100%; animation: bh-shimmer 1.4s ease infinite; }
@keyframes bh-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.bh-toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.bh-toast { padding: 12px 14px; border-radius: 10px; background: var(--bh-surface-2); border: 1px solid var(--bh-border); box-shadow: var(--bh-shadow); max-width: 360px; }
.bh-toast.is-error { border-color: var(--bh-error); }

.bh-callout { padding: 14px 16px; border-radius: 10px; border: 1px solid var(--bh-border); background: var(--bh-surface-2); }
.bh-callout.is-accent { border-color: var(--bh-accent); background: var(--bh-accent-wash); }
.bh-callout.is-error { border-color: var(--bh-error); background: var(--bh-error-wash); }

/* ---------- Panel de detalle ---------- */

.bh-drawer {
  position: fixed; top: 56px; right: 0; bottom: 0; z-index: 45; width: min(520px, 100vw);
  background: var(--bh-surface); border-left: 1px solid var(--bh-border); box-shadow: var(--bh-shadow);
  display: flex; flex-direction: column; transform: translateX(100%);
  /* Cerrado queda oculto de verdad: fuera del orden de tabulacion y sin sombra asomando. */
  visibility: hidden; transition: transform 0.18s ease, visibility 0s linear 0.18s;
}
.bh-drawer.is-open { transform: translateX(0); visibility: visible; transition: transform 0.18s ease, visibility 0s; }
.bh-drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--bh-border); }
.bh-drawer-head h2 { margin: 0; font-size: 16px; font-weight: 600; word-break: break-word; }
.bh-drawer-body { padding: 18px 20px 28px; overflow-y: auto; }
.bh-dl { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 10px 12px; margin: 0 0 20px; }
.bh-dl dt { color: var(--bh-text-2); }
.bh-dl dd { margin: 0; word-break: break-word; }

.bh-json { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.7; }
.bh-json details { margin-left: 14px; }
.bh-json summary { cursor: pointer; margin-left: -14px; color: var(--bh-text-2); }
.bh-json .bh-json-row { margin-left: 14px; word-break: break-word; }
.bh-json .k { color: var(--bh-accent-ink); }
.bh-json .s { color: var(--bh-text); }
.bh-json .n { color: var(--bh-success); }
.bh-json .z { color: var(--bh-text-3); }

.bh-code { position: relative; margin: 0; padding: 14px 16px; border-radius: 10px; background: var(--bh-bg); border: 1px solid var(--bh-border); overflow-x: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.6; white-space: pre; }
.bh-code-wrap { position: relative; }
.bh-code-wrap .bh-btn { position: absolute; top: 8px; right: 8px; }

.bh-list { display: flex; flex-direction: column; gap: 8px; }
.bh-list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--bh-border); background: var(--bh-surface); color: var(--bh-text); font: inherit; text-align: left; cursor: pointer; box-sizing: border-box; }
.bh-list-item:hover { border-color: var(--bh-text-3); }
.bh-list-item[aria-current="true"] { border-color: var(--bh-accent); background: var(--bh-accent-wash); }
.bh-split { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .bh-split { grid-template-columns: minmax(0, 1fr); } }
.bh-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.bh-stat { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--bh-border); }
.bh-stat b { display: block; font-size: 20px; font-weight: 600; }
.bh-stat span { color: var(--bh-text-2); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
