/* ==========================================================
   LOOM — DESIGN SYSTEM — ESTILOS GLOBAIS (global.css)
   ========================================================== */

/* ===================== DESIGN TOKENS ===================== */
:root {
  --orange: #18181B;
  --orange-light: #27272A;
  --orange-dark: #09090B;
  --orange-faded: rgba(24,24,27,0.06);

  --bg: #EEF1F5;
  --bg2: #E4E8EE;
  --surface: #FFFFFF;
  --surface2: #F4F6FA;
  --sidebar: #FFFFFF;
  --border: rgba(0,0,0,0.08);
  --shadow: 0 2px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);

  --text: #1A1A2E;
  --text2: #4A5568;
  --text3: #8A94A6;
  --text-inv: #FFFFFF;

  --green: #0EA05A;
  --green-faded: rgba(14,160,90,0.12);
  --red: #E53E3E;
  --red-faded: rgba(229,62,62,0.12);
  --amber: #D97706;
  --amber-faded: rgba(217,119,6,0.12);
  --blue: #3B82F6;
  --blue-faded: rgba(59,130,246,0.12);

  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --transition: all 0.22s cubic-bezier(0.4,0,0.2,1);
  --nav-w: 96px;
}

[data-theme="dark"] {
  --orange: #F4F4F5;
  --orange-light: #E4E4E7;
  --orange-dark: #FAFAFA;
  --orange-faded: rgba(244,244,245,0.08);
  --bg: #09090B;
  --bg2: #18181B;
  --surface: #121214;
  --surface2: #1C1C1E;
  --sidebar: #121214;
  --border: rgba(255,255,255,0.15);
  --shadow: none;
  --shadow-lg: none;
  --text: #FFFFFF;
  --text2: #F4F5F7;
  --text3: #A1A1B2;
  --text-inv: #09090B;
}

/* ===================== RESET ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh; min-height: 100dvh;
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: inherit; outline: none; }
a { text-decoration: none; color: inherit; }

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===================== APP LAYOUT ===================== */
#app { display: none; min-height: 100vh; min-height: 100dvh; }
#app.active { display: flex; }

/* ===================== SIDEBAR NAV ===================== */
.sidebar {
  width: var(--nav-w); min-height: 100vh; min-height: 100dvh;
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0; position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
  transition: background 0.3s, border-color 0.3s;
  box-shadow: 2px 0 12px rgba(0,0,0,0.04);
}
.sidebar-logo-img {
  width: 84px;
  height: auto;
  margin-bottom: 28px;
  filter: contrast(1.4) brightness(1.15);
  mix-blend-mode: multiply;
}
[data-theme="dark"] .sidebar-logo-img {
  filter: invert(1) contrast(1.4) brightness(1.15);
  mix-blend-mode: screen;
}
.nav-group { flex: 1; display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0 10px; }
.nav-item {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text3); transition: var(--transition); cursor: pointer;
  position: relative; margin: 0 auto;
}
.nav-item:hover { background: var(--orange-faded); color: var(--orange); }
.nav-item.active { background: var(--orange); color: var(--text-inv); box-shadow: none; }
.nav-item svg { width: 22px; height: 22px; }
.nav-tooltip {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: var(--text-inv); font-size: 0.75rem;
  font-weight: 600; padding: 5px 10px; border-radius: 6px;
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity 0.15s; z-index: 200;
}
.nav-item:hover .nav-tooltip { opacity: 1; }

.sidebar-bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 10px; }
.theme-toggle {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text3); background: var(--surface2); cursor: pointer;
  transition: var(--transition); border: none;
}
.theme-toggle:hover { background: var(--orange-faded); color: var(--orange); }
.user-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--orange); color: var(--text-inv); font-size: 0.8rem;
  font-weight: 800; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition); border: 2px solid transparent;
  position: relative;
}
.user-avatar:hover { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-faded); }

/* ===================== MAIN CONTENT ===================== */
.main {
  margin-left: var(--nav-w); flex: 1; min-width: 0;
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
}
.page { display: none; flex: 1; min-width: 0; padding: 28px 32px; animation: fadeIn 0.25s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== RESPONSIVE GENERAL ===================== */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  :root { --nav-w: 60px; }
  .page { padding: 20px 16px; }
  .agenda-layout { grid-template-columns: minmax(0, 1fr); }
  .fin-layout { grid-template-columns: minmax(0, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
  #settings-modal .modal {
    flex-direction: column !important;
    height: 90vh !important;
    max-height: none !important;
  }
  #settings-modal .modal > div:first-child {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    padding: 10px 14px !important;
    align-items: center !important;
  }
  #settings-modal .modal > div:first-child > div:first-child {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
  }
  #settings-modal .modal > div:first-child > div:first-child > div {
    display: none !important;
  }
  .settings-tab {
    margin-bottom: 0 !important;
    white-space: nowrap !important;
    padding: 8px 12px !important;
    font-size: 0.78rem !important;
  }
  #settings-modal .modal > div:first-child > div:last-child {
    display: none !important;
  }
  #settings-modal .modal > div:last-child {
    padding: 20px 16px !important;
  }
}

