:root {
  --yellow:    #D97706;
  --yellow-dim:#FFFBEB;
  --green:     #16a34a;
  --green-dim: #F0FDF4;
  --blue:      #2563EB;
  --blue-dim:  #EFF6FF;
  --blue-mid:  #BFDBFE;
  --orange:    #EA580C;
  --red:       #DC2626;
  --red-dim:   #FEF2F2;

  --bg:         #F8FAFC;
  --bg2:        #F1F5F9;
  --bg3:        #E2E8F0;
  --text:       #0F172A;
  --text2:      #64748B;
  --border:     #E2E8F0;
  --card:       #FFFFFF;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius:     8px;
  --sidebar-bg: #0F172A;
  --sidebar-tx: #94A3B8;
  --sidebar-w:  240px;
  --msg-user:   #2563EB;
  --msg-bot:    #F1F5F9;
  --msg-user-tx:#ffffff;
  --msg-bot-tx: #0F172A;
  --header-h:   56px;
}

[data-theme="dark"] {
  --bg:         #0f1117;
  --bg2:        #1a1a2e;
  --bg3:        #16213e;
  --text:       #e8eaf0;
  --text2:      #9ba3b8;
  --border:     #2a2d3e;
  --card:       #1a1a2e;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
  --sidebar-bg: #0f1117;
  --sidebar-tx: #9ba3b8;
  --msg-bot:    #252a3a;
  --msg-bot-tx: #e8eaf0;
}

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

html {
  -webkit-text-size-adjust: 100%;
  /* Altura real no iOS (sem a barra do browser) */
  height: -webkit-fill-available;
}
/* Suporte a safe-area (iPhone X+ notch / Dynamic Island) */
@supports (padding: max(0px)) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--yellow) 0%, var(--green) 40%, var(--blue) 100%);
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}
.header-logo { height: 36px; flex-shrink: 0; }
.header-title {
  font-weight: 700; color: #fff; font-size: 1rem;
  text-shadow: 0 1px 3px rgba(0,0,0,.3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Hamburger (mobile admin) ─────────────────────────── */
.hamburger {
  display: none;
  background: rgba(255,255,255,.2);
  border: none;
  border-radius: 8px;
  width: 40px; height: 40px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
}
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: #fff; border-radius: 2px;
  transition: all .25s;
}

/* ── Toggle tema ──────────────────────────────────────── */
.theme-toggle {
  background: rgba(255,255,255,.25);
  border: none; border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer; font-size: .8rem; color: #fff; font-weight: 600;
  transition: background .2s;
  min-height: 36px; min-width: 36px;
  white-space: nowrap;
}
.theme-toggle:hover { background: rgba(255,255,255,.4); }

/* ── Botão sair ───────────────────────────────────────── */
.btn-sair {
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff; padding: 6px 14px;
  border-radius: 8px; cursor: pointer; font-size: .82rem;
  transition: background .2s; min-height: 36px; white-space: nowrap;
}
.btn-sair:hover { background: rgba(255,255,255,.35); }

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
}

