/* =========================
   THEME TOKENS
   ========================= */
:root{
  /* fontes */
  --fs-min: 12px;

  /* navy (mantém como tokens, mas não força no light) */
  --navy-900: #0b1c2d;
  --navy-800: #0f2338;
  --navy-700: #10263f;

  /* base */
  --bg-light: #f5f5f7;
  --text-light: #111827;
  --card-light: #ffffff;

  --bg-dark: #020617;
  --text-dark: #e5e7eb;
  --card-dark: #0b1220;

  /* target (verde Libre-like: lime/acid) */
  --target-bg: rgba(134, 212, 18, 0.649);          /* #84cc16 */
  --target-border: rgba(142, 227, 24, 0.398);      /* #65a30d */
  --target-badge-bg: rgba(134, 198, 38, 0.919);
  --target-text: #2f5a12;                      /* verde escuro */

  /* alertas */
  --low-red: #dc2626;
  --high-orange: #f97316;
  --warn-yellow: #facc15;

  /* linhas/bordas */
  --line-light: rgba(15,23,42,0.08);
  --line-dark: rgba(148,163,184,0.18);

  /* sticky height helper */
  --sticky-top-h: 126px;
}

/* =========================
   BASE
   ========================= */
*{
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: max(var(--fs-min), 100%);
}
html, body{ height: 100%; }
body{ margin:0; padding:0; min-height:100vh; }

body.light{ background: var(--bg-light); color: var(--text-light); }
body.dark{ background: var(--bg-dark); color: var(--text-dark); }

/* Shell */
.app-shell{ width:100%; min-height:100vh; padding:18px; }
@media (max-width:980px){ .app-shell{ padding:12px; } }
@media (max-width:640px){ .app-shell{ padding:10px; } }

/* Card principal */
.card{
  width:100%;
  border-radius:22px;
  padding:22px 22px 16px;
  position: relative;
}
body.light .card{
  background: var(--card-light);
  border: 1px solid #e5e7eb;
  box-shadow: 0 13px 32px rgba(15,23,42,0.08);
}
body.dark .card{
  background: var(--card-dark);
  border: 1px solid var(--line-dark);
  box-shadow: 0 18px 44px rgba(0,0,0,0.55);
}

/* =========================
   STICKY TOP (header + tabs)
   ========================= */
