/* =======================
   Passer une commande — Drawer (match Emballage)
   ======================= */

:root{
  --border:#e5e7eb;
  --muted:#64748b;
  --bg:#f6f8fc;
  --card:#fff;
  --primary:#2563eb;
  --sidebar-bg:#dbe6ff;
  --sidebar-accent:#cfe0ff;
  --sidebar-grad-end:#bcd2ff;
}

/* --- Viewport hints --- */
@-ms-viewport{ width: device-width; }
@viewport{ width: device-width; }

/* ===== Reset / base ===== */
*,
*::before,
*::after{ box-sizing:border-box; }
html,body{ height:100%; width:100%; }
html{ -webkit-text-size-adjust:100%; text-size-adjust:100%; }
body{
  margin:0;
  background:var(--bg);
  color:#0f172a;
  font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  max-width:100vw;
  overflow-x:hidden;
}
body.drawer-open{ overflow-y:hidden; } /* sólo corta scroll cuando el drawer está abierto */

/* =================
   Layout (mobile-first)
   ================= */
.layout{
  display:grid;
  grid-template-columns:1fr;  /* drawer por defecto */
  min-height:100vh;
  min-width:0;
  max-width:100vw;
  overflow-x:hidden;
}

/* =================
   Sidebar (Drawer)
   ================= */
.sidebar{
  background:linear-gradient(180deg,var(--sidebar-bg),var(--sidebar-grad-end)65%);
  border-right:1px solid var(--border);
  padding:18px 16px;
  position:fixed; inset:0 auto 0 0;
  width:92vw; max-width:420px;
  height:100vh; overflow:auto;
  box-shadow:0 10px 40px rgba(0,0,0,.25);
  transform:translateX(-100%);
  transition:transform .25s ease;
  z-index:100;                 /* sobre el main */
  will-change:transform;
}
.drawer-open .sidebar{ transform:translateX(0); }

.drawer-scrim{
  position:fixed; inset:0;
  background:rgba(0,0,0,.35);
  display:none;
  z-index:90;                  /* debajo del drawer */
}
.drawer-open .drawer-scrim{ display:block; }

.side-header{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  position:sticky; top:0; z-index:1;
  background:var(--sidebar-accent);
  padding:12px; margin:-18px -16px 12px; border-bottom:1px solid var(--border);
}
.side-header h3{ margin:0; font-weight:800; font-size:20px; }
.side-header-actions{ display:flex; gap:8px; align-items:center; }
.side-actions{ display:flex; gap:8px; margin:12px 0 10px; }

