/* ============================================================
   RRi Agenda — Mobile CSS (Responsivo Completo)
   Desenvolvido por RR Intelligence
   ============================================================ */

html, body {
  overflow-x: hidden;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

.page-body,
.card,
.card-header,
.card-body,
.modal,
.table-wrapper {
  min-width: 0;
}

/* ===== BOTTOM NAV (só mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 66px;
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  z-index: var(--z-sidebar);
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
}

.bottom-nav-inner {
  display: grid;
  grid-template-columns: 1fr 1fr auto 1fr 1fr;
  align-items: center;
  justify-items: center;
  height: 66px;
  padding: 0 var(--space-2);
  gap: 0;
  width: 100%;   /* garante que o grid ocupa toda a largura do nav */
  flex: 1;       /* fallback quando bottom-nav é flex container */
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: var(--space-1) var(--space-1);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color 0.18s ease, transform 0.15s ease;
  text-decoration: none;
  width: 100%;
  min-height: 52px;
  position: relative;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.bottom-nav-item span {
  font-size: 10px;
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  max-width: 52px;
  text-align: center;
  line-height: 1.2;
}

.bottom-nav-item.active {
  color: var(--color-primary);
}

.bottom-nav-item.active svg {
  transform: scale(1.08);
  filter: drop-shadow(0 0 5px rgba(124,58,237,0.35));
}

.bottom-nav-item:active {
  transform: scale(0.9);
}

/* Indicador de ativo (bolinha roxa em cima do ícone) */
.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-primary);
}

/* Item oculto por permissão: mantém slot para não "embaralhar" ícones */
.bottom-nav-item.is-hidden-perm {
  visibility: hidden;
  pointer-events: none;
}

/* Botão central destacado (Agenda / FAB) */
.bottom-nav-fab {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 60%, #6D28D9 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124,58,237,0.45);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  position: relative;
  top: -4px; /* sobe levemente para destaque */
}

.bottom-nav-fab svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.bottom-nav-fab:active {
  transform: scale(0.91);
  box-shadow: 0 2px 10px rgba(124,58,237,0.3);
}

/* ===== BREAKPOINTS ===== */

/* --- Tablets (768px - 1024px) --- */
@media (max-width: 1024px) {
  .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
  .estoque-stats   { grid-template-columns: repeat(2, 1fr); }
  .config-layout   { grid-template-columns: 1fr; }
  .estoque-layout  { grid-template-columns: 1fr; }
}

