/* MakerCutt Factory — estilos base */
:root { --brand: #1d72f1; }

* { -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }

/* Scrollbar sutil */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Transições suaves */
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Sidebar link ativo */
.nav-link.active {
  background: rgba(29,114,241,.12);
  color: #1d72f1;
  font-weight: 600;
}
.nav-link.active i { color: #1d72f1; }

/* Navegação em grupos (accordion) */
.nav-group-btn.active { color: #1d72f1; font-weight: 600; }
.nav-group-btn.active i { color: #1d72f1; }
.nav-sub-link.active {
  background: rgba(29,114,241,.12);
  color: #1d72f1;
  font-weight: 600;
}
.nav-sub-link.active i { color: #1d72f1; }
.nav-chevron { color: #94a3b8; }
.nav-sub { animation: fadeIn .18s ease; }
.rotate-180 { transform: rotate(180deg); }

/* ── Topbar compacta (layout alternativo, mais espaço útil) ───────────── */
.h-13 { height: 3.25rem; }
.topnav-bar { min-height: 3.25rem; }
.topnav-scroll { scrollbar-width: none; }
.topnav-scroll::-webkit-scrollbar { display: none; }

.topnav-item {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .4rem .7rem; border-radius: .5rem;
  font-size: .82rem; font-weight: 500; color: #475569;
  white-space: nowrap; transition: background .15s, color .15s;
}
.topnav-item:hover { background: #f1f5f9; color: #1d72f1; }
.topnav-item-active { background: rgba(29,114,241,.12); color: #1d72f1; font-weight: 600; }
.topnav-item-active i { color: #1d72f1; }
/* Em telas médias esconde o rótulo, deixa só o ícone (mais compacto) */
@media (min-width: 768px) and (max-width: 1180px) {
  .topnav-label { display: none; }
  .topnav-item { padding: .45rem .55rem; }
}

/* Dropdown das abas com filhos */
.topnav-group { position: relative; }
.topnav-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 220px; background: #fff;
  border: 1px solid #e2e8f0; border-radius: .6rem;
  box-shadow: 0 10px 30px -8px rgba(15,23,42,.25);
  padding: .35rem; z-index: 50;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
/* Abre por hover (desktop com mouse) OU pela classe .open (toque/clique) */
@media (hover: hover) {
  .topnav-group:hover > .topnav-dropdown { opacity: 1; visibility: visible; transform: none; }
}
.topnav-group.open > .topnav-dropdown { opacity: 1; visibility: visible; transform: none; }
.topnav-dropdown.right-0 { left: auto; right: 0; }

.topnav-drop-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .7rem; border-radius: .45rem;
  font-size: .82rem; color: #475569; transition: background .12s, color .12s;
}
.topnav-drop-item:hover { background: #f1f5f9; color: #1d72f1; }
.topnav-drop-item.active { background: rgba(29,114,241,.12); color: #1d72f1; font-weight: 600; }

/* Painel do drawer de notas: desliza da direita */
.notes-drawer-panel { animation: slideInRight .22s ease; }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: none; } }
.note-card { transition: box-shadow .15s; }
.note-card:hover { box-shadow: 0 4px 14px -6px rgba(15,23,42,.2); }

/* Sub-abas horizontais do grupo ativo (2º nível de navegação) */
.subtabs-bar {
  display: flex; align-items: center; gap: .5rem;
  margin: -0.25rem 0 1rem; padding-bottom: .5rem;
  border-bottom: 1px solid #e2e8f0; overflow: hidden;
}
.subtabs-title { font-size: .72rem; font-weight: 600; color: #94a3b8; flex-shrink: 0; }
.subtabs-scroll { display: flex; align-items: center; gap: .25rem; overflow-x: auto; }
.subtab {
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
  padding: .35rem .75rem; border-radius: .5rem; font-size: .8rem; font-weight: 500;
  color: #64748b; transition: background .15s, color .15s;
}
.subtab:hover { background: #f1f5f9; color: #334155; }
.subtab-active { background: rgba(29,114,241,.12); color: #1d72f1; font-weight: 600; }

/* Reordenação de abas por arrastar (topbar) */
.topnav-item[draggable="true"], .topnav-group[draggable="true"] { cursor: grab; }
.tab-dragging { opacity: .45; }
.topnav-scroll .topnav-item, .topnav-scroll .topnav-group { user-select: none; }

/* Badges de status */
.badge { display:inline-flex; align-items:center; gap:.35rem; padding:.15rem .6rem; border-radius:9999px; font-size:.72rem; font-weight:600; }
.badge-new     { background:#dbeafe; color:#1e40af; }
.badge-draft   { background:#f1f5f9; color:#475569; }
.badge-sent    { background:#fef9c3; color:#854d0e; }
.badge-closed  { background:#dcfce7; color:#166534; }
.badge-queued  { background:#e0e7ff; color:#3730a3; }
.badge-progress{ background:#fef3c7; color:#92400e; }
.badge-done    { background:#dcfce7; color:#166534; }
.badge-rejected{ background:#fee2e2; color:#b91c1c; }

/* Card hover */
.hover-lift { transition: box-shadow .18s ease, transform .18s ease; }
.hover-lift:hover { box-shadow: 0 8px 24px -8px rgba(0,0,0,.15); transform: translateY(-1px); }

/* Toast */
.toast { animation: fadeIn .2s ease; }

/* Loading spinner */
.spinner { border:3px solid #e2e8f0; border-top-color: var(--brand); border-radius:50%; width:2rem; height:2rem; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Inputs consistentes */
.field {
  width:100%; border:1px solid #cbd5e1; border-radius:.5rem; padding:.55rem .75rem;
  font-size:.9rem; outline:none; transition: border-color .15s, box-shadow .15s; background:#fff;
}
.field:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29,114,241,.15); }
.label { display:block; font-size:.8rem; font-weight:600; color:#475569; margin-bottom:.3rem; }

/* ═══════════════════════════════════════════════════════════════════════
 * MOBILE / PWA — Bottom Navigation Bar + ajustes de app
 * ═══════════════════════════════════════════════════════════════════════ */

/* Barra fixa inferior (só mobile; o md:hidden do HTML controla a exibição). */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: space-around;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 20px -8px rgba(0,0,0,.15);
  padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom, 0px));
  min-height: 58px;
}

/* Item padrão da barra (ícone + rótulo). Alvo de toque confortável. */
.bnav-item {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: .35rem .2rem; min-width: 0;
  color: #64748b; font-size: 0; text-decoration: none;
  transition: color .15s;
}
.bnav-item .bnav-icon { position: relative; font-size: 1.15rem; line-height: 1; }
.bnav-item .bnav-label { font-size: .66rem; font-weight: 600; letter-spacing: .01em; }
.bnav-item:active { color: #1d72f1; }
.bnav-item.active { color: #1d72f1; }
.bnav-item.active .bnav-icon::after {
  content: ''; position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -7px; width: 4px; height: 4px; border-radius: 9999px; background: #1d72f1;
}

/* Botão central elevado (Estoque) — destaque circular saindo da barra. */
.bnav-center {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
  gap: 2px; text-decoration: none; color: #64748b; min-width: 0;
  transform: translateY(-14px);
}
.bnav-center-btn {
  width: 52px; height: 52px; border-radius: 9999px;
  background: linear-gradient(135deg, #1d72f1, #165bde);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; box-shadow: 0 6px 16px -4px rgba(29,114,241,.55);
  border: 3px solid #fff; transition: transform .15s, box-shadow .15s;
}
.bnav-center:active .bnav-center-btn { transform: scale(.94); }
.bnav-center.active .bnav-center-btn { box-shadow: 0 8px 22px -4px rgba(29,114,241,.7); }
.bnav-center-label { font-size: .66rem; font-weight: 700; color: #1d72f1; margin-top: -2px; }

/* Badge (novos leads) sobre o ícone da barra inferior. */
.bnav-badge {
  position: absolute; top: -6px; right: -10px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9999px; background: #f43f5e; color: #fff;
  font-size: .62rem; font-weight: 700; line-height: 17px; text-align: center;
  border: 2px solid #fff;
}

/* Em telas médias+ a barra some (usa sidebar/topbar). Garante que o FAB de
 * notas não colida com a barra inferior no mobile. */
@media (max-width: 767px) {
  #notes-fab.fixed { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
}

/* ── Ajustes gerais de navegação mobile ──────────────────────────────── */
/* Tabelas largas: rolagem horizontal suave por toque em vez de "estourar". */
@media (max-width: 767px) {
  .table-responsive, .overflow-x-auto { -webkit-overflow-scrolling: touch; }
  /* Alvos de toque mínimos confortáveis em botões/links de ação. */
  button, .btn, a.nav-link, .subtab { touch-action: manipulation; }
}

/* Modo standalone (app instalado): esconde qualquer dica de "abrir no navegador"
 * e ajusta o respiro superior para a status bar do iOS. */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top, 0px); }
  .pwa-only { display: initial; }
  .browser-only { display: none; }
}

/* ── Robustez de layout no mobile (todas as páginas) ─────────────────────
 * Evita que conteúdo largo (tabelas, blocos pré-formatados) estoure a
 * largura da viewport e crie scroll horizontal na PÁGINA inteira. */
@media (max-width: 767px) {
  /* Nada deve empurrar a página além da largura da tela. */
  #app, main { max-width: 100vw; overflow-x: hidden; }
  /* Tabelas sem wrapper de scroll próprio ainda rolam sozinhas. */
  main table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  /* Quando a tabela JÁ está dentro de um wrapper .overflow-x-auto, mantém o
   * comportamento de tabela normal (o wrapper cuida da rolagem). */
  main .overflow-x-auto > table { display: table; white-space: normal; }
  /* Cabeçalhos de página e cards não podem forçar largura fixa. */
  main img, main svg, main canvas { max-width: 100%; height: auto; }
  /* Modais ocupam quase a tela e rolam internamente. */
  .modal-panel, [data-modal-panel] { max-height: 90vh; overflow-y: auto; }
}

/* ── Banner "Instalar app" (PWA) ─────────────────────────────────────────
 * Aparece acima da barra de navegação inferior no mobile. Discreto,
 * dispensável, e não reaparece por 14 dias após dispensa. */
.pwa-install-banner {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: flex; align-items: center; gap: .75rem;
  background: #ffffff; border: 1px solid #e2e8f0; border-radius: 14px;
  padding: .7rem .8rem; box-shadow: 0 12px 32px -10px rgba(0,0,0,.28);
  animation: pwaSlideUp .25s ease;
}
@keyframes pwaSlideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.pwa-ib-icon { width: 40px; height: 40px; border-radius: 9px; flex-shrink: 0; }
.pwa-ib-text { flex: 1 1 auto; min-width: 0; }
.pwa-ib-title { font-size: .9rem; font-weight: 700; color: #0f172a; }
.pwa-ib-sub { font-size: .74rem; color: #64748b; line-height: 1.2; margin-top: 1px; }
.pwa-ib-hint { font-size: .72rem; color: #475569; line-height: 1.35; margin-top: 5px; }
.pwa-ib-hint i { color: #1d72f1; }
.pwa-ib-btn {
  flex-shrink: 0; background: #1d72f1; color: #fff; border: 0;
  border-radius: 9px; padding: .5rem .9rem; font-size: .82rem; font-weight: 700;
  cursor: pointer; transition: background .15s;
}
.pwa-ib-btn:hover { background: #165bde; }
.pwa-ib-close {
  flex-shrink: 0; background: transparent; border: 0; color: #94a3b8;
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: .95rem;
  display: flex; align-items: center; justify-content: center;
}
.pwa-ib-close:hover { background: #f1f5f9; color: #475569; }
/* Em telas grandes o banner nunca aparece (é uma experiência mobile). */
@media (min-width: 768px) { .pwa-install-banner { display: none; } }

/* ═══════════════════════════════════════════════════════════════════════
 * APARÊNCIA — Tamanho de fonte + Tema escuro (noite/dia)
 * Preferências client-side (localStorage), aplicadas em <html> via theme.js.
 * ═══════════════════════════════════════════════════════════════════════ */

/* ── Escala de fonte ─────────────────────────────────────────────────────
 * Multiplica o rem base. Como a app usa unidades rem (text-sm, px em rem via
 * Tailwind), aumentar o font-size do :root escala quase tudo proporcionalmente. */
html { font-size: calc(16px * var(--font-scale, 1)); }

/* ── TEMA ESCURO ─────────────────────────────────────────────────────────
 * A app usa classes Tailwind fixas (bg-white, bg-slate-100, text-slate-800…).
 * Em vez de reescrever milhares de elementos, remapeamos aqui as classes de
 * cor mais usadas quando <html> tem a classe .theme-dark. Transição suave. */
html.theme-dark { color-scheme: dark; }
html.theme-dark body { background: #0f172a; color: #e2e8f0; }
html.theme-dark,
html.theme-dark body,
html.theme-dark .transition,
html.theme-dark [class*="bg-"],
html.theme-dark [class*="text-"],
html.theme-dark [class*="border-"] { transition: background-color .2s ease, color .2s ease, border-color .2s ease; }

/* Fundos claros → tons escuros */
html.theme-dark .bg-white { background-color: #1e293b !important; }
html.theme-dark .bg-slate-50 { background-color: #1e293b !important; }
html.theme-dark .bg-slate-100 { background-color: #0f172a !important; }
html.theme-dark .bg-slate-200 { background-color: #334155 !important; }
html.theme-dark .bg-gray-50 { background-color: #1e293b !important; }
html.theme-dark .bg-gray-100 { background-color: #0f172a !important; }
/* Fundos semitransparentes usados em barras "sticky" */
html.theme-dark .bg-white\/90,
html.theme-dark .bg-white\/80,
html.theme-dark .bg-white\/70 { background-color: rgba(30,41,59,.9) !important; }
html.theme-dark .bg-slate-50\/50,
html.theme-dark .bg-slate-50\/60 { background-color: rgba(30,41,59,.6) !important; }

/* Cartões de destaque coloridos ficam levemente translúcidos p/ manter contraste */
html.theme-dark .bg-brand-50 { background-color: rgba(29,114,241,.12) !important; }
html.theme-dark .bg-amber-50, html.theme-dark .bg-amber-50\/60 { background-color: rgba(245,158,11,.12) !important; }
html.theme-dark .bg-emerald-50 { background-color: rgba(16,185,129,.12) !important; }
html.theme-dark .bg-rose-50 { background-color: rgba(244,63,94,.12) !important; }
html.theme-dark .bg-sky-50 { background-color: rgba(56,189,248,.12) !important; }
html.theme-dark .bg-indigo-50 { background-color: rgba(99,102,241,.12) !important; }
html.theme-dark .bg-yellow-50, html.theme-dark .bg-yellow-100 { background-color: rgba(234,179,8,.12) !important; }

/* Textos escuros → claros */
html.theme-dark .text-slate-900,
html.theme-dark .text-slate-800,
html.theme-dark .text-slate-700,
html.theme-dark .text-gray-900,
html.theme-dark .text-gray-800,
html.theme-dark .text-gray-700 { color: #e2e8f0 !important; }
html.theme-dark .text-slate-600,
html.theme-dark .text-slate-500,
html.theme-dark .text-gray-600,
html.theme-dark .text-gray-500 { color: #94a3b8 !important; }
html.theme-dark .text-slate-400,
html.theme-dark .text-slate-300,
html.theme-dark .text-gray-400 { color: #64748b !important; }

/* Bordas claras → escuras */
html.theme-dark .border-slate-100,
html.theme-dark .border-slate-200,
html.theme-dark .border-slate-300,
html.theme-dark .border-gray-100,
html.theme-dark .border-gray-200,
html.theme-dark .border-gray-300 { border-color: #334155 !important; }

/* Campos de formulário */
html.theme-dark .field { background: #0f172a; border-color: #334155; color: #e2e8f0; }
html.theme-dark .field::placeholder { color: #64748b; }
html.theme-dark input, html.theme-dark select, html.theme-dark textarea { color-scheme: dark; }
html.theme-dark input:not([type=checkbox]):not([type=radio]),
html.theme-dark select,
html.theme-dark textarea {
  background-color: #0f172a !important; border-color: #334155 !important; color: #e2e8f0 !important;
}
html.theme-dark .label { color: #cbd5e1; }

/* Navegação */
html.theme-dark .topnav-item { color: #cbd5e1; }
html.theme-dark .topnav-item:hover { background: #334155; color: #59b0ff; }
html.theme-dark .topnav-dropdown { background: #1e293b; border-color: #334155; }
html.theme-dark .topnav-drop-item { color: #cbd5e1; }
html.theme-dark .topnav-drop-item:hover { background: #334155; color: #59b0ff; }
html.theme-dark .subtab { color: #94a3b8; }
html.theme-dark .subtab:hover { background: #334155; color: #e2e8f0; }
html.theme-dark .subtabs-bar { border-color: #334155; }
html.theme-dark .nav-link.active,
html.theme-dark .nav-sub-link.active,
html.theme-dark .topnav-item-active { background: rgba(89,176,255,.18); color: #8ecdff; }

/* Barra inferior mobile */
html.theme-dark .bottom-nav { background: #1e293b; border-color: #334155; }
html.theme-dark .bnav-item { color: #94a3b8; }

/* Scrollbar */
html.theme-dark ::-webkit-scrollbar-thumb { background: #475569; }
html.theme-dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Sombras mais discretas no escuro */
html.theme-dark .shadow, html.theme-dark .shadow-sm, html.theme-dark .shadow-md,
html.theme-dark .shadow-lg, html.theme-dark .shadow-xl { box-shadow: 0 4px 20px -6px rgba(0,0,0,.6) !important; }

/* Divisores e tabelas */
html.theme-dark .divide-slate-100 > * + *,
html.theme-dark .divide-slate-200 > * + * { border-color: #334155 !important; }
html.theme-dark table th { color: #94a3b8; }
html.theme-dark tr:hover .hover\:bg-slate-50:hover,
html.theme-dark .hover\:bg-slate-50:hover { background-color: #334155 !important; }
html.theme-dark .hover\:bg-slate-100:hover { background-color: #334155 !important; }

/* Modais (UI.modal usa bg-white) já cobertos por .bg-white acima. Overlay ok. */

/* FASE J3 — detalhamento de serviços (chevron rotaciona ao abrir o <details>) */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary > .fa-chevron-right { transform: rotate(90deg); }
