/* ============================================================
   GELB NEXUS — HEALTH DASHBOARD
   Design: dark industrial, OLED-ready, TV-optimized
   ============================================================ */

:root {
  /* Status colors */
  --c-green:  #00ff88;
  --c-yellow: #ffcc00;
  --c-red:    #ff3355;
  --c-blue:   #45d6ff;
  --c-grey:   #556677;
  --c-violet: #9b59ff;

  /* Backgrounds */
  --bg:       #060810;
  --bg-1:     #0a0e1a;
  --bg-2:     #0f1624;
  --bg-card:  rgba(15,22,40,.92);
  --bg-glass: rgba(255,255,255,.03);

  /* Text */
  --txt:      #ffffff;
  --txt-2:    rgba(255,255,255,.75);
  --txt-m:    rgba(255,255,255,.45);
  --txt-3:    rgba(255,255,255,.25);

  /* Borders */
  --border:   rgba(255,255,255,.07);
  --border-2: rgba(255,255,255,.12);

  /* Accents */
  --acc:      #45d6ff;
  --acc-glow: rgba(69,214,255,.15);

  /* Shadows */
  --sha:      0 2px 12px rgba(0,0,0,.5);
  --sha-lg:   0 8px 40px rgba(0,0,0,.6);

  /* Fonts */
  --font:     'Syne', 'Space Grotesk', system-ui, sans-serif;
  --mono:     'Space Mono', 'Fira Code', monospace;
}

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

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Noise texture overlay ─────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: .5;
}

/* ── TV MODE ───────────────────────────────────────────── */
body.tv-mode {
  background: #000;
  overflow: hidden;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.tv-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tv-logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--acc), var(--c-violet));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -.5px;
  color: #000;
}

.tv-logo-text h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .04em;
}

.tv-logo-text p {
  font-size: 10px;
  color: var(--txt-m);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tv-status-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 12px;
}

.tv-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tv-kpi-val {
  font-size: 20px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
}

.tv-kpi-lbl {
  font-size: 9px;
  color: var(--txt-m);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.tv-kpi-val.green  { color: var(--c-green); }
.tv-kpi-val.red    { color: var(--c-red); }
.tv-kpi-val.yellow { color: var(--c-yellow); }
.tv-kpi-val.blue   { color: var(--acc); }

.tv-clock {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--acc);
  letter-spacing: .05em;
}

.tv-date {
  font-size: 10px;
  color: var(--txt-m);
  text-align: right;
  letter-spacing: .05em;
}

/* ── TV BLANK STATE ────────────────────────────────────── */
#tvBlankState {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 73px);
  gap: 20px;
}

#tvBlankState.visible {
  display: flex;
}

.blank-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(0,255,136,.1);
  border: 2px solid rgba(0,255,136,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%,100% { transform: scale(1); opacity: .7; }
  50% { transform: scale(1.05); opacity: 1; }
}

#tvBlankState h2 {
  font-size: 28px;
  font-weight: 800;
  color: var(--c-green);
  letter-spacing: -.02em;
}

#tvBlankState p {
  color: var(--txt-m);
  font-size: 14px;
}

/* ── CARDS GRID ────────────────────────────────────────── */
.health-main {
  padding: 24px 28px;
  position: relative;
  z-index: 1;
}

.polo-section {
  margin-bottom: 32px;
}

.polo-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.polo-label h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--acc);
}

.polo-stats {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--txt-m);
}

.polo-stat span { color: var(--txt-2); font-weight: 600; }

.pdv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

/* TV mode: larger cards */
body.tv-mode .pdv-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

body.tv-mode .health-main {
  padding: 20px 32px;
}

/* ── PDV CARD ──────────────────────────────────────────── */
.pdv-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.pdv-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 16px 16px 0 0;
  background: var(--card-accent, transparent);
  transition: .2s;
}

