/* Raio-X Maxinutri — tema verde alinhado com Power BI */
:root {
  --mxn-green-darkest: #1b5e20;
  --mxn-green-dark: #2e7d32;
  --mxn-green: #388e3c;
  --mxn-green-light: #c8e6c9;
  --mxn-green-bg: #e8f5e9;
  --mxn-orange: #f57c00;
  --bg: #f5f7f6;
  --card-bg: #ffffff;
  --border: #e0e0e0;
  --text: #212121;
  --text-muted: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--mxn-green-dark); text-decoration: none; }

/* ========== LAYOUT ========== */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: 'sidebar header' 'sidebar main';
  height: 100vh;
}

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--mxn-green-darkest) 0%, var(--mxn-green-dark) 100%);
  color: white;
  padding: 18px 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 0 22px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 14px;
}
.sidebar-logo h1 {
  font-size: 20px; font-weight: 700; letter-spacing: 1px;
}
.sidebar-logo small { color: var(--mxn-green-light); font-size: 11px; }
.sidebar-nav { flex: 1; }
.sidebar-nav a {
  display: block;
  padding: 11px 22px;
  color: rgba(255,255,255,0.85);
  border-left: 3px solid transparent;
  font-size: 13px;
  transition: all 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.07); color: white; }
.sidebar-nav a.active {
  background: rgba(255,255,255,0.12);
  border-left-color: white;
  color: white;
  font-weight: 600;
}
.sidebar-foot {
  padding: 14px 22px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 12px;
  color: rgba(255,255,255,0.7);
}
.sidebar-foot .who { display: block; font-weight: 600; color: white; margin-bottom: 4px; }
.sidebar-foot a { color: var(--mxn-green-light); }

/* Header com slicers */
.app-header {
  grid-area: header;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 10px 22px;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 60px;
}
.app-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--mxn-green-darkest);
  margin-right: auto;
}
.slicer-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.slicer-bar select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
  min-width: 110px;
}

/* Tabelas com scroll horizontal sempre */
.chart-card > div[style*="overflow"] {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}
.table { min-width: 600px; }

/* Main content */
.app-main {
  grid-area: main;
  overflow-y: auto;
  padding: 22px;
}
.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--mxn-green-darkest);
  margin-bottom: 18px;
}

/* ========== KPI CARDS ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--mxn-green-dark);
}
.kpi.alt { border-left-color: var(--mxn-orange); }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--mxn-green-darkest); }
.kpi-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ========== CARDS DE GRÁFICO ========== */
.chart-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
.chart-grid.full { grid-template-columns: 1fr; }
.chart-grid.thirds { grid-template-columns: 1fr 1fr 1fr; }
.chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-height: 240px;
}
.chart-card h3 { font-size: 13px; color: var(--mxn-green-darkest); font-weight: 600; margin-bottom: 8px; }
.chart-card .sub { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; }

/* ========== TABELAS ========== */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table th {
  background: var(--mxn-green-bg);
  color: var(--mxn-green-darkest);
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 2px solid var(--mxn-green-light);
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table tbody tr:hover { background: var(--mxn-green-bg); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ========== LOGIN ========== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--mxn-green-darkest), var(--mxn-green-dark));
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.login-logo {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo h1 {
  color: var(--mxn-green-darkest);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
}
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-card label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  font-weight: 600;
}
.login-card input[type=text],
.login-card input[type=tel],
.login-card input[type=password] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 16px;
  font-family: inherit;
  letter-spacing: 0.5px;
}
.login-card input:focus { outline: none; border-color: var(--mxn-green-dark); box-shadow: 0 0 0 3px var(--mxn-green-light); }
.login-card input[name=code] {
  font-size: 22px;
  text-align: center;
  letter-spacing: 6px;
  font-weight: 600;
  font-family: 'Consolas', monospace;
}
.btn {
  display: inline-block;
  padding: 12px 18px;
  background: var(--mxn-green-dark);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  transition: background 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--mxn-green-darkest); }
