/* =======================================================
   app.css — Mobile First
   Breakpoints: base (< 768px) → tablet (≥ 768px) → desktop (≥ 1024px)
   ======================================================= */

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

:root {
  /* ─── Paleta Almeida Consultoria Saúde ─────────────
     --blue* agora referem-se ao laranja institucional.
     Nomes mantidos para compatibilidade com o código. */
  --blue:     #F7931E;   /* laranja principal (Almeida) */
  --blue-l:   #FEF3C7;   /* laranja claro (backgrounds suaves) */
  --blue-d:   #D97706;   /* laranja escuro (hover/pressed) */
  --green:    #1B5E20;
  --green-l:  #E8F5E9;
  --red:      #B71C1C;
  --red-l:    #FFEBEE;
  --amber:    #E65100;
  --amber-l:  #FFF8E1;
  --gray-50:  #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-400: #94A3B8;
  --gray-600: #475569;
  --gray-800: #0F2942;   /* navy escuro do sidebar Almeida */
  --surface:  #FFFFFF;
  --bg:       #F0F4F8;
  --header-h: 56px;
  --sidebar-w: 200px;
  --toggle-size: 36px;
  --radius:   8px;
  --shadow:   0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:0 10px 30px rgba(0,0,0,.18);
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--gray-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==============================================
   Layout (Mobile First)
   ============================================== */

.app-wrap { display: flex; min-height: 100vh; position: relative; }

/* Sidebar — por padrão no mobile fica OCULTO (fora da tela) */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--gray-800);
  color: #CBD5E1;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(-100%);
  transition: transform .25s ease;
  box-shadow: var(--shadow-lg);
}
.app-wrap.sidebar-open .sidebar { transform: translateX(0); }

/* Backdrop escuro ao abrir sidebar no mobile */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.app-wrap.sidebar-open .sidebar-backdrop {
  opacity: 1;
  visibility: visible;
}

.sidebar-brand {
  padding: 14px 12px;                 /* padding reduzido */
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  letter-spacing: .3px;
}
.sidebar-brand span { font-size: 11px; font-weight: 400; color: #94A3B8; display: block; }

.sidebar-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748B;
  padding: 12px 12px 3px;             /* reduzido */
}

.sidebar nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;                  /* reduzido (era 9px 16px) */
  color: #CBD5E1;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active {
  background: rgba(21,101,192,.25);
  border-left-color: #F7931E;
  color: #fff;
}
.sidebar nav a svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 12px;
  font-size: 12px;
  color: #64748B;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer strong { color: #CBD5E1; }
.footer-sair { color: #EF4444 !important; }
.footer-suporte { color: #90CAF9 !important; font-size: 12px; }

/* =======================================================
   Botão toggle do sidebar — CENTRALIZADO NA VERTICAL,
   cortando a borda do sidebar (metade dentro/metade fora)
   ======================================================= */
.sidebar-toggle {
  position: fixed;
  left: 0;                       /* mobile: encosta na borda esquerda */
  top: 50%;
  transform: translateY(-50%);
  width: var(--toggle-size);
  height: 56px;
  border: none;
  background: var(--blue);
  color: #fff;
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 250;
  transition: left .25s ease, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-toggle:hover  { background: var(--blue-d); }
.sidebar-toggle:active { filter: brightness(.9); }
.sidebar-toggle .icon-close { display: none; }
.sidebar-toggle .icon-open  { display: block; }
.app-wrap.sidebar-open .sidebar-toggle .icon-close { display: block; }
.app-wrap.sidebar-open .sidebar-toggle .icon-open  { display: none; }

/* Main */
.main-wrap {
  margin-left: 0;               /* no mobile o sidebar é overlay */
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;                 /* impede overflow horizontal */
}

/* Topbar */
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 50px;        /* espaço p/ o botão toggle à esquerda */
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 8px;
}
.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-date  { display: none; }                /* esconde data no mobile */

/* Content */
.content { padding: 14px; flex: 1; min-width: 0; }

/* =======================================================
   Cards
   ======================================================= */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}
.card-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--gray-800); }
.card-body { padding: 14px; }
.card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* KPI Cards — mobile 1 coluna, depois 2 e 5 */
.kpi-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 10px; font-weight: 700; text-transform: uppercase;
             letter-spacing: .6px; color: var(--gray-600); margin-bottom: 4px; }
.kpi-value { font-size: 20px; font-weight: 700; color: var(--blue); line-height: 1.2; }
.kpi-value.green  { color: var(--green); }
.kpi-value.red    { color: var(--red); }
.kpi-value.amber  { color: var(--amber); }
.kpi-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* Progress bar */
.progress { background: var(--gray-200); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 99px; transition: width .4s; background: var(--blue); }
.progress-bar.green  { background: var(--green); }
.progress-bar.red    { background: var(--red); }
.progress-bar.amber  { background: var(--amber); }

/* =======================================================
   Tables
   ======================================================= */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-600);
  text-align: left;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: 9px 10px; font-size: 13px; vertical-align: middle; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-mono { font-family: "JetBrains Mono", monospace; font-size: 12px; }