.pdv-card:hover {
  border-color: rgba(255,255,255,.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

/* Status variants */
.pdv-card.green  { --card-accent: var(--c-green);  border-color: rgba(0,255,136,.15); }
.pdv-card.red    { --card-accent: var(--c-red);    border-color: rgba(255,51,85,.25);  background: rgba(255,51,85,.06); }
.pdv-card.yellow { --card-accent: var(--c-yellow); border-color: rgba(255,204,0,.2);   background: rgba(255,204,0,.04); }
.pdv-card.blue   { --card-accent: var(--acc);      border-color: rgba(69,214,255,.2); }
.pdv-card.grey   { --card-accent: var(--c-grey);   border-color: rgba(85,102,119,.3);  background: rgba(85,102,119,.05); }

/* ── CRITICAL ALERT PULSE ──────────────────────────────── */
.pdv-card.critical {
  animation: card-pulse 1.5s ease-in-out infinite;
  border-color: var(--c-red) !important;
  box-shadow: 0 0 0 1px var(--c-red), 0 0 30px rgba(255,51,85,.3);
}

@keyframes card-pulse {
  0%,100% { box-shadow: 0 0 0 1px var(--c-red), 0 0 20px rgba(255,51,85,.2); }
  50% { box-shadow: 0 0 0 2px var(--c-red), 0 0 40px rgba(255,51,85,.5); }
}

.pdv-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.pdv-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.pdv-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}

.green  .pdv-status-dot { background: var(--c-green); box-shadow: 0 0 8px var(--c-green); }
.red    .pdv-status-dot { background: var(--c-red); box-shadow: 0 0 8px var(--c-red); animation: dot-blink 1s infinite; }
.yellow .pdv-status-dot { background: var(--c-yellow); }
.blue   .pdv-status-dot { background: var(--acc); }
.grey   .pdv-status-dot { background: var(--c-grey); }

@keyframes dot-blink { 0%,100%{opacity:1} 50%{opacity:.2} }

.pdv-meta {
  font-size: 10px;
  color: var(--txt-m);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pdv-meta .tag {
  background: rgba(255,255,255,.06);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 9px;
  letter-spacing: .04em;
}

/* ── METRICS ROW ───────────────────────────────────────── */
.pdv-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.pdv-metric {
  background: rgba(255,255,255,.03);
  border-radius: 8px;
  padding: 7px 8px;
  text-align: center;
}

.pdv-metric-val {
  font-size: 15px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 2px;
}

.pdv-metric-lbl {
  font-size: 8px;
  color: var(--txt-m);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── HEALTH BAR ────────────────────────────────────────── */
.pdv-health-bar {
  height: 4px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.pdv-health-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s ease;
}

.pdv-health-pct {
  font-size: 10px;
  color: var(--txt-m);
  display: flex;
  justify-content: space-between;
}

/* ── ALERT BADGE ───────────────────────────────────────── */
.pdv-alert-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(255,51,85,.08);
  border: 1px solid rgba(255,51,85,.2);
  border-radius: 8px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--c-red);
}

.pdv-last-comm {
  font-size: 9px;
  color: var(--txt-3);
  font-family: var(--mono);
  text-align: right;
}

/* ── MODAL DETAIL ──────────────────────────────────────── */
.health-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  backdrop-filter: blur(8px);
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.health-modal-overlay.open { display: flex; }

.health-modal {
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 24px;
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 40px 100px rgba(0,0,0,.7);
}

.hm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hm-title { font-size: 18px; font-weight: 800; }
.hm-subtitle { font-size: 12px; color: var(--txt-m); margin-top: 2px; }

.hm-close {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,.06);
  color: var(--txt-2);
  cursor: pointer;
  font-size: 16px;
  transition: .15s;
}
.hm-close:hover { background: rgba(255,255,255,.12); }

.hm-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.hm-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.hm-kpi {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.hm-kpi-val {
  font-size: 22px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 4px;
}

.hm-kpi-lbl {
  font-size: 10px;
  color: var(--txt-m);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.hm-section { margin-bottom: 20px; }

.hm-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--acc);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hm-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Event timeline */
.hm-timeline { display: flex; flex-direction: column; gap: 6px; }

.hm-event {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.02);
  font-size: 12px;
}

.hm-event-icon {
  width: 24px; height: 24px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.hm-event.offline .hm-event-icon { background: rgba(255,51,85,.15); }
.hm-event.online  .hm-event-icon { background: rgba(0,255,136,.1); }
.hm-event.stock   .hm-event-icon { background: rgba(255,204,0,.1); }
.hm-event.restock .hm-event-icon { background: rgba(69,214,255,.1); }

.hm-event-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--txt-m);
  white-space: nowrap;
  margin-top: 2px;
}

/* Chart area */
.hm-chart-wrap { height: 140px; position: relative; }

/* ── SYSTEM VIEW HEADER ────────────────────────────────── */
.health-sys-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  position: sticky;
  top: 0;
  z-index: 50;
}

