@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");

/* ─── RESET & BASE ───────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: #f1f3f4;
  color: #202124;
  visibility: hidden;
}
body.app-shell,
body.login-page { visibility: visible; }

/* App shell (applied by auth.js when sidebar is injected) */
body.app-shell {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── TOP BAR ────────────────────────────────── */
#ocb-platform-bar {
  height: 56px;
  min-height: 56px;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  padding: 0 8px;
  z-index: 12;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5f6368;
  transition: background 0.15s;
  flex-shrink: 0;
  padding: 0;
}
.btn-icon:hover { background: rgba(0,0,0,0.06); }
.btn-icon svg { width: 20px; height: 20px; }

.tv-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 4px;
  text-decoration: none;
  flex-shrink: 0;
}
.tv-brand img { height: 40px; width: auto; object-fit: contain; display: block; }
.tv-brand-text {
  font-size: 16px;
  font-weight: 500;
  color: #4a8679;
  white-space: nowrap;
  line-height: 1;
}

.unit-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 36px;
  border: 1px solid rgba(0,0,0,0.23);
  border-radius: 4px;
  cursor: pointer;
  background: #fff;
  font-size: 13px;
  color: #202124;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  margin-left: 8px;
}
.unit-selector:hover { background: rgba(0,0,0,0.04); border-color: #4a8679; }
.unit-selector svg { width: 16px; height: 16px; color: #5f6368; flex-shrink: 0; }
.unit-selector-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.unit-selector-label .label-prefix {
  color: #5f6368;
  margin-right: 4px;
  font-size: 12px;
}

.unit-switcher { position: relative; }
.unit-switcher-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border-radius: 8px;
  min-width: 240px;
  max-height: 360px;
  overflow-y: auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  z-index: 200;
  padding: 6px 0;
}
.unit-switcher.open .unit-switcher-menu { display: block; }
.unit-switcher-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 16px;
  background: none;
  border: none;
  color: #202124;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.unit-switcher-menu button:hover { background: rgba(0,0,0,0.05); }
.unit-switcher-menu button.active { color: #4a8679; font-weight: 500; background: #e8f3f0; }

.bar-spacer { flex: 1; }

.tv-account-link {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  height: 36px;
  border-radius: 18px;
  color: #5f6368;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.tv-account-link:hover { background: rgba(0,0,0,0.06); color: #202124; }

.btn-logout {
  height: 36px;
  padding: 0 16px;
  background: transparent;
  color: #4a8679;
  border: 1px solid rgba(74,134,121,0.4);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  margin-left: 4px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-logout:hover { background: rgba(74,134,121,0.08); border-color: #4a8679; }

/* ─── ROOT (sidebar + main) ──────────────────── */
#ocb-root-page {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── LEFT PANEL ────────────────────────────── */
#ocb-left-panel {
  width: 256px;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 14;
  position: relative;
}
#ocb-left-panel.collapsed { width: 0; }

.cfc-console-nav {
  width: 256px;
  height: 100%;
  background: #fff;
  border-right: 1px solid rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 8px;
}
.nav-scroll::-webkit-scrollbar { width: 6px; }
.nav-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }
.nav-scroll::-webkit-scrollbar-track { background: transparent; }

.nav-divider {
  height: 1px;
  background: rgba(0,0,0,0.12);
  margin: 8px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 8px 0 16px;
  cursor: pointer;
  border-radius: 0 20px 20px 0;
  margin-right: 8px;
  gap: 16px;
  color: #3c4043;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
  position: relative;
  text-decoration: none;
  user-select: none;
}
.nav-item:hover { background: rgba(0,0,0,0.06); }
.nav-item.active {
  background: #e8f3f0;
  color: #3e6d61;
  font-weight: 500;
}
.nav-item.active .nav-icon { color: #4a8679; }

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: #5f6368;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-icon svg { width: 20px; height: 20px; }

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-expand {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
  color: #5f6368;
  border-radius: 50%;
}
.nav-expand:hover { background: rgba(0,0,0,0.08); }
.nav-expand svg { width: 18px; height: 18px; }
.nav-expand.expanded { transform: rotate(180deg); }

.nav-subitems {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-subitems.open { max-height: 600px; }

.nav-subitem {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 8px 0 52px;
  cursor: pointer;
  border-radius: 0 18px 18px 0;
  margin-right: 8px;
  font-size: 13px;
  color: #3c4043;
  text-decoration: none;
  transition: background 0.15s;
  user-select: none;
}
.nav-subitem:hover { background: rgba(0,0,0,0.06); }
.nav-subitem.active {
  background: #e8f3f0;
  color: #3e6d61;
  font-weight: 500;
}

/* ─── CENTER PANEL ───────────────────────────── */
#ocb-center-panel {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  background: #f1f3f4;
}

/* ─── LAYOUT (content) ──────────────────────── */
main { max-width: 1100px; margin: 24px auto; padding: 0 24px; width: 100%; }

h1 { font-size: 1.5rem; font-weight: 500; margin-bottom: 20px; color: #202124; }

/* ─── BUTTONS ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  height: 36px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
.btn-primary { background: #4a8679; color: #fff; }
.btn-primary:hover { background: #3e6d61; box-shadow: 0 1px 4px rgba(74,134,121,0.4); }
.btn-success { background: #62af9c; color: #fff; }
.btn-success:hover { background: #4a8679; }
.btn-sm { height: 28px; padding: 0 12px; font-size: 12px; }

/* ─── TABLE ────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
th {
  background: #4a8679;
  color: #fff;
  padding: 12px 14px;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 500;
}
td { padding: 11px 14px; border-bottom: 1px solid #eee; font-size: 0.9rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8faf9; }

.stock-low { color: #c1121f; font-weight: 600; }

.badge { display:inline-block; padding:2px 10px; border-radius:12px; font-size:.75rem; font-weight:600; }
.badge-ok      { background:#d1fae5; color:#065f46; }
.badge-critico { background:#ffedd5; color:#9a3412; }
.badge-zerado  { background:#fee2e2; color:#991b1b; }

.order-link {
  color: #4a8679;
  font-weight: 500;
  text-decoration: none;
}
.order-link:hover { text-decoration: underline; }

/* ─── CARDS / FORMS ────────────────────────── */
.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  padding: 28px;
  max-width: 560px;
}
.form-group { margin-bottom: 18px; }
label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 6px; color: #3c4043; }
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #dadce0;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: #202124;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #4a8679;
  box-shadow: 0 0 0 2px rgba(74,134,121,0.2);
}

.item-row { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-end; }
.item-row select { flex: 1; }
.item-row input[type=number] { width: 90px; flex: none; }
.item-row .btn { flex: none; }

/* ─── ALERTS ───────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.alert-success { background: #dcefe9; color: #3e6d61; }
.alert-error   { background: #ffe8e8; color: #7f1d1d; }

.header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.header-row h1 { margin: 0; }

#loading { color: #5f6368; font-size: 0.9rem; margin-bottom: 12px; }

/* ─── ROLE BADGES ──────────────────────────── */
.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 500;
}
.role-master     { background: #3e6d61; color: #fff; }
.role-aprovador  { background: #4a8679; color: #fff; }
.role-gerente    { background: #62af9c; color: #3e6d61; }
.role-estoquista { background: #dcefe9; color: #3e6d61; }
.role-rh         { background: #e0e7ff; color: #3730a3; }

/* ─── LOGIN PAGE (kept apart from app-shell) ─ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f1f3f4;
}
.login-container { width: 100%; max-width: 400px; padding: 16px; }
.login-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  padding: 40px 36px;
}
.login-title {
  color: #4a8679;
  font-size: 1.6rem;
  font-weight: 500;
  text-align: center;
  margin-bottom: 6px;
}
.login-subtitle {
  color: #5f6368;
  text-align: center;
  font-size: 0.9rem;
  margin-bottom: 28px;
}

/* ─── PAGINATION ───────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 4px;
  justify-content: center;
}
.btn-page {
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: 4px;
  padding: 5px 16px;
  cursor: pointer;
  font-size: .85rem;
  color: #3c4043;
  transition: background .12s;
}
.btn-page:hover:not([disabled]) { background: #f3f4f6; }
.btn-page[disabled] { opacity: .4; cursor: default; }
.page-info { font-size: .85rem; color: #5f6368; min-width: 120px; text-align: center; }

/* ─── VALIDITY STATUS BADGES ──────────────── */
.st { display:inline-block; padding:2px 9px; border-radius:10px; font-size:.75rem; font-weight:600; white-space:nowrap; }
.st-ok      { background:#d1fae5; color:#065f46; }
.st-soon    { background:#fef3c7; color:#92400e; }
.st-overdue { background:#fee2e2; color:#b91c1c; }
.st-none    { color:#bbb; font-size:.82rem; }

/* ─── EMPLOYEE STATUS BADGES ──────────────── */
.emp-status { display:inline-block; padding:2px 10px; border-radius:10px; font-size:.75rem; font-weight:600; white-space:nowrap; }
.emp-status-ativo        { background:#d1fae5; color:#065f46; }
.emp-status-experiencia  { background:#dbeafe; color:#1e40af; }
.emp-status-afastado     { background:#fef3c7; color:#92400e; }
.emp-status-desligado    { background:#e5e7eb; color:#4b5563; }

/* ─── FORM PERSIST BANNER ─────────────────── */
.persist-banner {
  background: #fef9c3; color: #713f12;
  border-left: 4px solid #ca8a04; border-radius: 6px;
  padding: 8px 12px; font-size: .85rem;
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.persist-banner button {
  background: none; border: 1px solid #92400e; color: #92400e;
  border-radius: 4px; padding: 2px 8px; cursor: pointer; font-size: .8rem;
}

/* ═════════════════════════════════════════════════════════════════
   RESPONSIVIDADE MOBILE
   Toda regra abaixo só ativa em telas <768px (ou <480px).
   Desktop ≥1024px ignora 100% deste bloco — layout atual preservado.
   ═════════════════════════════════════════════════════════════════ */

/* ─── Sidebar overlay backdrop (sempre presente, só visível em mobile) ─── */
.sidebar-backdrop {
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
  display: none;
}

@media (max-width: 768px) {
  /* ─── Shell: sidebar vira overlay slide-in ─── */
  #ocb-left-panel {
    position: fixed;
    top: 56px; left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.15);
    z-index: 100;
  }
  /* legacy: classe .collapsed (vinda de uso anterior em desktop) também esconde no mobile */
  #ocb-left-panel.collapsed { transform: translateX(-100%); }
  /* .open tem precedência — declarada por último para sobrescrever .collapsed se ambas existirem */
  #ocb-left-panel.open { transform: translateX(0); }

  .sidebar-backdrop.visible { display: block; }

  #ocb-center-panel { width: 100%; }

  /* ─── Topbar compacta ─── */
  #ocb-platform-bar { padding: 0 4px; gap: 4px; }
  .tv-brand img { height: 32px; }
  .tv-brand-text { display: none; }
  .tv-account-link {
    font-size: 12px;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .unit-selector {
    max-width: 140px;
    padding: 0 8px;
    font-size: 12px;
  }
  .unit-selector svg:last-child { display: none; }
  .btn-logout { padding: 0 12px; font-size: 12px; }

  /* ─── Tabelas: scroll horizontal automático ─── */
  /* 1) Wrappers explícitos (classe .table-scroll / .emp-tbl-wrap) */
  .table-scroll,
  .emp-tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  .table-scroll table,
  .emp-tbl-wrap > table {
    min-width: max-content;
  }
  .table-scroll::after,
  .emp-tbl-wrap::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 18px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,.07));
    pointer-events: none;
  }

  /* 2) Wrappers inline ([style*="overflow-x"]) — já usados em 29 views */
  [style*="overflow-x: auto"] > table,
  [style*="overflow-x:auto"] > table,
  [style*="overflow-x: scroll"] > table,
  [style*="overflow-x:scroll"] > table {
    min-width: max-content;
  }

  /* 3) Safety net: tabelas dentro de <main> sem wrapper viram block-scroll
        (display: block transforma a tabela num container rolável) */
  main > table,
  main > .form-card > table,
  main > section > table,
  main > div > table:not(.table-scroll table):not(.emp-tbl-wrap > table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }

  /* ─── Modais: ocupam quase toda a largura ─── */
  .modal-box {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    padding: 18px 16px !important;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
  .modal-grid {
    grid-template-columns: 1fr !important;
  }
  .modal-actions,
  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-actions button,
  .modal-footer button {
    flex: 1 1 100%;
  }

  /* ─── Forms ─── */
  .form-card {
    max-width: 100%;
    padding: 18px 14px;
  }
  .item-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .item-row > select,
  .item-row > input[type="text"],
  .item-row > input[type="email"],
  .item-row > input[type="date"] {
    flex: 1 1 100%;
    min-width: 0;
  }
  .item-row > input[type="number"] {
    flex: 0 1 100px;
    width: 100px;
  }

  /* ─── Headings + padding principal ─── */
  main { padding: 14px 12px; }
  main h1 { font-size: 1.3rem; }
  main h2 { font-size: 1.05rem; }

  /* ─── Charts (Chart.js) ─── */
  canvas.chart,
  .chart-card canvas,
  .charts-grid canvas {
    max-height: 220px !important;
  }
  .charts-grid {
    grid-template-columns: 1fr !important;
  }

  /* ─── Body lock quando sidebar aberta ─── */
  body.no-scroll { overflow: hidden; }
}

@media (max-width: 480px) {
  /* Topbar ainda mais enxuta */
  .unit-selector-label .label-prefix { display: none; }
  .unit-selector { max-width: 120px; }
  .tv-account-link { display: none; }
  .btn-logout { padding: 0 10px; font-size: 11px; }

  /* Filtros: stack vertical */
  .filter-row,
  .filters-row {
    flex-direction: column;
    align-items: stretch !important;
  }
  .filter-row > *,
  .filters-row > * {
    width: 100% !important;
    max-width: 100% !important;
  }
}