/* =======================================================
   Badges
   ======================================================= */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap;
}
.badge-blue   { background: var(--blue-l);  color: var(--blue-d); }
.badge-green  { background: var(--green-l); color: var(--green);  }
.badge-red    { background: var(--red-l);   color: var(--red);    }
.badge-amber  { background: var(--amber-l); color: var(--amber);  }
.badge-gray   { background: var(--gray-100);color: var(--gray-600);}

/* =======================================================
   Buttons — alvo de toque 40px+ no mobile
   ======================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  min-height: 40px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; transition: filter .15s, opacity .15s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(.92); text-decoration: none; }
.btn:active{ filter: brightness(.86); }
.btn-primary  { background: var(--blue);   color: #fff; }
.btn-success  { background: var(--green);  color: #fff; }
.btn-danger   { background: var(--red);    color: #fff; }
.btn-warning  { background: var(--amber);  color: #fff; }
.btn-ghost    { background: var(--gray-100); color: var(--gray-600); }
.btn-sm       { padding: 6px 10px; min-height: 32px; font-size: 12px; }
.btn-icon     { padding: 6px; min-width: 32px; min-height: 32px; }

/* =======================================================
   Forms
   ======================================================= */
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
label { font-size: 12px; font-weight: 600; color: var(--gray-600); }

input, select, textarea {
  padding: 10px 12px;              /* alvo de toque */
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 16px;                 /* evita zoom no iOS */
  background: var(--surface);
  color: var(--gray-800);
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21,101,192,.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--gray-400); }

/* Filter bar — empilhado no mobile */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
.filter-bar .form-group { min-width: 0; }
.filter-bar select, .filter-bar input { width: 100%; }
.filter-bar label { font-size: 11px; }
.filter-bar .form-group:has(button) { grid-column: 1 / -1; }

/* =======================================================
   Alerts / Flash
   ======================================================= */