/* ── Logout button (sidebar bottom) ──────────────────── */
.btn-logout {
  width: 100%; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,.1);
  background: transparent; color: var(--sidebar-tx); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: background .15s, color .15s; font-family: inherit;
}
.btn-logout:hover { background: rgba(220,38,38,.15); color: #FCA5A5; border-color: rgba(220,38,38,.3); }

/* ── Botões ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 6px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--text);
  cursor: pointer; font-size: .82rem; font-weight: 500;
  font-family: inherit;
  transition: background .15s, border-color .15s;
  touch-action: manipulation;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-success   { background: var(--green); color: #fff; border-color: var(--green); }
.btn-warning   { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn-danger    { background: var(--red); color: #fff; border-color: var(--red); }
.btn-secondary { background: var(--bg2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg3); }
.btn-sm        { padding: 6px 12px; font-size: .78rem; }
.btn:hover:not(:disabled):not(.btn-primary):not(.btn-success):not(.btn-warning):not(.btn-danger) { background: var(--bg2); }
.btn .bi { font-size: .88rem; }

/* ── Inputs ───────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; color: var(--text2); }
.form-control {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 16px;
  transition: border-color .2s; -webkit-appearance: none;
  min-height: 44px;
}
.form-control:focus { outline: none; border-color: var(--blue); }

/* ── Form row ─────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Badges ───────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .75rem; font-weight: 700; }
.badge-active  { background: #d4f0d4; color: #1a7a1a; }
.badge-inactive{ background: #fde8e8; color: #a00; }
.badge-error   { background: #fde8e8; color: var(--red); }
.badge-warn    { background: #fff3cd; color: #856404; }

/* ── Tabela ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table th { background: var(--bg2); padding: 10px 14px; text-align: left; font-size: .78rem; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .86rem; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg2); }

/* ── Layout admin ─────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w, 240px); background: var(--sidebar-bg);
  padding: 0; flex-shrink: 0;
  display: flex; flex-direction: column;
  transition: transform .25s, width .25s;
  z-index: 200;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar.collapsed { width: 56px; overflow: hidden; }
.sidebar.collapsed .nav-lbl { display: none; }
.sidebar.collapsed .sb-section-lbl { display: none; }
.sidebar.collapsed .sidebar-logo img { display: none; }
.sidebar.collapsed .sidebar-logo { padding: 14px 10px; display: flex; justify-content: center; }
.sidebar.collapsed .sidebar-nav a { padding: 14px; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-nav a.active { padding-left: 14px; border-left: none; }
.sidebar.collapsed .sidebar-badge { display: none; }
.sidebar.collapsed .sidebar-bottom { padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sidebar.collapsed .sidebar-bottom .btn-txt { display: none; }
.sidebar.collapsed .sb-user { display: none; }
.sidebar-logo { padding: 16px 20px 20px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-logo img { height: 34px; filter: brightness(0) invert(1); opacity: .9; }
.sb-section-lbl {
  font-size: .62rem; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: #475569;
  padding: 14px 28px 4px; display: block;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px 9px 20px; margin: 1px 10px;
  color: var(--sidebar-tx); border-radius: 6px;
  text-decoration: none; font-size: .84rem; font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: rgba(37,99,235,.18); color: #93C5FD; }
.sidebar-nav a.active::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--blue); border-radius: 0 3px 3px 0;
}
.sidebar-nav a .bi { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-badge {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: .65rem; font-weight: 700;
}
.sidebar-bottom { margin-top: auto; padding: 12px 16px 16px; border-top: 1px solid rgba(255,255,255,.06); }
.sb-user {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 8px; background: rgba(255,255,255,.05); margin-bottom: 8px;
}
.sb-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .78rem; flex-shrink: 0;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { color: #E2E8F0; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { color: var(--sidebar-tx); font-size: .68rem; }
.sidebar.collapsed .btn-logout .btn-txt { display: none; }
.sidebar.collapsed .btn-logout { padding: 9px; justify-content: center; }

.main-content { flex: 1; background: var(--bg); overflow: hidden; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.page { padding: 24px; flex: 1; }
.page-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 20px; color: var(--text); letter-spacing: -.3px; }

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: .8rem; }
.topbar-breadcrumb span { color: var(--text2); }
.topbar-breadcrumb strong { color: var(--text); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge-live {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .7rem; font-weight: 600; color: var(--green);
  background: var(--green-dim); padding: 3px 9px; border-radius: 20px;
}
.badge-live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  animation: pulse-live 2s infinite;
}
@keyframes pulse-live { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Overlay sidebar mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 190;
}
.sidebar-overlay.open { display: block; }

/* ── Métricas ─────────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric-card { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); }
.metric-card .value { font-size: 1.8rem; font-weight: 800; }
.metric-card .label { font-size: .76rem; color: var(--text2); margin-top: 2px; }

/* ── KEY result ───────────────────────────────────────── */
.key-result { border-radius: 8px; padding: 12px 16px; font-size: .84rem; margin-top: 8px; display: none; }
.key-result.ok    { background: #d4f0d4; color: #1a5c1a; border: 1px solid #8DC63F; }
.key-result.error { background: #fde8e8; color: #8a0000; border: 1px solid var(--red); }
.key-field { display: flex; gap: 8px; align-items: flex-end; }
.key-field .form-control { flex: 1; }

/* ── Modal ────────────────────────────────────────────── */
.modal-bg {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 300;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--card); border-radius: var(--radius);
  padding: 24px; width: 100%; max-width: 520px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 18px; font-size: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ── Bars chart ───────────────────────────────────────── */
.bar-wrap { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.bar-label { width: 110px; font-size: .8rem; color: var(--text2); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 14px; background: var(--bg3); border-radius: 8px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 8px; transition: width .5s; }
.bar-val   { font-size: .78rem; font-weight: 700; min-width: 34px; }

/* ── Sections ─────────────────────────────────────────── */
.section-title { font-size: .82rem; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin: 18px 0 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 20px; right: 16px; left: 16px;
  max-width: 380px; margin: 0 auto;
  background: #1a1a2e; color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: .88rem; z-index: 9999;
  transform: translateY(100px); opacity: 0;
  transition: all .3s; text-align: center;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ── Chip ao vivo ─────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px;
  font-size: .72rem; font-weight: 700;
}
.chip-live   { background: #fde8e8; color: var(--red); }
.chip-cached { background: var(--bg3); color: var(--text2); }

/* Mobile topbar — oculto por padrão, visível via CSS no mobile */
.mobile-topbar { display: none; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE — 768px (tablet / mobile landscape)
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  .mobile-topbar { display: flex !important; }
  .hamburger { display: flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }

  .main-content { width: 100%; }

  .form-row { grid-template-columns: 1fr; }

  .page { padding: 16px; }
  .page-title { font-size: 1.1rem; }

  .metrics { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 14px; }
  .metric-card .value { font-size: 1.5rem; }

  .modal { padding: 20px; }
  .modal-footer { justify-content: stretch; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  .key-field { flex-direction: column; }
  .key-field .btn { width: 100%; justify-content: center; }

  .bar-label { width: 80px; font-size: .75rem; }

  .card { padding: 16px; }

  .header-title { font-size: .9rem; }
  .btn-sair span { display: none; }

  .table { min-width: 400px; }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE — 480px (mobile portrait)
══════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  :root { --header-h: 52px; }

  .header { padding: 0 12px; gap: 8px; }
  .header-logo { height: 30px; }
  .header-title { font-size: .82rem; }
  .theme-toggle { padding: 5px 8px; font-size: .75rem; }

  .metrics { grid-template-columns: 1fr; }

  .page { padding: 12px; }

  .bar-label { display: none; }
  .bar-wrap { gap: 6px; }

  .actions .btn { padding: 6px 8px; font-size: .76rem; }

  .toast { font-size: .82rem; padding: 10px 14px; }

  .login-wrap { padding: 12px; }
  .card { padding: 20px 16px; }

  .modal { padding: 16px; border-radius: 12px 12px 0 0; position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; }
  .modal-bg { align-items: flex-end; padding: 0; }
}