/* --- Mobile (até 768px) --- */
@media (max-width: 768px) {
  :root {
    --topbar-height: 56px;
  }

  /* Sidebar vira drawer */
  .sidebar {
    transform: translateX(-100%);
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(86vw, 320px);
    z-index: var(--z-sidebar);
    transition: transform var(--transition-base);
    box-shadow: none;
  }

  .sidebar.open,
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  /* Overlay escuro quando sidebar aberta */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: calc(var(--z-sidebar) - 1);
    backdrop-filter: blur(2px);
  }

  .sidebar-overlay.active { display: block; }

  /* Conteúdo ocupa toda a largura */
  .app-content {
    margin-left: 0 !important;
    padding-bottom: 74px; /* espaço para bottom nav */
  }

  /* Bottom nav visível no mobile */
  .bottom-nav { display: flex; }

  /* Topbar mobile */
  .topbar {
    padding: 0 var(--space-3) 0 var(--space-2);
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    gap: var(--space-2);
  }

  .topbar-left {
    min-width: 0;
    flex: 1;
    gap: var(--space-1);
  }
  .topbar-right {
    gap: var(--space-2);
    margin-left: auto;
    flex-shrink: 0;
  }
  .topbar-title {
    font-size: 0.95rem;
    max-width: min(48vw, 200px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-date  { display: none; }

  /* Esconde botões secundários da topbar no mobile */
  .topbar-right .btn-ghost { display: none; }
  .topbar-right .btn-primary {
    position: relative !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    border-radius: var(--radius-full) !important;
    font-size: 0 !important;
    line-height: 0 !important;
    color: transparent !important;   /* esconde qualquer texto residual */
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(124,58,237,0.35);
    flex-shrink: 0;
  }
  /* SVG centralizado por posição absoluta — ignora texto no DOM */
  .topbar-right .btn-primary svg {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 20px !important;
    height: 20px !important;
    margin: 0 !important;
    display: block !important;
    color: #fff !important;
    stroke: #fff !important;
  }
  .topbar-right .btn-primary:active {
    transform: scale(0.92);
    box-shadow: 0 1px 6px rgba(124,58,237,0.25);
  }
  .topbar-right .btn-theme {
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
  }
  .logout-topbar {
    min-width: 36px;
    width: 36px;
    height: 36px;
    padding: 0 !important;
    justify-content: center;
    font-size: 0 !important;
    gap: 0 !important;
    overflow: hidden;
  }
  .logout-topbar svg {
    width: 16px;
    height: 16px;
  }

  /* Page body */
  .page-body {
    padding: var(--space-4) var(--space-3);
    padding-top: calc(var(--topbar-height) + var(--space-4));
  }

  /* Page header */
  .page-header { margin-bottom: var(--space-4); }
  .page-header-title { font-size: var(--text-xl); }

  /* Stats em coluna única no mobile pequeno */
  .dashboard-stats { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .estoque-stats   { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }

  /* Cards menores */
  .stat-card { padding: var(--space-3) var(--space-4); }
  .stat-value { font-size: var(--text-xl); }
  .stat-icon  { width: 38px; height: 38px; }

  /* Profissionais grid */
  .profissionais-grid { grid-template-columns: 1fr; }

  /* Clientes grid */
  .clientes-grid { grid-template-columns: 1fr; }

  /* Modais: centralizados no mobile */
  .modal-overlay {
    align-items: center;
    justify-content: center;
    padding: var(--space-4) var(--space-3);
  }

  .modal {
    border-radius: var(--radius-xl);   /* bordas arredondadas em todos os lados */
    max-width: 96%;
    width: 100%;
    max-height: calc(90dvh - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    animation: modalCenterIn 0.26s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  }

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

  /* Tabelas com scroll horizontal */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table th, .table td {
    font-size: var(--text-xs);
    padding: var(--space-2) var(--space-3);
    white-space: nowrap;
  }

  .table { min-width: 640px; }

  /* Form rows viram colunas */
  .form-row { grid-template-columns: 1fr; }

  /* Agenda mobile */
  .agenda-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Config nav horizontal no mobile */
  .config-nav {
    display: flex;
    overflow-x: auto;
    border-radius: 0;
    position: static;
    border: none;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-card);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  .config-nav-item {
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-xs);
    flex-shrink: 0;
  }

  .config-nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--color-primary);
  }

  .config-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .config-card-body { padding: var(--space-4); }
  .config-card-header { padding: var(--space-3) var(--space-4); }
  .config-card-footer { padding: var(--space-3) var(--space-4); }

  /* Estoque / Procedimentos */
  .estoque-layout { grid-template-columns: 1fr; }
  .proc-layout { grid-template-columns: 1fr; }
  .categorias-panel {
    display: block;
    position: static;
    overflow: hidden;
  }
  .categorias-list {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--space-1);
  }
  .categoria-item {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Toolbar mobile */
  .produtos-toolbar,
  .prof-toolbar,
  .clientes-toolbar,
  .procedimentos-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .produtos-search,
  .prof-search,
  .clientes-search,
  .procedimentos-search {
    min-width: 0;
    flex: 1;
    max-width: 100%;
  }

  .clientes-count {
    margin-left: 0;
  }

  .proc-card {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .proc-actions {
    opacity: 1;
    margin-left: auto;
  }

  /* Horários */
  .horario-row {
    grid-template-columns: 80px 1fr 1fr 60px;
    gap: var(--space-2);
    font-size: var(--text-xs);
  }

  /* Empty states */
  .empty-state { padding: var(--space-8) var(--space-4); }

  /* Tipo movimentação */
  .tipo-movimentacao-btns { grid-template-columns: 1fr 1fr 1fr; }
  .tipo-btn { padding: var(--space-2); font-size: 10px; }

  .sidebar-logo {
    padding: var(--space-4) var(--space-3);
  }

  .sidebar-logo-text {
    font-size: var(--text-sm);
  }

}

/* --- Mobile pequeno (até 480px) --- */
@media (max-width: 480px) {
  .dashboard-stats { grid-template-columns: 1fr 1fr; }
  .estoque-stats   { grid-template-columns: 1fr 1fr; }

  .topbar-right .btn:not(.btn-primary):not(.btn-theme) { display: none; }
  /* Tema: sempre visível, compacto */
  .topbar-right .btn-theme {
    display: flex !important;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border-radius: var(--radius-full);
    flex-shrink: 0;
  }
  .logout-topbar {
    display: none; /* logout vai pelo menu lateral */
  }

  .bottom-nav-item span { display: none; }
  .bottom-nav-item { padding: var(--space-2); }

  .page-header-title { font-size: var(--text-lg); }
}

/* ===== DARK MODE MOBILE ===== */
[data-theme="dark"] .bottom-nav {
  background: var(--color-bg-card);
  border-top-color: var(--color-border);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}

[data-theme="dark"] .sidebar-overlay {
  background: rgba(0,0,0,0.7);
}

/* ===== TOUCH TARGETS ===== */
@media (hover: none) and (pointer: coarse) {
  /* Aumenta área de toque em touch devices */
  .btn { min-height: 44px; }
  .nav-item { min-height: 44px; }
  .form-input, .form-select, .form-textarea { min-height: 44px; font-size: 16px !important; } /* 16px evita zoom no iOS */
  .bottom-nav-item { min-height: 44px; }

  /* Remove hover effects em touch */
  .prof-card-actions { opacity: 1; }
  .cliente-action-btn { opacity: 1; }
  .proc-actions { opacity: 1; }
}

/* ===== PWA SAFE AREAS (iPhone X+) ===== */
@supports (padding: max(0px)) {
  .topbar {
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    padding-top: max(0px, env(safe-area-inset-top));
  }

  .page-body {
    padding-top: calc(var(--topbar-height) + env(safe-area-inset-top) + var(--space-4));
  }

  .bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    height: calc(66px + env(safe-area-inset-bottom));
  }

  .bottom-nav-inner {
    height: 66px;
    width: 100%;
    flex: 1;
    grid-template-columns: 1fr 1fr auto 1fr 1fr;
  }

  .app-content {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }
}