.alert {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: var(--green-l); color: var(--green); border: 1px solid #A5D6A7; }
.alert-danger   { background: var(--red-l);   color: var(--red);   border: 1px solid #EF9A9A; }
.alert-warning  { background: var(--amber-l); color: var(--amber); border: 1px solid #FFCC80; }
.alert-info     { background: var(--blue-l);  color: var(--blue);  border: 1px solid #90CAF9; }

/* =======================================================
   Individual Grid (somente visualização)
   ======================================================= */
.ind-section { margin-bottom: 24px; }
.ind-team-header {
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.ind-team-header span { font-size: 11px; font-weight: 400; opacity: .9; }

.ind-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch;
                 border: 1px solid var(--gray-200); border-radius: 0 0 var(--radius) var(--radius); }
.ind-table { border-collapse: collapse; white-space: nowrap; font-size: 12px; }
.ind-table th {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  padding: 6px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--gray-600);
  text-align: center;
}
.ind-table .th-nome {
  text-align: left;
  min-width: 130px;
  position: sticky; left: 0; z-index: 2;
  background: var(--gray-50);
}
.ind-table td { border: 1px solid var(--gray-200); padding: 0; vertical-align: middle; }
.ind-table .td-nome {
  padding: 4px 10px;
  font-weight: 600;
  min-width: 130px;
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
}
.ind-table .td-meta-mensal {
  padding: 4px 8px; text-align: right; font-weight: 600;
  color: var(--blue); min-width: 84px; background: var(--blue-l);
  font-family: "JetBrains Mono", monospace; font-size: 12px;
}

/* 3 sub-linhas (meta / produzido / saldo) */
.cell-day { width: 58px; min-width: 58px; }
.cell-row { display: flex; flex-direction: column; }
.row-meta {
  padding: 2px 4px; text-align: center; font-size: 10px;
  color: var(--gray-600); background: rgba(0,0,0,.03);
  border-bottom: 1px solid rgba(0,0,0,.06);
  font-family: "JetBrains Mono", monospace;
}
.row-prod {
  padding: 3px 4px; text-align: center; font-size: 12px;
  font-weight: 700; color: var(--gray-800);
  font-family: "JetBrains Mono", monospace;
  min-height: 22px; display: flex; align-items: center; justify-content: center;
}
.row-prod-empty { color: var(--gray-400); font-weight: 400; }
.row-deficit {
  padding: 2px 4px; text-align: center; font-size: 10px;
  font-weight: 700; border-top: 1px solid rgba(0,0,0,.06);
  min-height: 18px; display: flex; align-items: center; justify-content: center;
  font-family: "JetBrains Mono", monospace;
}

/* Estados */
.day-ok      { background: #F0FDF4; }
.day-deficit { background: #FFFBEB; }
.day-miss    { background: #FFF5F5; }
.day-future  { background: #EFF6FF; }
.deficit-val { color: var(--amber); }
.ok-val      { color: var(--green); }

/* Legenda */
.legend {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px; font-size: 11px;
}
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* Ranking */
.rank-pos { font-weight: 800; color: var(--gray-400); width: 28px; text-align: center; }
.rank-1   { color: #F59E0B; }
.rank-2   { color: #94A3B8; }
.rank-3   { color: #B45309; }

/* =======================================================
   Dashboard grid
   ======================================================= */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* =======================================================
   Relatório Diário — view grid
   ======================================================= */
.reldiario-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
.reldiario-texto textarea {
  width: 100%; min-height: 280px;
  font-size: 12px; font-family: monospace;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px; background: var(--gray-50);
  resize: vertical;
  color: var(--gray-800); line-height: 1.6;
}

/* =======================================================
   Login
   ======================================================= */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0F2942 0%, #1E4169 100%);
  padding: 16px;
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 20px; font-weight: 800; color: var(--gray-800); }
.login-logo p  { font-size: 13px; color: var(--gray-400); margin-top: 4px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
  padding: 12px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 14px; }

/* Utilities */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.flex-end { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.w-full { width: 100%; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--gray-400); }
.text-bold { font-weight: 700; }
.hidden { display: none; }

/* Section header (formulário do relatório diário) */
.section-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 2px solid;
}
.section-header.blue  { color: var(--blue);  border-color: var(--blue-l); }
.section-header.green { color: var(--green); border-color: var(--green-l); }
.section-header.amber { color: var(--amber); border-color: var(--amber-l); }

/* Badge de solicitações pendentes (vermelho pulsante no menu) */
.badge-pendente {
  background: var(--red);
  color: #fff;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
  min-width: 18px;
  text-align: center;
  animation: pulse-pendente 1.6s ease-in-out infinite;
}
@keyframes pulse-pendente {
  0%, 100% { box-shadow: 0 0 0 0 rgba(183,28,28,.55); }
  50%      { box-shadow: 0 0 0 6px rgba(183,28,28,0); }
}
.sidebar nav a { justify-content: flex-start; }
.sidebar nav a .badge-pendente { margin-left: auto; }

/* Senha plain visível para o master */
.password-chip {
  display: inline-block;
  background: var(--amber-l); color: var(--amber);
  padding: 2px 6px; border-radius: 4px;
  font-size: 11px; font-family: "JetBrains Mono", monospace;
}

/* =======================================================
   TABLET (≥ 768px)
   ======================================================= */
@media (min-width: 768px) {
  :root { --header-h: 58px; }

  .content { padding: 20px; }
  .topbar { padding: 0 20px 0 56px; }
  .topbar-title { font-size: 16px; }
  .topbar-date { display: inline; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-value { font-size: 22px; }

  .form-grid-2 { grid-template-columns: 1fr 1fr; }
  .form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .form-grid-4 { grid-template-columns: repeat(2, 1fr); }

  .filter-bar {
    display: flex; flex-wrap: wrap; align-items: flex-end;
    padding: 14px 18px;
  }
  .filter-bar .form-group { min-width: 130px; flex: 0 1 auto; }
  .filter-bar .form-group:has(button) { grid-column: auto; }

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

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

/* =======================================================
   DESKTOP (≥ 1024px)
   ======================================================= */
@media (min-width: 1024px) {
  /* Sidebar permanente em desktop */
  .sidebar {
    transform: translateX(0);
    box-shadow: none;
  }
  .sidebar-backdrop { display: none !important; }

  .main-wrap { margin-left: var(--sidebar-w); transition: margin-left .25s ease; }
  .topbar    { padding: 0 24px 0 24px; }   /* sem espaço extra: topbar limpa */

  /* Botão toggle cortando a borda: metade dentro / metade fora do sidebar */
  .sidebar-toggle {
    left: var(--sidebar-w);
    transform: translate(-50%, -50%);
    border-radius: var(--radius);
    transition: left .25s ease, transform .25s ease, background .15s;
  }

  /* Estado "collapsed" — sidebar oculto, botão desliza p/ esquerda */
  .app-wrap.sidebar-collapsed .sidebar   { transform: translateX(-100%); }
  .app-wrap.sidebar-collapsed .main-wrap { margin-left: 0; }
  .app-wrap.sidebar-collapsed .sidebar-toggle {
    left: 0;
    transform: translate(0, -50%);
    border-radius: 0 var(--radius) var(--radius) 0;
  }

  /* Ícones do botão no desktop — aberto vs fechado invertidos */
  .sidebar-toggle .icon-close { display: block; }
  .sidebar-toggle .icon-open  { display: none; }
  .app-wrap.sidebar-collapsed .sidebar-toggle .icon-close { display: none; }
  .app-wrap.sidebar-collapsed .sidebar-toggle .icon-open  { display: block; }

  .content { padding: 24px; }
  .topbar  { padding: 0 24px; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .form-grid-4 { grid-template-columns: repeat(4, 1fr); }

  .dash-grid { grid-template-columns: 1fr 1.6fr; }
  .reldiario-grid { grid-template-columns: 1fr 380px; }

  .cell-day { width: 64px; min-width: 64px; }
}
