/*
 * AEM Planner — Responsive Overrides
 * UX/UI Pro Max: mobile-first, 44px touch targets, 375/768/1024/1440 breakpoints
 * Complementa styles.css sin sobreescribir la base de marca.
 */

/* ── BASE GLOBAL ──────────────────────────────────────────── */

:root {
  /* Viewport height seguro (evita el bug de 100vh en iOS Safari) */
  --vh-full: 100dvh;
  /* Timing tokens */
  --t-fast: 150ms;
  --t-med:  250ms;
  --t-slow: 350ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in:  cubic-bezier(0.64, 0, 0.78, 0);
}

/* touch-action para quitar el delay 300ms en iOS */
button, a, [role="button"] {
  touch-action: manipulation;
}

/* Scroll suave en toda la app */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Evita el bounce horizontal en iOS */
body {
  overscroll-behavior-x: none;
}

/* Focus visible solo con teclado (no con ratón/touch) */
:focus:not(:focus-visible) {
  outline: none;
}
:focus-visible {
  outline: 2px solid #4e6359;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── TOUCH TARGETS MÍNIMOS (44px Apple HIG / 48dp Material) ─ */

.btn {
  min-height: 44px;
  min-width: 44px;
}

.mini-btn {
  min-height: 38px;   /* en listas densas usamos 38; botones de acción primaria ≥44 */
  padding: 0 12px;
}

.nav button {
  min-height: 44px;
}

.tabs button,
.tab-btn {
  min-height: 40px;
}

/* ── ANIMACIONES CON prefers-reduced-motion ─────────────────  */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── TOAST: no bloquea interacción, aria-live gestionado en JS ─ */

.toast {
  animation: toastIn var(--t-med) var(--ease-out);
}

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

/* ── MODAL: animación desde el centro ───────────────────────── */

.modal-card {
  animation: modalIn var(--t-med) var(--ease-out);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── CARDS: feedback de press ───────────────────────────────── */

.wedding-card {
  transition: transform var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}

.wedding-card:active {
  transform: scale(0.98);
}

.row {
  transition: transform var(--t-fast) var(--ease-out),
              border-color var(--t-fast) ease,
              box-shadow var(--t-fast) ease;
}

.row:active {
  transform: scale(0.99);
}

/* ── TABLET 768–1023px ──────────────────────────────────────── */

@media (min-width: 768px) and (max-width: 1023px) {

  /* Sidebar compacta en tablet: iconos + tooltips */
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    min-height: var(--vh-full);
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: visible;
  }

  .brand {
    margin-bottom: 20px;
  }

  .brand-logo {
    width: 44px;
    height: auto;
    object-fit: contain;
  }

  .brand-title,
  .brand p {
    display: none;
  }

  .nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
  }

  .nav button {
    width: 52px;
    min-height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 14px;
    position: relative;
  }

  /* Tooltip en hover para tablet */
  .nav button::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #24231d;
    color: #fbfaf2;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--t-fast) ease;
    z-index: 50;
  }

  .nav button:hover::after {
    opacity: 1;
  }

  .nav button span:not(.ico) {
    display: none;
  }

  .sidebar-footer {
    position: static;
    margin-top: auto;
    padding-top: 12px;
    font-size: 10px;
    text-align: center;
  }

  .sidebar-footer strong,
  .sidebar-footer br {
    display: none;
  }

  .sidebar-footer .btn {
    padding: 0;
    width: 44px;
    min-width: 44px;
    justify-content: center;
    font-size: 0;
  }

  .sidebar-footer .btn::before {
    content: "↩";
    font-size: 16px;
  }

  /* Grids tablet: 2 columnas en vez de 4/3 */
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Dashboard priority: 2 columnas en tablet */
  .dashboard-priority-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Wedding summary: columna única */
  .wedding-summary-grid {
    grid-template-columns: 1fr;
  }

  .wedding-identity {
    grid-row: auto;
  }

  /* Export: columna única */
  .export-studio {
    grid-template-columns: 1fr;
  }

  /* Guide: columna única */
  .guide-layout {
    grid-template-columns: 1fr;
  }

  /* Content padding */
  .content {
    padding: 22px 20px 40px;
  }

  .topbar {
    padding: 16px 20px;
  }

  /* Estas tres tenían columnas fijas en px que no se ajustaban en tablet
     (solo se colapsaban del todo en móvil ≤767px) — con la sidebar de 72px
     de tablet quedaba poco margen y podían sentirse apretadas o desbordar. */
  .control-hero {
    grid-template-columns: minmax(0, 1fr) minmax(120px, 160px);
    padding: 24px;
  }

  .wedding-command {
    grid-template-columns: minmax(150px, 180px) minmax(140px, 1fr) auto;
    gap: 14px;
  }

  .palette-editor {
    grid-template-columns: repeat(3, minmax(64px, 84px)) minmax(180px, 1fr);
  }
}