/* ===== SCROLL SUAVE ===== */
@media (max-width: 768px) {
  * { -webkit-tap-highlight-color: transparent; }

  html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
  }
}

/* ===== ANIMAÇÕES GLOBAIS ===== */

/* Fade de entrada da página */
@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.app-content {
  animation: none;
}

@media (max-width: 768px) {
  .app-content {
    animation: pageFadeIn 0.28s ease both;
  }
}

/* Botões com feedback de pressão */
@media (hover: none) and (pointer: coarse) {
  .btn:active {
    transform: scale(0.94);
    transition: transform 0.1s ease;
  }
  .btn-hoje:active,
  .agenda-nav-btn:active {
    transform: scale(0.90);
    transition: transform 0.1s ease;
  }
}

/* Modais com spring suave */
@keyframes modalSpring {
  0%   { opacity: 0; transform: translateY(100%) scale(0.98); }
  60%  { opacity: 1; transform: translateY(-4px) scale(1.005); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 768px) {
  .modal {
    animation: modalCenterIn 0.26s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  }

  /* Bottom nav items com micro-animação */
  .bottom-nav-item,
  .bottom-nav-fab {
    -webkit-tap-highlight-color: transparent;
  }
}

/* Toast com spring */
@keyframes toastSpring {
  0%   { opacity: 0; transform: translateX(30px) scale(0.95); }
  60%  { opacity: 1; transform: translateX(-4px) scale(1.01); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

.toast {
  animation: toastSpring 0.3s cubic-bezier(0.34, 1.40, 0.64, 1) both;
}

/* Skeleton loading pulse */
@keyframes skeletonPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.skeleton {
  background: var(--color-border);
  border-radius: var(--radius-sm);
  animation: skeletonPulse 1.4s ease infinite;
}