.health-sys-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
}

.health-sys-kpis {
  display: flex;
  gap: 20px;
  align-items: center;
}

.health-sys-kpi {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.health-sys-kpi .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}

.health-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── FILTER BAR ────────────────────────────────────────── */
.health-filters {
  display: flex;
  gap: 6px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-wrap: wrap;
}

.filter-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt-2);
  font-size: 12px;
  cursor: pointer;
  transition: .15s;
  font-family: var(--font);
}

.filter-btn:hover { border-color: var(--acc); color: var(--acc); }
.filter-btn.active { background: rgba(69,214,255,.12); border-color: var(--acc); color: var(--acc); }

/* ── UTILS ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  transition: .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
}
.btn-ghost {
  background: rgba(255,255,255,.06);
  color: var(--txt-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(255,255,255,.1); color: var(--txt); }
.btn-primary {
  background: linear-gradient(135deg, var(--acc), #2fb8e8);
  color: #000;
  font-weight: 700;
}
.btn-danger {
  background: rgba(255,51,85,.15);
  color: var(--c-red);
  border: 1px solid rgba(255,51,85,.3);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-green  { background: rgba(0,255,136,.12); color: var(--c-green); border: 1px solid rgba(0,255,136,.2); }
.badge-red    { background: rgba(255,51,85,.12);  color: var(--c-red);   border: 1px solid rgba(255,51,85,.2); }
.badge-yellow { background: rgba(255,204,0,.12); color: var(--c-yellow); border: 1px solid rgba(255,204,0,.2); }
.badge-blue   { background: rgba(69,214,255,.12); color: var(--acc);     border: 1px solid rgba(69,214,255,.2); }
.badge-grey   { background: rgba(85,102,119,.15); color: var(--c-grey);  border: 1px solid rgba(85,102,119,.2); }

.mono { font-family: var(--mono); }
.text-green  { color: var(--c-green); }
.text-red    { color: var(--c-red); }
.text-yellow { color: var(--c-yellow); }
.text-blue   { color: var(--acc); }
.text-muted  { color: var(--txt-m); }

@media (max-width: 768px) {
  .hm-kpis { grid-template-columns: repeat(2,1fr); }
  .pdv-grid { grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); }
  .tv-status-bar { gap: 12px; }
  .tv-kpi-val { font-size: 16px; }
  .tv-clock { font-size: 18px; }
}

/* ── TV MODE — FONTES LEGÍVEIS PARA 60" ─────────────────── */
body.tv-mode .tv-logo-text h1   { font-size: 28px !important; }
body.tv-mode .tv-logo-text p    { font-size: 14px !important; }
body.tv-mode .tv-logo-icon      { width: 56px !important; height: 56px !important; font-size: 20px !important; }
body.tv-mode .tv-kpi-val        { font-size: 36px !important; }
body.tv-mode .tv-kpi-lbl        { font-size: 14px !important; }
body.tv-mode .tv-clock          { font-size: 40px !important; }
body.tv-mode .tv-date           { font-size: 14px !important; }
body.tv-mode .tv-status-bar     { gap: 36px !important; }
body.tv-mode #tvBlankState h2   { font-size: 48px !important; }
body.tv-mode #tvBlankState p    { font-size: 22px !important; }
body.tv-mode .blank-icon        { width: 120px !important; height: 120px !important; font-size: 56px !important; }
body.tv-mode .pdv-grid          { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)) !important; gap: 20px !important; }
body.tv-mode #tvAlertBar        { gap: 16px !important; padding: 16px 28px !important; }

/* ── TV MODE — FONTE INTER PARA LEGIBILIDADE ────────────── */
body.tv-mode,
body.tv-mode .tv-header,
body.tv-mode .tv-logo-text h1,
body.tv-mode .tv-logo-text p,
body.tv-mode .tv-kpi-lbl,
body.tv-mode .tv-date,
body.tv-mode #tvBlankState h2,
body.tv-mode #tvBlankState p {
  font-family: 'Inter', sans-serif !important;
  -webkit-font-smoothing: antialiased;
}
body.tv-mode .tv-kpi-val,
body.tv-mode .tv-clock {
  font-family: 'Inter', sans-serif !important;
  font-weight: 800 !important;
}
body.tv-mode .tv-logo-text h1 {
  font-weight: 900 !important;
  letter-spacing: 0 !important;
}