@media (max-width: 600px) {
  .sidebar {
    width: 100% !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
    position: fixed !important;
    bottom: 0 !important;
    top: auto !important;
    left: 0 !important;
    flex-direction: row !important;
    justify-content: space-around !important;
    padding: 0 6px !important;
    border-right: none !important;
    border-top: 1px solid var(--border) !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08) !important;
    z-index: 999 !important;
    gap: 4px !important;
  }
  .main {
    margin-left: 0 !important;
    margin-bottom: 60px !important;
  }
  .sidebar-logo-img {
    display: none !important;
  }
  .nav-group {
    flex-direction: row !important;
    flex: 0 1 auto !important;
    width: auto !important;
    justify-content: space-around !important;
    gap: 0 !important;
    min-width: 0 !important;
  }
  .nav-item {
    width: 44px !important;
    height: 44px !important;
    margin-bottom: 0 !important;
    padding: 4px !important;
  }
  .nav-item svg {
    width: 19px !important;
    height: 19px !important;
  }
  .sidebar-bottom {
    flex-direction: row !important;
    gap: 8px !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
  }
  .theme-toggle {
    width: 36px !important;
    height: 36px !important;
  }
  .user-avatar {
    width: 36px !important;
    height: 36px !important;
  }
  .user-menu {
    bottom: 68px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
  }

  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  .fin-stats {
    grid-template-columns: 1fr !important;
  }
  .estoque-stats {
    grid-template-columns: 1fr !important;
  }
  .dash-grid {
    grid-template-columns: 1fr !important;
  }

  tbody td, thead th {
    padding: 8px 10px !important;
    font-size: 0.8rem !important;
  }
}


/* ===== BANNERS DE AVISO: faixa horizontal no topo, nao coluna ===== */
#trial-warning-banner,
#readonly-banner {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  order: -1;
}
#app { flex-wrap: wrap; }


/* ===== REFINAMENTO MOBILE (UX) ===== */
@media (max-width: 760px) {
  /* Fonte menor que 16px faz o iOS dar zoom automatico ao focar o campo.
     16px e o minimo que evita esse comportamento. */
  input, select, textarea { font-size: 16px !important; }

  /* Titulo longo quebra linha em vez de esticar a pagina */
  .page-title { font-size: 1.4rem; line-height: 1.25; overflow-wrap: anywhere; min-width: 0; }
  .page-header { flex-wrap: wrap; gap: 10px; }
  .page-header > * { min-width: 0; }

  /* Alvos de toque confortaveis (padrao de acessibilidade: 44px) */
  button, .btn, .nav-item, .icon-btn { min-height: 44px; }
  .nav-item { min-width: 44px; }

  /* Barra inferior respeitando a area segura do iPhone.
     Em Android e iPhones antigos env() vale zero, entao nada muda. */
  .sidebar {
    height: calc(60px + env(safe-area-inset-bottom)) !important;
    min-height: calc(60px + env(safe-area-inset-bottom)) !important;
    max-height: calc(60px + env(safe-area-inset-bottom)) !important;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Respiro entre o ultimo item e a navegacao */
  .main { margin-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* Toque mais limpo, sem o flash cinza do Android */
  * { -webkit-tap-highlight-color: transparent; }
}


/* ===== AGENDA E FINANCEIRO: uma coluna no celular ===== */
/* Em telas estreitas o layout de 2 colunas espremia o calendario e os
   graficos a poucos pixels. Aqui eles passam a empilhar. */
@media (max-width: 900px) {
  .agenda-layout,
  .fin-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px;
  }
  .agenda-layout > *,
  .fin-layout > * { min-width: 0; }

  /* Calendario ocupa a largura toda, com celulas confortaveis de tocar */
  .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)) !important; }
  .cal-grid > * { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; }

  /* Graficos nao podem estourar a largura do cartao */
  canvas { max-width: 100% !important; height: auto !important; }
}


/* ===== LOGIN: video no desktop, imagem no celular ===== */
/* O video tem 6MB. No celular ele era o maior peso da abertura,
   entao usamos a logo estatica (92KB) no lugar. */
.login-logo-img { display: none; }

@media (max-width: 760px) {
  .login-logo-video { display: none !important; }
  .login-logo-img {
    display: block;
    width: 100%;
    max-width: 220px;
    height: auto;
    margin: 0 auto;
    border-radius: 16px;
    object-fit: contain;
  }
}

/* ===== LOOM 25/08/2026 — densidade no celular ==========================
   Os cartões de número ocupavam a largura inteira, um por vez: para ver
   quatro contagens a pessoa rolava quatro telas. Em duas colunas cabem
   todos de uma vez, que é o ponto de um painel. */
@media (max-width: 600px) {
  .stats-grid,
  .fin-stats,
  .estoque-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .stat-card,
  .fin-stat,
  .estoque-stats > div {
    padding: 14px !important;
    min-height: 0 !important;
  }
  .stat-card .stat-value,
  .fin-stat-value {
    font-size: 1.25rem !important;
    line-height: 1.2 !important;
  }
  .stat-card .stat-label,
  .fin-stat-label {
    font-size: 0.65rem !important;
  }
  /* O círculo decorativo virava um borrão atrás do número nesse tamanho. */
  .stat-card .stat-bg {
    display: none !important;
  }

  /* Busca e filtro de categoria espremidos lado a lado cortavam os dois
     textos ("Pesquisar mate", "Todas as Categ"). Empilhados, cabem. */
  .estoque-filtros {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .estoque-filtros > select {
    width: 100% !important;
  }
}
