/* ============================================================
   AGROVISION 2.0 — mobile.css
   Mobile-first: bottom nav, safe areas, transições de página,
   toasts, FAB, scroll snap, sheets, landscape mode
   ============================================================ */

/* ─── VARIÁVEIS MOBILE ───────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --nav-h: 54px;
    --bottom-nav-h: 66px;
  }
}

/* ─── MEDIA QUERY PRINCIPAL ──────────────────────────── */
@media (max-width: 768px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-x: clip;
    overscroll-behavior-x: none;
  }


  /* ── Visibilidade ─────────────────────────────────── */
  .desktop-only { display: none !important; }
  .mobile-only  { display: block !important; }

  /* ── Body ─────────────────────────────────────────── */
  body {
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }

  /* ── Header ───────────────────────────────────────── */
  .site-header {
    padding: 0 1rem;
    height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    gap: 0.62rem;
  }

  .brand-block {
    min-width: 0;
    flex: 0 0 auto;
  }
  .brand-name { font-size: 1.05rem; }
  .brand-logo { width: 28px; height: 28px; }

  .page-title {
    font-size: 0.7rem;
    flex: 0 1 clamp(112px, calc(50vw - 1rem), 47vw);
    max-width: clamp(112px, calc(50vw - 1rem), 47vw);
    margin-left: auto;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ── Main ─────────────────────────────────────────── */
  .page-main {
    width: 94vw;
    margin: 1rem auto calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1.2rem);
    animation: pageFadeIn 280ms var(--ease-out) both;
  }

  @keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* ── Surface Card ─────────────────────────────────── */
  .surface-card {
    padding: 1.1rem 1.2rem;
    border-radius: 18px;
  }
  /* Desativa hover lift — usa active no lugar */
  .surface-card:hover { transform: none; }
  .surface-card:active { transform: scale(0.99); box-shadow: var(--shadow-xs); }

  /* ── Section Title ────────────────────────────────── */
  .section-title { font-size: 1rem; }

  /* ── Stat Value ───────────────────────────────────── */
  .stat-value { font-size: 2.5rem; }

  /* ── Grids ────────────────────────────────────────── */
  .page-grid.grid-two,
  .page-grid.grid-three { grid-template-columns: 1fr; }

  .page-grid.grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  /* Bento grid vira 2 colunas */
  .bento-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .bento-col-3, .bento-col-4, .bento-col-5,
  .bento-col-6, .bento-col-7, .bento-col-8,
  .bento-col-12 { grid-column: span 2; }

  /* ── Botões ───────────────────────────────────────── */
  .btn, button, .desktop-btn {
    padding: 0.65rem 1rem;
    font-size: 0.8rem;
    -webkit-tap-highlight-color: transparent;
  }
  .btn:active, button:active { transform: scale(0.94); transition-duration: 80ms; }

  .actions-row .btn,
  .actions-row button {
    flex: 1;
    justify-content: center;
    font-size: 0.78rem;
  }

  .dashboard-ai-state {
    font-size: 0.82rem;
    margin-bottom: 0.55rem;
  }

  .dashboard-ai-text {
    min-height: 3rem;
  }

  /* ── Inputs ───────────────────────────────────────── */
  input, select, textarea {
    font-size: 16px; /* evita zoom automático iOS */
    padding: 0.75rem 0.9rem;
  }

  /* ── Chat ─────────────────────────────────────────── */
  .chatbox {
    min-height: 300px;
    max-height: 50vh;
    border-radius: 16px;
  }
  .message { max-width: 86%; font-size: 0.85rem; }
  .chat-form input { font-size: 16px; }

  /* ── Charts ───────────────────────────────────────── */
  .chart-box { min-height: 200px; }
  .chart-box canvas { height: 190px !important; }

  /* ── Upload ───────────────────────────────────────── */
  .upload-dropzone { padding: 1.8rem 1rem; }
  .upload-dropzone i { font-size: 2rem; }

  /* ── Monitor Grid ─────────────────────────────────── */
  .monitor-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .monitor-value { font-size: 1.5rem; }
  .monitor-card { border-radius: 16px; }

  /* ── Table ────────────────────────────────────────── */
  .table { font-size: 0.78rem; }
  .table th, .table td { padding: 0.5rem 0.65rem; }

  /* ── Record Card ──────────────────────────────────── */
  .record-card { padding: 0.9rem 1rem; border-radius: 16px; }
  .record-card h3 { font-size: 0.84rem; }

  /* ── Max-width ────────────────────────────────────── */
  .max-w-sm, .max-w-md { max-width: 100%; }

  /* ── Footer ───────────────────────────────────────── */
  .site-footer { display: none; }

  .dev-badge {
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 0.65rem);
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-width: none;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    font-size: 0.68rem;
    padding: 0.5rem 0.72rem;
  }
  .dev-badge-logo {
    width: 20px;
    height: 20px;
  }

  /* ── Loading Card ─────────────────────────────────── */
  .loading-card { min-width: 0; width: min(88vw, 260px); }

  /* ── Reveal — menor deslocamento no mobile ────────── */
  .reveal       { transform: translateY(16px); }
  .reveal-left  { transform: translateX(-16px); }
  .reveal-right { transform: translateX(16px); }

  /* ─────────────────────────────────────────────────────
     BOTTOM NAV — Coração da navegação mobile
  ──────────────────────────────────────────────────── */
  .bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--line);
    z-index: 90;
    display: grid !important;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    align-items: stretch;
    overflow-x: hidden;
    scrollbar-width: none;
    animation: slideUpNav 380ms 80ms var(--ease-spring) both;
    box-shadow: 0 -4px 24px rgba(30, 80, 50, 0.07);
  }

  @keyframes slideUpNav {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
  }

  /* Linha decorativa no topo do nav */
  .bottom-nav::before {
    content: '';
    position: absolute;
    top: 0;
    left: 15%; right: 15%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line-mid), transparent);
    pointer-events: none;
  }

  .bottom-nav::-webkit-scrollbar { display: none; }

  .bottom-nav-item {
    text-decoration: none;
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.2rem 0.45rem;
    min-width: 0;
    width: auto;
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0.2rem;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: color var(--dur-fast) var(--ease-out);
    overflow: hidden;
  }

  /* Ripple ao tocar */
  .bottom-nav-item::after {
    content: '';
    position: absolute;
    width: 44px; height: 28px;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--r-md);
    background: rgba(45, 122, 79, 0);
    transition: background var(--dur-fast);
  }
  .bottom-nav-item:active::after { background: rgba(45,122,79,0.1); }

  .bottom-nav-item:active { color: var(--brand); transform: scale(0.92); transition-duration: 80ms; }

  .bottom-nav-item i {
    font-size: 1.1rem;
    display: block;
    transition:
      transform var(--dur-mid) var(--ease-spring),
      color var(--dur-fast);
    position: relative;
    z-index: 1;
  }

  .bottom-nav-item span {
    display: block;
    text-align: center;
    line-height: 1;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Estado ativo */
  .bottom-nav-item.active { color: var(--brand); }

  /* Pílula de fundo no ativo */
  .bottom-nav-item.active::after {
    background: rgba(45, 122, 79, 0.1);
  }

  .bottom-nav-item.active i {
    color: var(--brand);
    transform: translateY(-2px) scale(1.12);
  }

  /* Indicador pontinho acima do ícone */
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 3px;
    background: var(--brand);
    border-radius: var(--r-full);
    animation: scaleIn 220ms var(--ease-spring) both;
  }

  /* ─────────────────────────────────────────────────────
     FAB — Floating Action Button
  ──────────────────────────────────────────────────── */
  .fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1rem);
    right: 1.1rem;
    width: 50px; height: 50px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    border: 0;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    cursor: pointer;
    z-index: 85;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--dur-fast) var(--ease-spring), box-shadow var(--dur-fast);
    animation: scaleIn 400ms 200ms var(--ease-spring) both;
  }
  .fab:active {
    transform: scale(0.88);
    box-shadow: var(--shadow-sm);
  }

  /* ─────────────────────────────────────────────────────
     TOAST NOTIFICATIONS
  ──────────────────────────────────────────────────── */
  .toast {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1rem);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    border-radius: var(--r-full);
    padding: 0.55rem 1.2rem;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 500;
    opacity: 0;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-spring);
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  .toast.success { background: var(--brand-2); }
  .toast.error   { background: var(--danger); }
  .toast.warning { background: var(--warning); }

  /* ─────────────────────────────────────────────────────
     MOBILE SHEET (modal inferior)
  ──────────────────────────────────────────────────── */
  .mobile-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-radius: var(--r-2xl) var(--r-2xl) 0 0;
    padding: 1.25rem 1.25rem calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 0.75rem);
    z-index: 200;
    box-shadow: 0 -12px 48px rgba(30,80,50,0.12);
    animation: sheetUp 300ms var(--ease-spring) both;
  }
  @keyframes sheetUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .mobile-sheet-handle {
    width: 36px; height: 4px;
    border-radius: var(--r-full);
    background: var(--line-mid);
    margin: 0 auto 1rem;
  }

  /* ─────────────────────────────────────────────────────
     SCROLL STRIP horizontal (snap)
  ──────────────────────────────────────────────────── */
  .scroll-strip {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
    margin: 0 -1.1rem;
    padding: 0 1.1rem 0.25rem;
  }
  .scroll-strip::-webkit-scrollbar { display: none; }
  .scroll-strip > * {
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  .strip-card {
    width: min(72vw, 220px);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    padding: 1rem;
    background: var(--surface);
    transition: border-color var(--dur-fast);
  }
  .strip-card:active { transform: scale(0.97); }

  /* ─────────────────────────────────────────────────────
     TABLE — vira cards no mobile pequeno
  ──────────────────────────────────────────────────── */
  @media (max-width: 480px) {
    .table-wrap { border: none; overflow: visible; }
    .table thead { display: none; }
    .table tbody tr {
      display: grid;
      grid-template-columns: 1fr;
      margin-bottom: 0.75rem;
      border: 1px solid var(--line);
      border-radius: var(--r-lg);
      overflow: hidden;
      background: var(--surface);
    }
    .table td {
      padding: 0.5rem 0.85rem;
      font-size: 0.8rem;
      border-bottom: 0;
    }
    .table td::before {
      content: attr(data-label);
      display: block;
      font-size: 0.65rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.07em;
      color: var(--muted-light);
      margin-bottom: 0.1rem;
    }
  }

  /* ─────────────────────────────────────────────────────
     REDUCED MOTION MOBILE
  ──────────────────────────────────────────────────── */
  @media (prefers-reduced-motion: reduce) {
    .bottom-nav  { animation: none; }
    .fab         { animation: none; }
    .page-main   { animation: none; }
    .mobile-sheet { animation: none; }
    .bottom-nav-item.active i { transform: none; }
    .bottom-nav-item.active::before { animation: none; }
  }

} /* end max-width: 768px */