.side-card{
  background:#fff; border:1px solid var(--border); border-radius:16px;
  padding:14px; box-shadow:0 2px 10px rgba(0,0,0,.03);
}
.side-card label{ display:block; font-weight:700; color:#475569; margin-bottom:6px; }
.side-card input[type="text"]{
  width:100%; border:1px solid #dbe2f3; border-radius:12px; padding:12px 14px;
  background:#fafcff; outline:none; font-size:15px;
}
.side-card input[type="text"]:focus{
  border-color:#3b82f6; box-shadow:0 0 0 3px rgba(59,130,246,.12);
}

.cmd-list{ margin-top:12px; }
.cmd-item{
  padding:10px 12px; border:1px solid #eef2ff; border-radius:12px; background:#fff;
  margin-bottom:8px; cursor:pointer; transition:.15s;
}
.cmd-item:hover{ background:#f8fbff; transform:translateY(-1px); }
.cmd-item.active{ background:#eef2ff; border-color:#cbd5ff; }
.cmd-item .title{ font-weight:700; }
.cmd-item .meta{ font-size:12px; color:#64748b; margin-top:4px; }

/* Botones abrir/cerrar */
.btn-open,.btn-close{ display:inline-flex; align-items:center; gap:8px; }

/* =========
   Main pane
   ========= */
.main{
  padding:20px 22px 36px;
  position:relative;
  z-index:1;                    /* por debajo del drawer */
  min-width:0;
  max-width:100vw;
  overflow-x:hidden;
}
.page-header{
  display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px;
}
.page-title-wrap{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; min-width:0; }
.page-title{ margin:0; font-size:22px; font-weight:800; }
.cta-bar{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }

/* ================
   Client banner (encabezado dinámico)
   ================ */
.client-banner{
  margin:6px 0 0;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
  display:flex;
  gap:10px;
  align-items:flex-start;
}
.client-banner .chip{
  display:inline-flex;
  align-items:center;
  padding:6px 10px;
  border-radius:999px;
  font-weight:700;
  border:1px solid var(--border);
  white-space:nowrap;
}
.chip.prix-avec{ background:#ecfdf5; border-color:#a7f3d0; color:#065f46; }
.chip.prix-sans{ background:#fffbeb; border-color:#fde68a; color:#92400e; }
.client-banner .obs{
  flex:1;
  color:#334155;
  font-size:14px;
  line-height:1.35;
  max-height:4.5em;
  overflow:auto;
}

/* ===== Meta inline bajo el input de cliente ===== */
.client-meta{
  margin-top:8px;
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:10px;
  background:#fff;
  display:flex;
  gap:8px;
  align-items:flex-start;
}
.client-meta .chip{
  display:inline-flex;
  align-items:center;
  padding:5px 9px;
  border-radius:999px;
  font-weight:700;
  border:1px solid var(--border);
  white-space:nowrap;
  font-size:12.5px;
}
.client-meta .obs{
  flex:1;
  color:#334155;
  font-size:13px;
  line-height:1.35;
  max-height:4.5em;
  overflow:auto;
}

/* Steps / Cards */
.step{
  background:#fff; border:1px solid var(--border); border-radius:14px;
  padding:14px; margin:14px 0;
}
.step-title{ display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.badge{
  display:inline-flex; align-items:center; justify-content:center;
  width:28px; height:28px; border-radius:50%;
  background:#1f62ff; color:#fff; font-weight:800;
}
.subtle{ color:#64748b; font-size:13px; }

/* Form grid */
.row{ display:grid; grid-template-columns:repeat(12,1fr); gap:12px; min-width:0; }
.field{ display:flex; flex-direction:column; min-width:0; }
.field label{ font-weight:700; color:#374151; margin-bottom:6px; }
.field input,.field textarea,.field select{
  border:1px solid var(--border); border-radius:10px; padding:12px 14px; font-size:15px; background:#fff;
  min-width:0; width:100%;
}
.field textarea{ min-height:72px; }

.col-12{ grid-column:span 12; }
.col-8{ grid-column:span 8; }
.col-6{ grid-column:span 6; }
.col-4{ grid-column:span 4; }
.col-3{ grid-column:span 3; }

/* Tabla de items */
.table-wrap{
  width:100%;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:12px; border:1px solid var(--border); background:#fff;
}
table{
  width:100%;
  border-collapse:separate; border-spacing:0;
  min-width:720px;
}
thead th{
  background:#f8fafc; color:#334155; text-align:left; padding:10px 12px;
  border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:10;  /* sobre filas; el drawer está en otra capa */
}
tbody td{ padding:10px 12px; border-bottom:1px solid #f1f5f9; }
tbody tr:hover{ background:#fafcff; }
.right{ text-align:right; }
.space-top{ margin-top:10px; }
.space-bottom{ margin-bottom:10px; }

/* Modal */
.modal{
  position:fixed; inset:0; display:none; align-items:center; justify-content:center;
  background:rgba(0,0,0,.35); z-index:80;   /* debajo del drawer */
}
.modal.open{ display:flex; }
.modal-card{
  width:min(680px,92vw); max-height:88vh; overflow:auto;
  background:#fff; border-radius:12px; padding:16px;
  box-shadow:0 20px 60px rgba(0,0,0,.25);
}
.modal-header{ display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.close-x{ background:#fff; border:1px solid var(--border); border-radius:8px; width:34px; height:34px; cursor:pointer; }

/* Botones */
.btn{
  border:none; border-radius:12px; padding:10px 14px; background:var(--primary); color:#fff; cursor:pointer;
  box-shadow:0 1px 2px rgba(0,0,0,0.08); font-weight:600;
  transition:filter .15s ease, transform .05s ease, box-shadow .15s ease;
}
.btn:hover{ filter:brightness(0.98); box-shadow:0 4px 12px rgba(37,99,235,.18); }
.btn:active{ transform:translateY(0.5px); }
.btn.secondary{ background:#0ea5e9; }
.btn.warn{ background:#f59e0b; color:#111; }
.btn.danger{ background:#ef4444; }
.btn.ghost{ background:#fff; color:#0f3b9d; border:1px solid #c7d2fe; }
.btn:disabled{ opacity:.6; cursor:not-allowed; }

.sticky-cta{
  position:sticky; top:-1px; background:#fff; padding:8px;
  border-radius:10px; border:1px solid var(--border);
}

/* =========================
   Typeahead: por encima del drawer
   ========================= */
.typeahead-portal{
  position:fixed; display:none; max-height:50vh; overflow:auto;
  border:1px solid #e5e7eb; border-radius:10px; background:#fff;
  box-shadow:0 12px 40px rgba(0,0,0,.18);
  z-index:110; /* > sidebar (100) y scrim (90) */
}
.typeahead-item{ padding:10px 12px; cursor:pointer; }
.typeahead-item:hover,.typeahead-item.active{ background:#f1f5ff; }
.typeahead-empty{ padding:10px 12px; color:#64748b; }

/* ===== Breakpoints ===== */

/* <=1100px: tablet (Fire HD 10/8 portrait/landscape) */
@media (max-width:1100px){
  html{ font-size:16px; }
  .col-6,.col-4,.col-3{ grid-column:span 12; } /* apilar campos */
  .field input,.field textarea,.field select{ font-size:16px; padding:12px 16px; }
  .page-title{ font-size:20px; }
  .btn{ padding:12px 16px; border-radius:14px; }
  .step{ border-radius:16px; }
  table{ min-width:640px; }
}

/* <=900px: Fire HD 8 portrait */
@media (max-width:900px){
  html{ font-size:15px; }
  .main{ padding:14px 16px 26px; }
  .page-title{ font-size:18px; }
  table{ min-width:560px; }
}

/* <=760px: extra compacto */
@media (max-width:760px){
  table{ min-width:520px; }
}

/* =====================================================
   Desktop (>=1200px) — sidebar fijo SIN overlay
   ===================================================== */
@media (min-width:1200px){
  .layout{ grid-template-columns:344px 1fr; align-items:start; }
  .sidebar{
    position: sticky !important;
    inset: auto !important;
    top: 0; height: 100vh;
    transform: none !important;
    box-shadow: 6px 0 14px -10px rgba(16,24,40,.18);
    z-index: 50;              /* > main y > thead (10) */
    align-self: start;        /* asegura sticky dentro de grid */
    width: auto !important;      /* deja que el grid (344px) mande */
    max-width: none !important;  /* quita el 420px del modo drawer */
  }
  /* neutraliza cualquier estado heredado de drawer */
  body.drawer-open .sidebar{ transform: none !important; }
  .drawer-scrim{ display: none !important; }
  .btn-open, .btn-close{ display: none !important; }
  .main{ padding: 24px 26px 40px; }
  table{ min-width: unset; }
  thead th{ z-index: 10; }
}

/* =====================================================
   Fallback manual con clases (extra robustez)
   ===================================================== */
/* HOTFIX: cuando activamos .sidebar-sticky (no-tablet), forzar 2 columnas */
.sidebar-sticky .layout{
  grid-template-columns:344px 1fr;
  align-items:start;
}
/* Subir z-index del sidebar en fallback para igualarlo al desktop */
.sidebar-sticky .sidebar{
  position:sticky; inset:auto; top:0; height:100vh; transform:none !important;
  box-shadow:6px 0 14px -10px rgba(16,24,40,.18); z-index:50;
  width: auto !important;
  max-width: none !important;
}
.sidebar-sticky .drawer-scrim{ display:none !important; }

.is-tablet .layout{ grid-template-columns:1fr; }
.is-tablet .sidebar{
  position:fixed; inset:0 auto 0 0; width:92vw; max-width:420px;
  height:100vh; overflow:auto;
  transform:translateX(-100%); transition:transform .25s ease;
  box-shadow:0 10px 40px rgba(0,0,0,.25); z-index:100;
}
.is-tablet.drawer-open .sidebar{ transform:translateX(0); }
.is-tablet .drawer-scrim{ position:fixed; inset:0; background:rgba(0,0,0,.35); display:none; z-index:90; }
.is-tablet.drawer-open .drawer-scrim{ display:block; }
.is-tablet .btn-open,.is-tablet .btn-close{ display:inline-flex; }
.is-tablet .main{ padding:16px 18px 28px; }
.is-tablet table{ min-width:560px; }

/* ===== Forzar escritorio cuando el <body> tenga .force-desktop ===== */
body.force-desktop .layout{ grid-template-columns:344px 1fr !important; }
body.force-desktop .sidebar{
  position: sticky !important;
  inset: auto !important;
  top: 0;
  height: 100vh;
  transform: none !important;
  box-shadow: 6px 0 14px -10px rgba(16,24,40,.18);
  z-index: 50 !important;
  width: auto !important;
  max-width: none !important;
}
body.force-desktop .drawer-scrim{ display:none !important; }
body.force-desktop .btn-open,
body.force-desktop .btn-close{ display:none !important; }
body.force-desktop .main{ padding:24px 26px 40px; }
body.force-desktop table{ min-width: unset; }
/* === Mostrar SOLO una vista de meta cliente según viewport === */

/* Mobile-first: mostrar la tarjeta inline y ocultar el banner */
.client-banner { display: none; }
#clientMetaInline { display: flex; }  /* usa el ID real del HTML */

/* Desktop (>=1200px): mostrar banner y ocultar la tarjeta inline */
@media (min-width:1200px){
  .client-banner { display: flex; }
  #clientMetaInline { display: none; }
}
/* === FIX: header sin montarse y banner a toda línea === */
.page-header{
  display:flex;
  flex-wrap:wrap;            /* permite bajar a otra línea */
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.page-title-wrap{
  flex:1 1 auto;             /* ocupa el espacio de la izquierda */
  min-width:260px;           /* evita colapsar en breakpoints raros */
}

.cta-bar{
  flex:0 0 auto;             /* se queda compacta a la derecha */
}

.page-header .client-banner{
  flex:1 1 100%;             /* ocupa toda la fila siguiente */
  order:3;                   /* asegura que va debajo del título/cta */
  margin-top:6px;
}

/* (opcional) un poco más de aire en desktop */
@media (min-width:1200px){
  .page-header{ gap:14px; }
  .page-header .client-banner{ margin-top:8px; }
}