/* ── DESKTOP GRANDE 1440px+ ──────────────────────────────── */

@media (min-width: 1440px) {
  .content {
    padding: 32px 48px 64px;
    max-width: 1440px;
    margin: 0 auto;
  }

  .control-hero h3 {
    font-size: 64px;
  }
}

/* ── MOBILE ≤ 767px ─────────────────────────────────────── */

@media (max-width: 767px) {

  /* App shell: columna única, nav abajo */
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: 72px; /* espacio para la nav fija */
  }

  /* Sidebar → bottom navigation bar (solo 5 items principales) */
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 10;
    min-height: 0;
    padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    background: rgba(251, 250, 242, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid rgba(216, 210, 189, 0.7);
    border-right: none;
    border-radius: 0;
    box-shadow: 0 -8px 30px rgba(36, 35, 29, 0.1);
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

  .desktop-nav {
    display: none;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    min-height: 66px;
    padding: 6px max(6px, env(safe-area-inset-right)) 5px max(6px, env(safe-area-inset-left));
  }

  .mobile-nav button {
    min-width: 0;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px 2px;
    border: 0;
    background: transparent;
    color: var(--tinta-suave);
    font: inherit;
    font-size: 10px;
    border-radius: 12px;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }

  .mobile-nav .ico {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    flex: none;
    font-size: 14px;
  }

  .mobile-nav button > span:last-child {
    display: block;
    font-size: 10px;
    line-height: 1.15;
    font-weight: 600;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-nav button.active {
    transform: none;
    box-shadow: none;
    background: linear-gradient(135deg, rgba(78, 99, 89, 0.14), rgba(217, 225, 218, 0.6));
    color: var(--aem-green-deep);
  }

  .mobile-nav button.active .ico {
    background: rgba(78, 99, 89, 0.2);
    color: #33463d;
  }

  .mobile-nav .mobile-nav-more {
    position: relative;
    min-height: 58px;
    margin-top: -17px;
    color: var(--aem-green-deep);
  }

  .mobile-nav-more-icon {
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    border: 5px solid var(--crema, #fbfaf2);
    border-radius: 50%;
    background: var(--aem-green);
    box-shadow: 0 8px 20px rgba(36, 35, 29, 0.22);
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: 25px;
    font-weight: 300;
    line-height: 1;
    transition: transform 160ms ease, background 160ms ease;
  }

  .mobile-nav-more[aria-expanded="true"] .mobile-nav-more-icon {
    transform: rotate(45deg);
    background: var(--aem-green-deep);
  }

  .mobile-more-layer {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: block;
  }

  .mobile-more-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    background: rgba(30, 35, 31, 0.48);
    backdrop-filter: blur(3px);
  }

  .mobile-more-sheet {
    position: absolute;
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    max-height: min(68dvh, 560px);
    overflow-y: auto;
    padding: 20px;
    border: 1px solid rgba(216, 210, 189, 0.9);
    border-radius: 18px;
    background: rgba(251, 250, 242, 0.98);
    box-shadow: 0 24px 70px rgba(36, 35, 29, 0.28);
    animation: mobileMoreIn 180ms var(--ease-out);
  }

  @keyframes mobileMoreIn {
    from { opacity: 0; transform: translateY(18px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }

  .mobile-more-head,
  .mobile-more-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
  }

  .mobile-more-head h2 {
    margin: 0;
    color: var(--ink);
    font-family: "Italiana", Georgia, serif;
    font-size: 26px;
    font-weight: 400;
    letter-spacing: 0;
  }

  .mobile-more-close {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
  }

  .mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 18px;
  }

  .mobile-more-grid button {
    min-height: 62px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--borde-suave);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.68);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    text-align: left;
  }

  .mobile-more-grid button.active {
    border-color: rgba(78, 99, 89, 0.5);
    background: rgba(217, 225, 218, 0.72);
    color: var(--aem-green-deep);
  }

  .mobile-more-grid .ico {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 34px;
    border-radius: 9px;
    background: rgba(78, 99, 89, 0.1);
  }

  .mobile-more-footer {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--borde-suave);
  }

  .mobile-more-footer > span {
    display: grid;
    min-width: 0;
  }

  .mobile-more-footer small {
    margin-top: 2px;
    color: var(--tinta-suave);
  }

  /* Main sin padding lateral ajustado */
  .content {
    padding: 16px 16px 24px;
  }

  .topbar {
    padding: 14px 16px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: clamp(20px, 5vw, 28px);
  }

  .topbar p {
    font-size: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .topbar .actions {
    flex-shrink: 0;
  }

  /* Modal: full-screen en móvil */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    animation: modalSlideUp var(--t-med) var(--ease-out);
  }

  .onboarding-layer {
    place-items: end center;
    padding: 10px 10px calc(82px + env(safe-area-inset-bottom, 0px));
  }

  .onboarding-card {
    max-height: calc(100dvh - 104px);
    overflow-y: auto;
    padding: 24px 22px;
    border-radius: 14px;
  }

  .onboarding-card > img {
    width: 128px;
    margin-bottom: 18px;
  }

  .onboarding-card h2 {
    font-size: 29px;
  }

  .onboarding-actions .btn,
  .onboarding-actions .link-btn {
    min-height: 44px;
  }

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

  /* Grids: todos a 1 columna */
  .grid.cols-4,
  .grid.cols-3,
  .grid.cols-2 {
    grid-template-columns: 1fr;
  }

  .stat-row-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-row-5 > :last-child {
    grid-column: 1 / -1;
  }

  .weddings-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Tabs: scroll horizontal suave, sin barra */
  .tabs {
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 6px;
    padding: 0 0 10px;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tabs button,
  .tab-btn {
    min-height: 40px;
    font-size: 13px;
    padding: 0 11px;
  }

  /* Hero control: layout vertical */
  .control-hero {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 22px 18px;
    gap: 16px;
  }

  .readiness-orbit {
    min-height: 100px;
    border: 1px solid rgba(255,255,255,0.28);
  }

  .readiness-orbit strong {
    font-size: 38px;
  }

  /* Dashboard priority: columna única */
  .dashboard-priority-grid {
    grid-template-columns: 1fr;
    margin-top: 14px;
  }

  /* Wedding command: vertical */
  .wedding-command {
    grid-template-columns: 1fr;
    gap: 12px;
    border-left-width: 4px;
  }

  .wedding-command strong {
    font-size: 28px;
  }

  /* Wedding summary: columna única */
  .wedding-summary-grid {
    grid-template-columns: 1fr;
  }

  .wedding-identity {
    grid-row: auto;
  }

  /* Export checklist: 1 columna */
  .export-checklist {
    grid-template-columns: 1fr;
  }

  /* Export studio: columna única */
  .export-studio {
    grid-template-columns: 1fr;
  }

  /* Guide layout: columna única */
  .guide-layout {
    grid-template-columns: 1fr;
  }

  /* Guide steps: 2 columnas en vez de 3 */
  .guide-step {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .guide-step .btn {
    grid-column: 2;
  }

  /* Rows: layout vertical */
  .row {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 12px;
  }

  .row .inline-tools {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  /* Palette editor: 3 colores + nota abajo */
  .palette-editor {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .palette-note {
    grid-column: 1 / -1;
  }

  /* Print options modal: full height */
  .print-options-modal {
    width: 100%;
    max-width: 100%;
    height: 92dvh;
    border-radius: 20px 20px 0 0;
    border-top: 6px solid var(--print-primary, #4a6355);
  }

  /* Audience control en móvil: full width */
  .audience-control {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .audience-control button {
    flex-shrink: 0;
  }

  /* Login: columna única */
  .login {
    grid-template-columns: 1fr;
  }

  .login-visual {
    min-height: 38vh;
  }

  .login-visual h1 {
    font-size: clamp(32px, 8vw, 52px);
  }

  /* Portal hero */
  .portal-hero {
    min-height: 260px;
  }

  .portal-hero h1 {
    font-size: clamp(28px, 7vw, 48px);
  }

  .portal-hero-logo {
    width: 132px;
    margin-bottom: 14px;
  }

  /* Metrics en 2 columnas en móvil grande */
  @media (min-width: 500px) {
    .grid.cols-4 {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  /* Task stats: 3 columnas siempre */
  .task-stats.grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Toolbar panel: columna única */
  .toolbar-panel {
    grid-template-columns: 1fr;
  }

  /* Section title: wrap */
  .section-title {
    flex-wrap: wrap;
    gap: 10px;
  }

  .section-title .actions {
    justify-content: flex-start;
  }

  /* Print toolbar: wrap */
  .print-toolbar {
    flex-wrap: wrap;
  }

  /* Botones: que el texto largo pueda envolver en vez de desbordar
     (antes esta regla ponía nowrap y pisaba el "normal" de styles.css,
     provocando que etiquetas largas como "Añadir invitado" se recortaran). */
  .btn,
  .mini-btn {
    white-space: normal;
    word-break: break-word;
    text-align: center;
  }

  /* Barra de acciones del portal: botones a ancho completo y apilados,
     mejor objetivo táctil que varios botones estrechos en una fila. */
  .portal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .portal-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Textos largos: recortar en topbar */
  .topbar > div:first-child {
    min-width: 0;
    overflow: hidden;
  }
}

/* ── LANDSCAPE MÓVIL ─────────────────────────────────────── */

@media (max-width: 767px) and (orientation: landscape) {
  .sidebar {
    padding-bottom: max(env(safe-area-inset-bottom, 0), 4px);
  }

  .nav button {
    min-height: 44px;
    flex-direction: row;
    gap: 6px;
    font-size: 11px;
    padding: 0 8px;
  }

  .nav button span:not(.ico) {
    font-size: 11px;
  }

  .login-visual {
    min-height: 50vh;
  }

  .control-hero {
    padding: 16px;
  }
}

/* ── IMPRESIÓN ───────────────────────────────────────────── */

@media print {
  .sidebar,
  .topbar,
  .tabs,
  .tab-nav,
  .tab-btn,
  .sidebar-boda-chip,
  .wedding-card-actions,
  .mesa-card-actions,
  .btn,
  .mini-btn,
  .actions,
  .toast {
    display: none !important;
  }

  .app-shell {
    display: block;
    padding-bottom: 0;
  }

  .content {
    padding: 0;
  }

  .panel, .card, .row {
    box-shadow: none;
    break-inside: avoid;
    border: 1px solid #d8d2bd;
  }

  .modal-backdrop {
    display: none !important;
  }
}

/* ── UTILIDADES EXTRA ────────────────────────────────────── */

/* Skeleton loader para futura carga async */
.skeleton {
  background: linear-gradient(90deg, #e8e4d6 25%, #f0ece0 50%, #e8e4d6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Scroll to top suave en secciones de contenido */
.content {
  scroll-padding-top: 80px;
}

/* ==========================================================================
   Presupuesto y contrato en tablet y móvil
   ========================================================================== */
@media (max-width: 1023px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

@media (max-width: 767px) {
  .stat-grid { grid-template-columns: 1fr; }

  /* La tabla sigue siendo tabla (se puede arrastrar), pero se estrecha para
     que quepan más columnas antes de tener que desplazar. */
  .table-wrap > table { min-width: 640px; font-size: 13px; }
  .budget-table th,
  .budget-table td { padding: 8px 10px; }
  .budget-table .inline-tools { display: flex; gap: 6px; justify-content: flex-end; }

  /* El documento subido pasa a dos filas: nombre arriba, acciones abajo,
     para que el botón de descargar no quede espachurrado. */
  .contract-upload { flex-wrap: wrap; }
  .contract-upload-body { flex: 1 1 100%; }
  .contract-upload .inline-tools { flex: 1 1 100%; justify-content: flex-start; }
  .contract-exchange { padding: 14px 14px 16px; }
}

@media (pointer: coarse) {
  .budget-table .mini-btn,
  .contract-upload .mini-btn { min-height: 44px; min-width: 44px; }
}