/* ─── LANDSCAPE MOBILE ───────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  .chatbox { max-height: 42vh; min-height: 180px; }
  .page-main { margin-top: 0.75rem; }

  /* Nav horizontal em landscape */
  .bottom-nav {
    height: calc(52px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav-item {
    flex-direction: row;
    gap: 0.35rem;
    font-size: 0.65rem;
    min-width: 0;
    padding: 0.3rem 0.5rem;
    justify-content: center;
    align-items: center;
  }
  .bottom-nav-item i { font-size: 0.95rem; }
  .bottom-nav-item.active i { transform: scale(1.1); }
  .bottom-nav-item.active::before {
    top: auto;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 2px;
  }
}

/* ─── TABLET HÍBRIDO (769–1000px) ───────────────────── */
@media (min-width: 769px) and (max-width: 1000px) {
  .page-main { width: 96vw; margin: 1.25rem auto 2.5rem; }

  .top-nav { padding: 0 1.25rem; }
  .top-nav-item { padding: 0.8rem 0.75rem; font-size: 0.78rem; }
  /* Esconde label, mantém ícone */
  .top-nav-item span { display: none; }

  .stat-value { font-size: 2.4rem; }
  .surface-card { padding: 1.25rem 1.4rem; }

  .page-grid.grid-three { grid-template-columns: repeat(2, 1fr); }
  .page-grid.grid-auto  { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