.btn.secondary { background: white; color: var(--mxn-green-dark); border: 1px solid var(--mxn-green-dark); }
.btn.secondary:hover { background: var(--mxn-green-bg); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert.info { background: var(--mxn-green-bg); color: var(--mxn-green-darkest); border: 1px solid var(--mxn-green-light); }
.muted-link { display: block; text-align: center; margin-top: 14px; font-size: 12px; color: var(--text-muted); }
.muted-link a { color: var(--mxn-green-dark); }

/* ========== MODAL ========== */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: white;
  border-radius: 8px;
  max-width: 900px;
  width: 100%;
  max-height: 86vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  background: var(--mxn-green-bg);
}
.modal-head h3 { color: var(--mxn-green-darkest); flex: 1; font-size: 15px; }
.modal-head .close {
  background: none; border: none; font-size: 22px; color: var(--mxn-green-darkest);
  cursor: pointer; padding: 0 6px;
}
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  text-align: right;
  background: #fafafa;
}

/* Botão pequeno (drill-down) */
.btn-mini {
  background: var(--mxn-green-bg);
  color: var(--mxn-green-darkest);
  border: 1px solid var(--mxn-green-light);
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-mini:hover {
  background: var(--mxn-green-dark);
  color: white;
  border-color: var(--mxn-green-dark);
}

/* ========== DRAWER (filtros) ========== */
.drawer-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  display: none;
}
.drawer-bg.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: 380px; max-width: 100vw;
  background: white;
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 20px rgba(0,0,0,0.18);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 14px 18px;
  background: var(--mxn-green-bg);
  border-bottom: 1px solid var(--mxn-green-light);
  display: flex; align-items: center;
}
.drawer-head h3 { color: var(--mxn-green-darkest); flex: 1; font-size: 14px; }
.drawer-head .close {
  background: none; border: none; font-size: 22px;
  color: var(--mxn-green-darkest); cursor: pointer;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.drawer-body label {
  display: block; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; font-weight: 600; margin: 12px 0 4px;
  letter-spacing: 0.5px;
}
.drawer-body label:first-child { margin-top: 0; }
.drawer-body select, .drawer-body input[type=text] {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; background: white;
}
.drawer-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}
.drawer-foot .btn { padding: 10px; }

/* Botão funil + ações */
.action-btn {
  background: white;
  border: 1px solid var(--mxn-green-dark);
  color: var(--mxn-green-dark);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.action-btn:hover { background: var(--mxn-green-bg); }
.action-btn.primary { background: var(--mxn-green-dark); color: white; }
.action-btn.primary:hover { background: var(--mxn-green-darkest); }
.action-btn .badge {
  background: var(--mxn-orange);
  color: white;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
}

/* ========== CHIPS (Mostrar por) ========== */
.chips {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  margin-bottom: 12px;
}
.chips-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; margin-right: 6px;
}
.chip {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--mxn-green-dark); }
.chip.active {
  background: var(--mxn-green-dark);
  color: white;
  border-color: var(--mxn-green-dark);
}

/* ========== AUTOCOMPLETE / TYPEAHEAD ========== */
.typeahead {
  position: relative;
  width: 100%;
}
.typeahead input {
  width: 100%;
}
.typeahead-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: white;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 4px 4px;
  max-height: 280px; overflow-y: auto;
  z-index: 50;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.typeahead.open .typeahead-list { display: block; }
.typeahead-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.typeahead-item:hover { background: var(--mxn-green-bg); }
.typeahead-item .meta { font-size: 11px; color: var(--text-muted); }
.typeahead-item.empty { color: var(--text-muted); font-style: italic; cursor: default; }

/* Esconde header slicers quando .with-drawer-only */
.app-shell.drawer-mode .app-header .slicer-bar { display: none; }

/* ========== RESPONSIVO ========== */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 60px 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar-nav a { padding: 11px 6px; text-align: center; font-size: 10px; line-height: 1.2; }
  .sidebar-logo { padding: 12px 6px; }
  .sidebar-logo h1 { font-size: 13px; }
  .sidebar-logo small { display: none; }
  .sidebar-foot { padding: 10px 6px; font-size: 10px; }
  .sidebar-foot .who { font-size: 11px; }

  .app-header {
    height: auto;
    min-height: 60px;
    padding: 8px 12px;
    align-items: flex-start;
  }
  .app-title { width: 100%; margin: 4px 0; font-size: 14px; }
  .slicer-bar { width: 100%; gap: 6px; }
  .slicer-bar select { font-size: 12px; padding: 6px 8px; min-width: 90px; flex: 1 1 auto; }

  .app-main { padding: 12px; }
  .chart-grid, .chart-grid.thirds { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 16px; }
  .kpi-label { font-size: 10px; }

  .modal { max-width: 100vw; max-height: 92vh; border-radius: 0; }
  .modal-head h3 { font-size: 13px; }
  .modal-body { padding: 10px 12px; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