.sticky-top{
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 6px 0 10px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ✅ LIGHT: branco / iOS-like */
body.light .sticky-top{
  background: rgba(245,245,247,0.80);
  border-bottom: 1px solid rgba(229,231,235,0.95);
  color: var(--text-light);
}

/* ✅ DARK: mantém dark */
body.dark .sticky-top{
  background: rgba(2,6,23,0.75);
  border-bottom: 1px solid rgba(148,163,184,0.18);
}

@media (max-width:640px){
  :root{ --sticky-top-h: 140px; }
  .sticky-top{ padding-bottom: 8px; }
}

/* =========================
   HEADER
   ========================= */
.header{
  display:flex;
  justify-content: space-between;
  align-items:flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.header-left{ display:flex; align-items:center; gap:12px; }
.agent-avatar{
  width:46px; height:46px; border-radius:999px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.title{ font-size:18px; font-weight:700; }
.subtitle{ font-size:12px; opacity:0.65; }

.header-right{ display:flex; gap:10px; }
.theme-toggle{
  border:none; background:transparent; cursor:pointer; font-size:20px;
}
@media (max-width:640px){
  .agent-avatar{ width:40px; height:40px; }
  .title{ font-size:16px; }
}

/* =========================
   TABS
   ========================= */
.tabs-ios{
  display:flex;
  gap:6px;
  padding:6px;
  border-radius:999px;
  margin: 10px 0 12px;
}
body.light .tabs-ios{ background:#e5e7eb; }
body.dark .tabs-ios{ background:#020617; border: 1px solid #1f2937; }

.tab-ios{
  flex:1;
  border:none;
  border-radius:999px;
  padding:8px 0;
  font-size:13px;
  font-weight:600;
  background:transparent;
  cursor:pointer;
  transition: background .18s ease, color .18s ease, transform .1s ease;
}
body.light .tab-ios{ color:#4b5563; }
body.dark .tab-ios{ color:#9ca3af; }

body.light .tab-ios.tab-active{
  background:#fff;
  color:#111827;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
body.dark .tab-ios.tab-active{
  background:#2563eb;
  color:#f9fafb;
  box-shadow: 0 8px 18px rgba(37,99,235,0.45);
}
.tab-ios:active{ transform: scale(0.98); }

.tab-panel{ display:none; }
.tab-panel.active{ display:block; }

/* =========================
   TOP GRID
   ========================= */
.top-grid{
  display:grid;
  grid-template-columns: 360px 1fr;
  gap:14px;
  align-items: stretch;
  margin-top: 8px;
  margin-bottom: 12px;
}
@media (max-width:980px){
  .top-grid{ grid-template-columns:1fr; }
}

/* =========================
   STATUS CARD (centralizado)
   ========================= */
.status-card{
  border:1px solid var(--line-light);
  border-radius:16px;
  padding:16px;
  min-height:190px;

  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
}

.status-head{
  width:100%;
  display:flex;
  justify-content:center;
  margin-bottom: 12px;
}

.status-badge{
  display:inline-flex;
  align-items:center;
  padding:8px 12px;
  border-radius:999px;
  font-weight:800;
  font-size:13px;
  letter-spacing:.3px;
}

.status-value{
  display:flex;
  align-items:baseline;
  justify-content:center;
  gap:12px;
  margin-top: 6px;
}

.status-number{
  font-size:64px;
  font-weight:900;
  line-height:1;
  color: #0f172a;
}
body.dark .status-number{ color:#f9fafb; }

.status-unit{
  font-size:18px;
  opacity:.85;
  font-weight:700;
}

.status-sub{
  margin-top: 10px;
  font-size:14px;
  opacity:.85;
}

/* MUITO BAIXO */
.status-verylow{
  background: rgba(220,38,38,0.10);
  border-color: rgba(220,38,38,0.28);
}
.status-verylow .status-badge{
  background: rgba(220,38,38,0.18);
  color:#991b1b;
}

/* BAIXO */
.status-low{
  background: rgba(249,115,22,0.12);
  border-color: rgba(249,115,22,0.30);
}
.status-low .status-badge{
  background: rgba(249,115,22,0.20);
  color:#9a3412;
}

/* ALVO */
.status-inrange{
  background: var(--target-bg);
  border-color: var(--target-border);
}
.status-inrange .status-badge{
  background: var(--target-badge-bg);
  color: var(--target-text);
}

/* ALTO */
.status-high{
  background: rgba(250,204,21,0.18);
  border-color: rgba(250,204,21,0.35);
}
.status-high .status-badge{
  background: rgba(250,204,21,0.28);
  color:#854d0e;
}

/* MUITO ALTO */
.status-veryhigh{
  background: rgba(249,115,22,0.16);
  border-color: rgba(249,115,22,0.35);
}
.status-veryhigh .status-badge{
  background: rgba(249,115,22,0.26);
  color:#9a3412;
}

/* =========================
   CHART CARD
   ========================= */
.chart-card{
  border:1px solid var(--line-light);
  border-radius:16px;
  padding:12px 12px 10px;
  background: rgba(255,255,255,.65);
}
body.dark .chart-card{
  background: rgba(2,6,23,.55);
  border-color: var(--line-dark);
}

.chart-head{
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap:10px;
  margin-bottom: 6px;
}
.chart-title{
  font-weight:800;
  font-size:13px;
  opacity:.85;
}
.time-range{ display:flex; gap:6px; }
.time-range-btn{
  border:1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.7);
  border-radius:999px;
  padding:6px 10px;
  font-size:12px;
  font-weight:800;
  cursor:pointer;
}
body.dark .time-range-btn{
  background: rgba(2,6,23,.65);
  border-color: rgba(148,163,184,.22);
  color:#e5e7eb;
}
.time-range-btn.active{
  background: rgba(37,99,235,.12);
  border-color: rgba(37,99,235,.35);
}

.mini-chart{ width:100%; min-height:280px; }
body.fit-screen .mini-chart{ min-height:220px; }

.mini-legend{
  margin-top: 6px;
  font-size:12px;
  opacity:.75;
  text-align:center;
}

/* =========================
   SUMMARY
   ========================= */
.summary-card{
  border:1px solid var(--line-light);
  border-radius:16px;
  padding:14px 16px;
  background: rgba(255,255,255,.65);
  margin-top: 10px;
}
body.dark .summary-card{
  background: rgba(2,6,23,.55);
  border-color: var(--line-dark);
}
.summary-title{
  font-weight:900;
  font-size:13px;
  opacity:.85;
  margin-bottom: 6px;
}
.summary-text{
  font-size:13px;
  line-height:1.35;
  margin-bottom:10px;
}
.summary-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
@media (max-width:980px){
  .summary-grid{ grid-template-columns:1fr; }
}
.summary-item{
  border:1px solid rgba(0,0,0,.06);
  border-radius:14px;
  padding:10px 12px;
  background: rgba(255,255,255,.7);
}
body.dark .summary-item{
  background: rgba(2,6,23,.65);
  border-color: var(--line-dark);
}
.summary-label{
  font-size:12px;
  opacity:.7;
  margin-bottom:4px;
  font-weight:800;
}
.summary-value{ font-size:13px; font-weight:900; }

.summary-risk-ok{ color:#166534; }
.summary-risk-bad{ color:#991b1b; }
.summary-risk-warn{ color:#854d0e; }

/* =========================
   SECTIONS / INSIGHT TEXT
   ========================= */
.section-title{
  font-weight:800;
  font-size:13px;
  margin-top: 14px;
  margin-bottom: 8px;
}

.insight-text{
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.5;
}

/* =========================
   PILL GRID
   ========================= */
.pill-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:12px;
  margin-top: 8px;
  margin-bottom: 10px;
}

@media (max-width:980px){
  .pill-grid{ grid-template-columns: 1fr; }
}

.pill-card{
  border-radius:14px;
  padding:12px 14px;
  display:flex;
  flex-direction:column;
  justify-content:flex-start;
  min-height: 84px;
  font-size: 12px;
}
body.light .pill-card{ background:#f9fafb; }
body.dark .pill-card{ background:#0f172a; border: 1px solid #1e293b; }

.pill-label{ opacity:.7; font-size:12px; margin-bottom:2px; font-weight:700; }
.pill-value{ font-weight:900; font-size:13px; }
.pill-sub{ font-size:12px; opacity:.85; }

.reco-list{ font-size:12px; margin: 6px 0 10px; padding-left:18px; }
.reco-list li{ margin-bottom:2px; }

.food-chips{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:8px;
  align-items:center;
  font-size:12px;
}
.food-chip{
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,.35);
  background: rgba(255,255,255,.7);
  white-space: nowrap;
  line-height: 1.2;
}
body.dark .food-chip{
  background: rgba(2,6,23,.65);
  border-color: rgba(148,163,184,.25);
}

/* =========================
   HISTORY (direita)
   ========================= */
.desktop-history-box{
  border: 1px solid var(--line-light);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,.65);
}
body.dark .desktop-history-box{
  background: rgba(2,6,23,.55);
  border-color: var(--line-dark);
}

.history-title{ margin-top: 0; font-size: 12px; font-weight: 900; }
.history-meta{ font-size: 12px; opacity: .75; margin-bottom: 6px; }

#history-list{ list-style:none; padding:0; margin:0; }
#history-list li{
  display:flex;
  justify-content: space-between;
  align-items:center;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: 12px;
}
body.light #history-list li{ background:#f9fafb; }
body.dark  #history-list li{ background:#0f172a; border: 1px solid #1e293b; }

#history-list li .history-time{ opacity:.85; }
#history-list li .history-value{ font-weight:900; }

#history-list li .history-value.low{ color: var(--high-orange); }
#history-list li .history-value.high{ color: var(--low-red); }

/* Desktop grid */
@media (min-width:980px){
  .desktop-grid{
    display:grid;
    grid-template-columns: 1.9fr 1fr;
    gap:18px;
    align-items:flex-start;
    margin-top: 8px;
  }
  .desktop-history-box{
    position: sticky;
    top: 14px;
    align-self: start;
    max-height: calc(100vh - 40px);
    overflow:auto;
  }
}

/* =========================
   FORMS
   ========================= */
.field-group{ margin-bottom: 8px; }
.field-label{
  font-size: 12px;
  margin-bottom: 2px;
  display:block;
  font-weight: 800;
  opacity: .85;
}
.field-row{ display:flex; gap:8px; }
.field-row .field-group{ flex:1; }

input[type="number"], select{
  width:100%;
  font-size:13px;
  padding:8px 10px;
  border-radius:10px;
  border:1px solid #e5e7eb;
  background:#fff;
}
body.dark input[type="number"], body.dark select{
  background: rgba(2,6,23,.65);
  border-color: rgba(148,163,184,.22);
  color:#e5e7eb;
}

.btn-primary{
  width:100%;
  margin-top:6px;
  border:none;
  border-radius:12px;
  padding:10px 12px;
  background:#2563eb;
  color:#fff;
  font-size:13px;
  font-weight:900;
  cursor:pointer;
}
.btn-primary:active{ transform: scale(0.99); }

.sim-result, .settings-info{
  font-size: 12px;
  margin-top: 8px;
  line-height: 1.5;
}
.hint{ font-size: 12px; opacity:.75; margin-top: 6px; }

/* =========================
   FOOTER
   ========================= */
.footer{
  margin-top: 12px;
  opacity: .7;
  font-size: 12px;
  display:flex;
  justify-content: space-between;
  align-items:center;
}
.dot{
  width:8px;
  height:8px;
  background:#10b981;
  border-radius:999px;
  animation: pulse 1.7s infinite;
}
@keyframes pulse{
  0%{ transform: scale(1); }
  50%{ transform: scale(1.2); }
  100%{ transform: scale(1); }
}

/* =========================
   TV MODE
   ========================= */
body.tv-mode .tabs-ios{ display:none; }
body.tv-mode .header-right{ display:none; }
body.tv-mode .card{ border-radius:10px; padding:18px; }
body.tv-mode .mini-chart{ min-height:320px; }
body.tv-mode .status-number{ font-size:74px; }

/* =========================
   FIT SCREEN
   ========================= */
body.fit-screen{ overflow:hidden; }
body.fit-screen .app-shell{ min-height:100vh; height:100vh; padding:12px; }
body.fit-screen .card{
  height: calc(100vh - 24px);
  overflow: hidden;
  padding: 16px;
  display:flex;
  flex-direction:column;
}
body.fit-screen .desktop-grid{
  flex:1;
  min-height:0;
  overflow:hidden;
}
body.fit-screen .desktop-history-box{
  height:100%;
  overflow:auto;
  min-height:0;
}

/* =========================
   PATCH: Tabela do simulador (mais fina / menos "grossa")
   ========================= */
#quick-carb-table{
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(148,163,184,0.18);
}

/* wrapper arredondado */
.table-wrap{
  border: 1px solid rgba(148,163,184,0.16);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.55);
}
body.dark .table-wrap{
  background: rgba(2,6,23,0.45);
  border-color: rgba(148,163,184,0.18);
}

/* tabela */
.simple-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.25;
}

.simple-table thead th{
  font-size: 12px;
  font-weight: 800;
  opacity: .75;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(148,163,184,0.22);
  white-space: nowrap;
}

.simple-table tbody td{
  padding: 6px 8px;
  border-bottom: 1px solid rgba(148,163,184,0.14);
  vertical-align: top;
}

.simple-table td:nth-child(2),
.simple-table td:nth-child(3){
  text-align: right;
  white-space: nowrap;
}
.simple-table td:first-child{ white-space: normal; }

/* zebra sutil */
body.light .simple-table tbody tr:nth-child(odd){
  background: rgba(15,23,42,0.02);
}
body.dark .simple-table tbody tr:nth-child(odd){
  background: rgba(148,163,184,0.06);
}

/* =========================
   SIMULATOR: RESULT CARDS (volta o formato)
   ========================= */
.sim-cards{
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

@media (max-width: 980px){
  .sim-cards{ grid-template-columns: 1fr; }
}

.sim-card{
  border: 1px solid rgba(148,163,184,0.18);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.dark .sim-card{
  background: rgba(2,6,23,0.55);
  border-color: rgba(148,163,184,0.22);
}

.sim-card .k{
  font-size: 12px;
  font-weight: 900;
  opacity: .75;
  margin-bottom: 6px;
}

.sim-card .v{
  font-size: 16px;
  font-weight: 900;
  line-height: 1.15;
}

.sim-card .s{
  font-size: 12px;
  opacity: .75;
  margin-top: 6px;
}

.sim-badge{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  border: 1px solid rgba(148,163,184,0.22);
  background: rgba(255,255,255,0.75);
}

body.dark .sim-badge{
  background: rgba(2,6,23,0.55);
  border-color: rgba(148,163,184,0.22);
}

.sim-badge.ok{
  border-color: rgba(16,185,129,0.30);
  background: rgba(16,185,129,0.10);
  color: #065f46;
}

.sim-badge.risk{
  border-color: rgba(245,158,11,0.35);
  background: rgba(245,158,11,0.12);
  color: #854d0e;
}
/* ================================
   MOBILE FIX (iPhone/Android)
   ================================ */
@media (max-width: 820px) {
  html, body {
    width: 100%;
    overflow-x: hidden; /* mata o "deslocado pra direita" */
  }

  .app-shell {
    padding: 10px;
  }

  .card {
    width: 100%;
    max-width: 100%;
    overflow: hidden; /* impede vazamento interno */
  }

  /* Header: quebra correta e sem elementos soltos */
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .header-left {
    min-width: 0;
    display: flex;
    gap: 10px;
    align-items: center;
  }

  .header-left .title {
    font-size: 18px;
    line-height: 1.15;
  }

  .header-left .subtitle {
    font-size: 12px;
    opacity: 0.8;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }

  .btn-logout {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    border-radius: 14px;
    white-space: nowrap;
  }

  /* Tabs: rolagem horizontal */
  .tabs-ios {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    gap: 8px;
    padding: 8px 4px;
  }

  .tabs-ios::-webkit-scrollbar {
    display: none;
  }

  .tab-ios {
    flex: 0 0 auto;
  }

  /* Top grid: vira 1 coluna */
  .top-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Desktop grid: vira 1 coluna */
  .desktop-grid {
    display: block !important;
  }

  .desktop-history-box {
    margin-top: 12px;
  }

  /* Status card: reduz "vazamento" */
  .status-card {
    width: 100%;
    max-width: 100%;
  }

  .status-number {
    font-size: 64px; /* evita cortar no mobile */
    line-height: 1;
  }

  /* Chart card: impede estouro do Apex */
  .chart-card {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  #mini-chart {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  /* ApexCharts container + svg responsivo */
  .apexcharts-canvas,
  .apexcharts-inner,
  .apexcharts-svg {
    max-width: 100% !important;
  }

  /* Se o seu CSS tiver padding grande aqui, isso ajuda */
  .mini-legend {
    font-size: 12px;
    line-height: 1.2;
  }

  /* Pills não estourarem */
  .pill-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Tabelas no mobile: scroll */
  .table-wrap {
    width: 100%;
    overflow-x: auto;
  }
}

@media (max-width: 820px) {
  html, body { width: 100%; overflow-x: hidden; }

  .app-shell { padding: 10px; }
  .card { width: 100%; max-width: 100%; overflow: hidden; }

  .header { display:flex; align-items:center; justify-content:space-between; gap:10px; }
  .header-left { min-width:0; display:flex; align-items:center; gap:10px; }
  .header-right { display:flex; align-items:center; gap:10px; flex-shrink:0; }

  .btn-logout {
    text-decoration:none;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    padding:10px 12px;
    border-radius:14px;
    white-space:nowrap;
  }

  .tabs-ios {
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    white-space:nowrap;
    gap:8px;
    padding:8px 4px;
  }
  .tabs-ios::-webkit-scrollbar { display:none; }
  .tab-ios { flex:0 0 auto; }

  .top-grid { display:grid; grid-template-columns:1fr !important; gap:12px; }
  .desktop-grid { display:block !important; }
  .desktop-history-box { margin-top:12px; }

  .status-number { font-size:64px; line-height:1; }

  .chart-card, #mini-chart { width:100%; max-width:100%; overflow:hidden; }

  .apexcharts-canvas,
  .apexcharts-inner,
  .apexcharts-svg { max-width:100% !important; }

  .pill-grid { display:grid; grid-template-columns:1fr; gap:10px; }

  .table-wrap { width:100%; overflow-x:auto; }
}
/* MOBILE FIX: layout do chart e tabs */
@media (max-width: 820px) {
  .top-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 14px;
  }

  .chart-card {
    width: 100%;
    overflow: hidden;
  }

  .chart-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .time-range {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
  }

  .time-range-btn {
    flex: 0 0 auto;
  }

  .mini-chart {
    width: 100% !important;
    min-height: 240px;
  }

  /* ApexCharts costuma travar width inline */
  .apexcharts-canvas,
  .apexcharts-svg {
    width: 100% !important;
  }

  .mini-legend {
    white-space: normal;
    text-align: left;
  }
}

/* ✅ MOBILE FIX */
html, body { overflow-x: hidden; }

@media (max-width: 820px) {
  .app-shell { padding: 12px; }
  .card { padding: 12px; }

  .header { flex-wrap: wrap; gap: 10px; }
  .header-left { min-width: 0; }
  .title { font-size: 20px; }
  .subtitle { font-size: 13px; }

  .header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .tabs-ios {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
  }
  .tabs-ios::-webkit-scrollbar { display: none; }
  .tab-ios { flex: 0 0 auto; white-space: nowrap; }

  .top-grid { grid-template-columns: 1fr !important; }
  .desktop-grid { grid-template-columns: 1fr !important; }

  .desktop-history-box { margin-top: 14px; }

  .status-card { padding: 18px; }
  .status-number { font-size: 64px; }

  .chart-card { padding: 16px; }
  .mini-chart { width: 100%; height: 260px; }

  /* ApexCharts às vezes “passa” da largura no iOS */
  .apexcharts-canvas,
  .apexcharts-svg {
    width: 100% !important;
  }
}
/* ✅ HEADER não estoura */
.header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.header-left { display:flex; align-items:center; gap:12px; min-width:0; }
.header-left > div { min-width:0; } /* título pode “encolher” */
.title, .subtitle { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.header-right { display:flex; align-items:center; gap:10px; flex:0 0 auto; }
.btn-logout{
  padding: 10px 14px;
  border-radius: 14px;
  text-decoration: none;
  font-weight: 600;
  background: rgba(148,163,184,.18);
  color: inherit;
  border: 1px solid rgba(148,163,184,.25);
}

/* ✅ MENU (tabs) responsivo e scrollável */
.tabs-ios{
  display:flex;
  gap:8px;
  padding: 10px;
  border-radius: 18px;
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.tabs-ios::-webkit-scrollbar{ display:none; }
.tab-ios{
  
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ✅ No mobile, garante que não vai “vazar” */
@media (max-width: 820px){
  .tabs-ios{ margin-top: 8px; }
  .tab-ios{ padding: 10px 14px; }
}

/* ===== Mobile fixes ===== */
* { max-width: 100%; }
img, svg, canvas { max-width: 100%; height: auto; }

.app-shell { padding: 12px; }
.card { overflow: hidden; }

/* header/tabs não estourarem */
.header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-left .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-left .subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.btn-logout{
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* top-grid vira 1 coluna no mobile */
.top-grid { display: grid; gap: 14px; }
@media (max-width: 860px){
  .top-grid { grid-template-columns: 1fr !important; }
  .desktop-grid { grid-template-columns: 1fr !important; }
  .desktop-history-box { margin-top: 14px; }
}

/* tabs: evitar corte/estouro */
.tabs-ios{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
}
.tab-ios{
  flex: 1 1 auto;
  min-width: 110px;
  text-align: center;
}

/* chart: garantir altura e evitar “vazio” */
.chart-card { overflow: hidden; }
.mini-chart { width: 100%; min-height: 260px; }
@media (max-width: 480px){
  .mini-chart { min-height: 300px; }
}

/* legend sempre colada no chart, sem duplicar layout */
.mini-legend{
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,.06);
}

/* evitar qualquer “gap fantasma” por div quebrada */
.chart-head { display:flex; align-items:center; justify-content:space-between; gap: 10px; flex-wrap: wrap; }
.time-range { display:flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* MOBILE: tabs em 1 linha rolável */
.tabs-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* evita quebrar em 2 linhas */
.tabs-ios {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  min-width: max-content;
  padding-bottom: 6px;
}

/* cada botão não encolhe e mantém largura confortável */
.tabs-ios .tab-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ================================
   MOBILE PATCH (CANON) — não duplica
   ================================ */
html, body { overflow-x: hidden; }

@media (max-width: 820px) {

  .app-shell { padding: 10px; }
  .card { padding: 14px; overflow: hidden; }

  /* HEADER: não estoura / não quebra feio */
  .header { align-items: center; }
  .header-left { min-width: 0; }
  .header-left > div { min-width: 0; }
  .title, .subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* TABS: 1 linha, rolável (estilo iOS) */
  .tabs-ios{
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding: 8px;
    border-radius: 999px;
  }
  .tabs-ios::-webkit-scrollbar { display: none; }

  .tab-ios{
    flex: 0 0 auto;         /* não encolhe */
    padding: 10px 14px;     /* toque confortável */
    white-space: nowrap;
  }

  /* GRID: vira 1 coluna */
  .top-grid { grid-template-columns: 1fr !important; }
  .desktop-grid { display: block !important; }
  .desktop-history-box { margin-top: 12px; }

  /* CHART: impede vazamento no iOS */
  .chart-card { overflow: hidden; }
  #mini-chart, .mini-chart { width: 100%; max-width: 100%; overflow: hidden; }
  .apexcharts-canvas, .apexcharts-svg { max-width: 100% !important; }
}

/* ===========================
   PATCH MENU + CHART (SAFE)
   Cole no FINAL do samuel.css
   =========================== */

/* --- 1) DESKTOP: tabs ocupam a largura (sem ficar tudo junto) --- */
@media (min-width: 821px){
  .tabs-ios{
    overflow: visible !important;
    flex-wrap: nowrap !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }
  .tab-ios, .tabs-ios .tab-btn{
    flex: 1 1 0 !important;     /* cada tab cresce igualmente */
    min-width: 0 !important;
    white-space: nowrap !important;
  }
}

/* --- 2) MOBILE: sem scroll, em 2 colunas (2x2) --- */
@media (max-width: 820px){
  .tabs-ios{
    overflow-x: visible !important;  /* mata o scroll */
    flex-wrap: wrap !important;
    gap: 10px !important;
    padding: 10px !important;
  }

  .tab-ios, .tabs-ios .tab-btn{
    flex: 1 1 calc(50% - 10px) !important; /* 2 colunas */
    min-width: 0 !important;
    white-space: nowrap !important;
  }
}

/* --- 3) CHART: evita cortar o último dígito no eixo X --- */
/* (o “19:1” geralmente é o “0” sendo clipado pelo container) */
.chart-card,
#mini-chart{
  overflow: visible !important; /* deixa o SVG respirar */
}

/* Dá um respiro no canvas do Apex */
.apexcharts-canvas{
  overflow: visible !important;
}

/* Pequeno padding visual extra sem alterar layout geral */
.chart-card{
  padding-right: 16px !important;
}

/* ===== Mobile: tabs (menu) mais compacto ===== */
@media (max-width: 520px) {
  .tabs {
    padding: 10px 12px !important;
    gap: 8px !important;
    border-radius: 16px !important;
  }

  .tab-btn {
    padding: 10px 10px !important;
    font-size: 14px !important;
    border-radius: 14px !important;
    min-height: 38px !important;
  }

  /* se você usa ícone/emoji no botão */
  .tab-btn .icon {
    font-size: 16px !important;
  }
}

/* ===== Mobile: menu/tabs compacto e bonito ===== */
@media (max-width: 520px) {

  /* Container dos botões (ajuste o seletor se o seu wrapper tiver outro nome) */
  .tabs,
  .tabs-bar,
  .tab-bar,
  .tab-buttons {
    display: flex !important;
    gap: 8px !important;
    padding: 8px !important;
    border-radius: 18px !important;
    background: rgba(148, 163, 184, 0.18) !important;
    overflow: hidden !important;
  }

  /* Botões */
  .tab-btn {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    padding: 10px 10px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border-radius: 14px !important;
    background: transparent !important;
    box-shadow: none !important;
    border: 1px solid rgba(148, 163, 184, 0.22) !important;
  }

  /* Ativo */
  .tab-btn.tab-active {
    background: rgba(255, 255, 255, 0.85) !important;
    border-color: rgba(148, 163, 184, 0.25) !important;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.10) !important;
  }

  /* Se seu layout tiver aquele "fundão" cinza gigante, ele costuma vir de um wrapper interno */
  .tabs::before,
  .tabs::after {
    display: none !important;
    content: none !important;
  }
}

/* ===== Mobile: tabs em UMA linha (com scroll) ===== */
@media (max-width: 520px) {

  /* wrapper dos tabs (ajuste se necessário, mas normalmente pega) */
  .tabs,
  .tabs-bar,
  .tab-bar,
  .tab-buttons {
    display: flex !important;
    flex-wrap: nowrap !important;       /* ✅ não quebra linha */
    gap: 10px !important;
    padding: 10px !important;
    border-radius: 16px !important;
    background: rgba(148,163,184,.16) !important;

    overflow-x: auto !important;        /* ✅ scroll se precisar */
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .tabs::-webkit-scrollbar,
  .tabs-bar::-webkit-scrollbar,
  .tab-bar::-webkit-scrollbar,
  .tab-buttons::-webkit-scrollbar {
    display: none !important;
  }

  /* botões viram “pills” e não esticam */
  .tab-btn {
    flex: 0 0 auto !important;          /* ✅ não força 2 por linha */
    white-space: nowrap !important;     /* ✅ não quebra texto */
    padding: 10px 14px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border-radius: 999px !important;
  }

  .tab-btn.tab-active{
    background: rgba(255,255,255,.9) !important;
    box-shadow: 0 6px 16px rgba(15,23,42,.10) !important;
  }
}

/* ===== CANON: Tabs em 1 linha no mobile (força mesmo) ===== */
@media (max-width: 520px){

  .tabs-ios{
    display: flex !important;
    flex-wrap: nowrap !important;        /* NÃO quebra linha */
    justify-content: flex-start !important;
    gap: 8px !important;

    padding: 8px !important;
    border-radius: 999px !important;

    overflow-x: auto !important;         /* scroll horizontal */
    -webkit-overflow-scrolling: touch !important;

    white-space: nowrap !important;
    scrollbar-width: none !important;
  }
  .tabs-ios::-webkit-scrollbar{ display:none !important; }

  .tab-ios{
    flex: 0 0 auto !important;           /* não estica e não força 2 linhas */
    width: auto !important;
    min-width: max-content !important;   /* mantém texto inteiro */
    white-space: nowrap !important;

    padding: 10px 14px !important;       /* pill confortável */
  }
}
/* ===== FIX: último tab não corta (iOS Safari) ===== */
@media (max-width: 520px){

  /* dá “respiro” pro scroll chegar até o fim */
  .tabs-ios{
    padding-right: 16px !important;
    scroll-padding-right: 16px !important;
  }

  /* garante que o container do menu não está clipando */
  .sticky-top,
  .card{
    overflow: visible !important;
  }

  /* cria uma folga no final do scroll */
  .tabs-ios::after{
    content: "";
    flex: 0 0 14px;   /* espaço final */
  }
}

/* Tabs em 1 linha, sem scroll */
.tabs,
.tabs-row,
.tab-bar {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: hidden;     /* ✅ sem scroll */
}

/* Cada botão “encolhe” pra caber */
.tab-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 8px;      /* ✅ menos padding */
  font-size: 13px;        /* ✅ menor */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* wrapper das tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;

  /* mata scroll horizontal */
  overflow: hidden;
}

/* botões */
.tab-btn {
  width: 100%;
  white-space: nowrap;   /* não quebra linha */
  overflow: hidden;
  text-overflow: ellipsis; /* se ficar apertado, corta com … */
  padding: 10px 8px;
  font-size: 14px;
}

/* iPhone: deixa mais compacto */
@media (max-width: 520px) {
  .tab-btn {
    font-size: 13px;
    padding: 9px 6px;
  }
}

/* Tabs mobile: 1 linha, sem scroll */
@media (max-width: 520px) {
  .tabs { 
    display: grid; 
    grid-template-columns: repeat(4, 1fr); 
    gap: 6px; 
    overflow: hidden; 
    width: 100%;
  }

  .tab-btn { 
    min-width: 0; 
    width: 100%;
    padding: 7px 4px;
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
body { overflow-x: hidden; }

/* =====================================================
   MOBILE CANON (ÚNICO) — menu 1 linha, sem scroll, bonito
   cole no FINAL do samuel.css
   ===================================================== */
@media (max-width: 520px) {

  html, body { overflow-x: hidden; }

  .app-shell { padding: 10px; }
  .card { padding: 14px; width: 100%; max-width: 100%; overflow: hidden; }

  /* Header não estoura */
  .header-left { min-width: 0; }
  .header-left > div { min-width: 0; }
  .title, .subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Tabs: SEM scroll (4 colunas em 1 linha) */
  .tabs-ios{
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px !important;
    overflow: hidden !important;
    padding: 6px !important;
    border-radius: 999px !important;
  }

  .tab-ios{
    width: 100% !important;
    min-width: 0 !important;
    flex: initial !important;
    padding: 9px 6px !important;
    font-size: 12.5px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Layout vira 1 coluna */
  .top-grid{ grid-template-columns: 1fr !important; }
  .desktop-grid{ display: block !important; }
  .desktop-history-box{ margin-top: 12px; }

  /* Apex não vaza */
  .chart-card, #mini-chart{ max-width: 100%; overflow: hidden; }
  .apexcharts-canvas, .apexcharts-svg{ max-width: 100% !important; }
}

.sensor-banner{
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(148,163,184,0.14);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.sensor-banner.hidden{ display:none; }

body.dark .sensor-banner{
  border-color: rgba(148,163,184,0.25);
  background: rgba(148,163,184,0.10);
}

.sensor-banner-title{ font-weight: 900; font-size: 13px; }
.sensor-banner-sub{ font-size: 12px; opacity: .8; margin-top: 2px; }
.hidden{ display:none !important; }

.sensor-dot {
 width: 10px;
  height: 10px;
  min-width: 10px;
  min-height: 10px;

  border-radius: 50%;
  display: inline-block; /* 🔑 importante */
}

.sensor-dot.ok {
  background: #22c55e; /* verde */
}

.sensor-dot.stale {
  background: #ef4444; /* vermelho */
}


/* =========================
   MENU AZUL PETRÓLEO
========================= */

.tabs-ios {
  background: #0f2f3f; /* azul petróleo */
}

.tab-ios {
  color: #cfe6ef; /* texto claro */
  background: transparent;
}

.tab-ios:hover {
  color: #ffffff;
}

/* Aba ativa */
.tab-ios.tab-active {
  background: #ffffff;
  color: #0f2f3f;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.tab-ios.tab-active::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 20%;
  right: 20%;
  height: 3px;
  border-radius: 3px;
  background: #0f2f3f;
}

/* ===== MENU AZUL PETRÓLEO (override forte) ===== */
:root{
  --petroleo: #0f2f3f;
  --petroleo-text: #cfe6ef;
}

/* o “capsule” do menu */
.tabs-wrap .tabs-ios{
  background: var(--petroleo) !important;
}

/* texto dos botões */
.tabs-wrap .tabs-ios .tab-ios{
  color: var(--petroleo-text) !important;
  background: transparent !important;
  border-color: rgba(255,255,255,.18) !important;
}

/* ativo = pill branco */
.tabs-wrap .tabs-ios .tab-ios.tab-active{
  background: #ffffff !important;
  color: var(--petroleo) !important;
  box-shadow: 0 2px 10px rgba(0,0,0,.10) !important;
}

/* remove a “retinha azul” (underline/indicator antigo) */
.tabs-wrap .tabs-ios .tab-ios::after,
.tabs-wrap .tabs-ios .tab-ios.tab-active::after{
  content: none !important;
  display: none !important;
}

/* ApexCharts — evita cortar labels no iPhone/iPad */
.mini-chart {
  padding-bottom: 10px;
}

.apexcharts-xaxis text {
  dominant-baseline: central;
}

@media (max-width: 520px) {
  .apexcharts-xaxis-label {
    font-size: 11px !important;
  }
}
/* ApexCharts — linha sólida e visível (SEM ferrar outros paths) */
#mini-chart .apexcharts-line-series path.apexcharts-line {
  stroke-dasharray: 0 !important;
  stroke-opacity: 1 !important;
  stroke-linecap: round !important;
  stroke-width: 2px !important;
}

/* Se você usar area em algum momento, também segura o contorno */
#mini-chart .apexcharts-area-series path.apexcharts-area {
  stroke-dasharray: 0 !important;
  stroke-opacity: 1 !important;
}