:root {
  --blue: #1a3a8f;
  --blue-dark: #12265e;
  --red: #c1121f;
  --bg: #f2f4f8;
  --border: #d4d9e2;
  --profit: #0a7d33;
}
* { box-sizing: border-box; }
/* El atributo hidden SIEMPRE oculta, aunque el elemento tenga display propio (flex/grid).
   Sin esto, el panel de login quedaba visible para siempre tapando la app. */
[hidden] { display: none !important; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; background: var(--bg); color: #1c2331; }

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--blue-dark); color: #fff; padding: 10px 24px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.brand-main { font-size: 20px; font-weight: 800; letter-spacing: 1px; }
.brand-sub { display: block; font-size: 11px; color: #aebbdd; letter-spacing: 2px; }
.navbtn {
  background: transparent; color: #cdd6ee; border: 1px solid transparent; border-radius: 6px;
  padding: 8px 14px; margin-left: 6px; cursor: pointer; font-size: 14px;
}
.navbtn:hover { background: rgba(255,255,255,.1); }
.navbtn.active { background: #fff; color: var(--blue-dark); font-weight: 600; }

.view { max-width: 1100px; margin: 24px auto; padding: 0 20px 60px; }
h2 { color: var(--blue-dark); }
.muted { color: #7a8398; font-weight: normal; font-size: 13px; }

/* ---------- Tablas ---------- */
.grid { width: 100%; border-collapse: collapse; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-radius: 8px; overflow: hidden; }
.grid th { background: var(--blue-dark); color: #fff; padding: 9px 10px; font-size: 12.5px; text-align: left; }
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
.grid tbody tr:hover { background: #f7f9fd; }
.grid .num, .grid td.num { text-align: right; }
.grid input, .grid textarea, .grid select {
  width: 100%; border: 1px solid var(--border); background: #fff; font: inherit; padding: 4px 6px; border-radius: 4px;
}
.grid input:focus, .grid textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(26,58,143,.15); }
.grid input[readonly] { border-color: transparent; }
.grid input.num { text-align: right; }
.grid textarea { resize: vertical; min-height: 34px; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; background: #fff; padding: 16px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 20px; }
.form-grid label { font-size: 12.5px; font-weight: 600; color: #46506a; display: flex; flex-direction: column; gap: 4px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid textarea, .form-grid select {
  font: inherit; font-weight: normal; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px;
}
.form-grid input:focus, .form-grid textarea:focus { outline: none; border-color: var(--blue); }

.editor-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.editor-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toggle { font-size: 13px; margin-right: 8px; user-select: none; }

button { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
button:hover { border-color: var(--blue); color: var(--blue); }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--blue-dark); color: #fff; }
button.danger { color: var(--red); }
.items-toolbar { display: flex; gap: 10px; margin-bottom: 10px; }
.items-toolbar select { padding: 8px; border-radius: 6px; border: 1px solid var(--border); max-width: 420px; }

/* ---------- Totales ---------- */
.totals-panel { display: flex; justify-content: flex-end; gap: 20px; margin: 16px 0 28px; flex-wrap: wrap; }
.totals-internal, .totals-client { background: #fff; border-radius: 8px; padding: 14px 18px; min-width: 260px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.totals-internal { border-left: 4px solid var(--profit); }
.totals-internal h4 { margin: 0 0 8px; color: var(--profit); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.totals-panel div > div, .totals-internal > div, .totals-client > div { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.totals-client .grand { border-top: 2px solid var(--blue-dark); margin-top: 6px; padding-top: 8px; font-size: 17px; color: var(--blue-dark); }
.profit { color: var(--profit); }

/* Ocultar columnas internas cuando el toggle está apagado */
body.hide-internal .internal-col { display: none !important; }

/* ---------- Kits (ítems compuestos) ---------- */
.kit-bar { display: flex; gap: 6px; margin-top: 4px; }
.kit-btn { font-size: 11.5px; padding: 3px 8px; color: #46506a; }
.kit-row > td { background: #f3f6fc; padding: 10px 14px 14px; border-left: 4px solid var(--blue); }
.kit-panel .kit-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.kit-panel .kit-head button { margin-left: auto; font-size: 12.5px; padding: 4px 10px; }
.kit-table { box-shadow: none; border: 1px solid var(--border); }
.kit-table th { background: #5a6a94; font-size: 11.5px; padding: 6px 8px; }
.kit-table td { padding: 4px 8px; font-size: 13px; }
.kit-summary { margin-top: 8px; font-size: 13px; color: #46506a; text-align: right; }
input[readonly] { color: #7a8398; background: #f0f2f6 !important; }

/* ---------- Imagen de ítem ---------- */
.item-img-wrap { position: relative; display: inline-block; margin-top: 6px; }
.item-img { max-height: 90px; max-width: 160px; border: 1px solid var(--border); border-radius: 6px; display: block; }
.img-del { position: absolute; top: -8px; right: -8px; padding: 0 6px; font-size: 11px; border-radius: 50%; background: #fff; }

/* ---------- Campos extra de condiciones ---------- */
.extra-conds { background: #fff; padding: 4px 16px 16px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.extra-conds h4 { color: #46506a; margin: 12px 0; }
.extra-row { display: grid; grid-template-columns: 260px 1fr auto; gap: 10px; margin-bottom: 8px; }
.extra-row input { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; }
.extra-row .extra-label { text-transform: uppercase; font-weight: 600; font-size: 13px; }
.extra-row input:focus { outline: none; border-color: var(--blue); }

.status-pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #e7eaf3; }
.status-ACEPTADA { background: #d7f2e0; color: var(--profit); }
.status-ENVIADA { background: #dbe7ff; color: var(--blue); }
.status-RECHAZADA { background: #ffe0e0; color: var(--red); }

/* ---------- Configuración ---------- */
.cfg-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-weight: normal; }
.letterhead-preview { max-width: 320px; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.internal-note { margin-top: 6px; font-size: 12px !important; color: #7a8398; border: 1px dashed var(--border) !important; border-radius: 4px; }

/* ---------- Editor de portada ---------- */
.cover-section { background: #fff; padding: 4px 16px 16px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 20px; }
.rt-toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.rt-toolbar button { padding: 5px 10px; font-size: 13px; }
.rt-toolbar select { padding: 5px; border: 1px solid var(--border); border-radius: 6px; }
.cover-editor {
  min-height: 260px; border: 1px solid var(--border); border-radius: 6px; padding: 20px;
  font-family: Calibri, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.4; background: #fff;
}
.cover-editor:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(26,58,143,.15); }
.cover-editor:empty::before { content: attr(data-placeholder); color: #a6adc0; }
.cover-editor img { max-width: 100%; }

/* ================= DOCUMENTO DE IMPRESIÓN (hojas A4) ================= */
.sheet {
  background: #fff; width: 800px; min-height: 1128px; margin: 20px auto; padding: 40px 50px 70px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15); font-family: Calibri, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.45;
  position: relative; box-sizing: border-box;
}
/* El inicio del contenido bajo el membrete se controla con la variable --lh-top,
   así ninguna regla de pantalla/móvil puede pisarlo al imprimir */
.sheet.with-letterhead { padding-top: var(--lh-top, 42mm); }
.sheet-inner { position: relative; z-index: 1; }
.letterhead-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.sheet-footer { position: absolute; bottom: 26px; right: 50px; z-index: 1; font-size: 12px; color: #555; }
.sheet-footer-left { position: absolute; bottom: 26px; left: 50px; z-index: 1; font-size: 12px; font-weight: 700; color: #555; }
.cover-content { padding-top: 10px; }
.cover-content img { max-width: 100%; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 4px solid var(--red); padding-bottom: 8px; margin-bottom: 18px; }
.doc-logo .logo-word {
  font-weight: 900; font-style: italic; font-size: 22px; color: var(--blue-dark); line-height: 1;
  border: 3px solid var(--blue-dark); border-radius: 50% / 38%; padding: 14px 20px; position: relative;
}
.logo-cursive { display: block; font-family: "Brush Script MT", cursive; font-weight: normal; font-style: italic; font-size: 16px; color: var(--red); text-align: right; }
.doc-company { text-align: center; }
.co-name { color: var(--blue); font-size: 26px; font-weight: 900; letter-spacing: 1px; }
.co-sub { color: var(--red); font-size: 16px; font-weight: 800; letter-spacing: 1px; }
.co-detail { font-size: 12px; font-weight: 600; color: #333; }
.co-detail.small { font-weight: normal; font-size: 11px; }
.doc-date { text-align: left; }
.doc-clientline { display: flex; justify-content: space-between; }
.doc-attline { margin: 2px 0; }
.doc-ref span { text-decoration: underline; font-weight: 700; }
.doc-section-title { font-weight: 700; text-decoration: underline; margin-top: 16px; }
#pFeatures li { margin-bottom: 4px; }

.doc-items { width: 100%; border-collapse: collapse; margin-top: 14px; }
.doc-items th, .doc-items td { border: 1px solid #000; padding: 5px 8px; font-size: 13px; vertical-align: top; }
.doc-items th { background: #fff; font-weight: 700; text-align: center; }
.doc-items td.center { text-align: center; }
.doc-items td.num { text-align: right; white-space: nowrap; }
.doc-items td.detail { white-space: pre-line; }
.doc-item-img { max-height: 140px; max-width: 260px; margin-top: 6px; display: block; }
.doc-items td.detail b { text-transform: uppercase; }

.doc-totals { width: 100%; border-collapse: collapse; margin-top: 0; }
.doc-totals td { border: 1px solid #000; padding: 6px 8px; font-size: 13px; }
.doc-totals .doc-words { width: 60%; font-weight: 700; vertical-align: top; }
.doc-totals .tl { font-weight: 700; }
.doc-totals .tv { text-align: right; font-weight: 700; white-space: nowrap; }

.doc-conditions { margin-top: 18px; font-size: 12.5px; border-collapse: collapse; }
.doc-conditions td { padding: 2px 8px 2px 0; vertical-align: top; }
.doc-conditions td:first-child { font-weight: 700; white-space: nowrap; }
.doc-conditions td:last-child { font-weight: 600; }

.doc-signatures { display: flex; justify-content: space-around; margin-top: 70px; text-align: center; font-weight: 700; font-size: 13px; }
.sig-line { border-top: 1px solid #000; width: 220px; margin: 0 auto 6px; }
.sig span { font-weight: normal; }
.doc-back { text-align: center; margin-top: 30px; padding-bottom: 20px; }
/* Barra de acciones fija arriba en la vista previa (para no bajar hasta el final) */
.doc-actionbar {
  position: sticky; top: 0; z-index: 50; display: flex; gap: 8px; align-items: center;
  justify-content: center; flex-wrap: wrap; background: var(--blue-dark); padding: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.doc-actionbar .toggle { color: #fff; }
.doc-actionbar select { padding: 6px; border-radius: 6px; }

/* ---------- Impresión ---------- */
@media print {
  /* Sin márgenes de página: cada .sheet de 296mm debe caber exacta en la hoja A4,
     si no, cada hoja "derrama" y aparece una página en blanco después */
  html, body { margin: 0 !important; padding: 0 !important; background: #fff; }
  .no-print, .topbar { display: none !important; }
  .sheet {
    box-shadow: none; margin: 0; width: 210mm; height: 296mm; overflow: hidden;
    min-height: 0; /* anula el min-height de pantalla (1128px ≈ 298mm) que desbordaba a una página en blanco */
    padding: 12mm 14mm 18mm; page-break-after: always;
  }
  /* Con membrete, el contenido SIEMPRE empieza bajo el encabezado, gane quien gane en pantalla */
  .sheet.with-letterhead { padding-top: var(--lh-top, 42mm) !important; }
  .sheet:last-child { page-break-after: auto; }
  .sheet-footer { bottom: 8mm; right: 14mm; }
  .sheet-footer-left { bottom: 8mm; left: 14mm; }
  /* El escalado de pantalla (zoom de fitSheets) jamás debe afectar la impresión */
  #printSheets { zoom: 1 !important; }
  .letterhead-bg { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  @page { size: A4; margin: 0; }
}
.config-section { margin-top: 28px; padding-top: 8px; border-top: 2px solid var(--border); }

/* ---------- Administración (sub-ventanas) ---------- */
.admin-subnav { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 18px; border-bottom: 2px solid var(--border); padding-bottom: 10px; }
.admin-subnav button { background: #eef1f7; border: 1px solid var(--border); border-radius: 8px; padding: 8px 16px; font-size: 14px; cursor: pointer; }
.admin-subnav button:hover { border-color: var(--blue); color: var(--blue); }
.admin-subnav button.active { background: var(--blue-dark); color: #fff; border-color: var(--blue-dark); }
.admin-panel h3 { color: var(--blue-dark); margin-top: 0; }
/* Empresas vinculadas a un barco (chips) */
.link-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 5px; }
.link-chip { display: inline-flex; align-items: center; gap: 4px; background: #e7eefb; color: var(--blue-dark); border-radius: 16px; padding: 3px 6px 3px 10px; font-size: 12.5px; }
.link-chip button { border: none; background: #c9d7f2; color: var(--blue-dark); border-radius: 50%; width: 18px; height: 18px; line-height: 1; cursor: pointer; font-size: 11px; padding: 0; }
.link-sel { font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
.link-btn { font: inherit; font-size: 12.5px; padding: 4px 10px; }
.link-add { margin-top: 4px; }
.cat-manager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #fff; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- Novedades de importación / descuentos ---------- */
.flag-chip { display: inline-block; background: #fdecc8; color: #8a5a00; border-radius: 12px; padding: 2px 9px; font-size: 11px; font-weight: 700; margin: 1px; }
.import-banner { background: #fff8e6; border: 1px solid #f0d590; border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: 13.5px; }
.discount-row select, .discount-row input { font: inherit; font-size: 12.5px; padding: 3px 5px; border: 1px solid var(--border); border-radius: 5px; }
.discount-amt { color: #b25a00; }
.noiva-toggle { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; }
.attach-thumb .att-del { position: absolute; top: -6px; right: -6px; padding: 0 5px; font-size: 10px; border-radius: 50%; background: #fff; }
/* Selectores de barco/empresa en los editores */
.pick-vessel select, .pick-company select { font: inherit; padding: 7px 9px; border: 1px solid var(--blue); border-radius: 6px; background: #f4f8ff; }
.pick-company select { border-color: var(--profit); background: #f2fbf5; }

/* ---------- Dashboard del administrador ---------- */
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.home-card { background: #fff; border-radius: 12px; padding: 16px 18px; box-shadow: 0 1px 4px rgba(0,0,0,.1); border-top: 4px solid var(--blue); }
.hc-num { font-size: 30px; font-weight: 800; color: var(--blue-dark); line-height: 1; }
.hc-label { font-size: 13px; color: #46506a; margin: 4px 0 8px; font-weight: 600; }
.hc-sub { display: flex; flex-wrap: wrap; gap: 5px; }
.hp-pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #eef1f7; color: #46506a; }
.home-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.home-panel { background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.home-panel h3 { margin: 0 0 10px; color: var(--blue-dark); font-size: 15px; }
.home-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.home-row:last-child { border-bottom: none; }
.home-row[data-open-report] { cursor: pointer; }
.home-row[data-open-report]:hover { color: var(--blue); }

/* ---------- Adjuntos (bitácora) ---------- */
.wl-attach-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.attach-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-card { position: relative; width: 92px; background: #f2f4f8; border-radius: 8px; padding: 6px; text-align: center; font-size: 11px; }
.attach-card img { width: 100%; height: 60px; object-fit: cover; border-radius: 5px; }
.attach-card .attach-ico { height: 60px; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.attach-card .attach-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; color: #46506a; }
.attach-card button { position: absolute; top: -6px; right: -6px; padding: 0 6px; font-size: 11px; border-radius: 50%; background: #fff; }
.attach-thumb { display: inline-block; width: 74px; height: 74px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb.file { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: #46506a; font-size: 26px; background: #f2f4f8; }
.attach-thumb.file small { font-size: 9px; }

/* ---------- Herramientas de campo ---------- */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.tool-card { background: #fff; border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.1); border-top: 4px solid var(--blue); }
.tool-card h3 { margin: 0 0 10px; color: var(--blue-dark); font-size: 15px; }
.tool-row { display: flex; flex-wrap: wrap; gap: 10px; }
.tool-row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: #46506a; flex: 1 1 100px; }
.tool-row input, .tool-row select { font: inherit; padding: 8px 9px; border: 1px solid var(--border); border-radius: 6px; width: 100%; }
.tool-row input:focus { outline: none; border-color: var(--blue); }
.tool-out { margin-top: 10px; background: #f2f7ff; border-radius: 8px; padding: 8px 12px; font-size: 14px; color: var(--blue-dark); min-height: 20px; }
.tool-out:empty { display: none; }

/* ---------- Tareas ---------- */
.nav-badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 700; margin-left: 3px; }
.search-box { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; min-width: 250px; }
.search-box:focus { outline: none; border-color: var(--blue); }
.search-hint td { background: #f2f7ff; color: var(--blue-dark); font-size: 12.5px; border-top: none !important; }
.task-form { margin-bottom: 16px; }
.task-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.task-col { background: #eef1f7; border-radius: 10px; padding: 10px; min-height: 200px; }
.task-col h4 { margin: 2px 4px 10px; color: var(--blue-dark); }
.task-card { background: #fff; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.1); cursor: pointer; border-left: 4px solid var(--blue); }
.task-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.tk-title { font-weight: 700; font-size: 13.5px; margin-bottom: 5px; }
.tk-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11.5px; color: #46506a; }
.tk-prio { font-weight: 700; border-radius: 10px; padding: 0 7px; background: #e7eaf3; }
.tk-baja { border-left-color: #9aa4b8; }
.tk-normal { border-left-color: var(--blue); }
.tk-alta { border-left-color: #e08600; }
.tk-alta .tk-prio { background: #ffe9d6; color: #b25a00; }
.tk-urgente { border-left-color: var(--red); }
.tk-urgente .tk-prio { background: #ffdada; color: var(--red); }
.tk-vencida { color: var(--red); font-weight: 700; }
.task-detail-body { padding: 16px 20px; overflow-y: auto; }
.td-meta { font-size: 13px; color: #46506a; margin-bottom: 8px; }
.td-details { white-space: pre-line; background: #f7f9fd; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.td-details:empty { display: none; }
.td-status { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.td-updates { max-height: 260px; overflow-y: auto; margin-bottom: 10px; }
.td-update { border-left: 3px solid var(--blue); background: #fff; padding: 6px 10px; margin-bottom: 6px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.07); font-size: 13px; }
.td-update.auto { border-left-color: #9aa4b8; color: #46506a; }
.tdu-head { font-size: 11.5px; margin-bottom: 2px; }
.td-addupdate { display: flex; gap: 8px; flex-wrap: wrap; }
.td-addupdate textarea { flex: 1 1 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
@media screen and (max-width: 760px) { .task-board { grid-template-columns: 1fr; } .search-box { min-width: 0; flex: 1; } }

/* ---------- Bitácora diaria (Mi día) ---------- */
.time-pair { display: flex; gap: 8px; }
.time-pair input { flex: 1; }
.wl-actions { display: flex; gap: 10px; }
.wl-entry { background: #fff; border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-left: 4px solid var(--blue); }
.wl-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.wl-time { font-size: 13px; font-weight: 700; color: var(--blue); white-space: nowrap; }
.wl-notes { margin: 6px 0; font-size: 14px; white-space: pre-line; }
.wl-btns { display: flex; gap: 6px; justify-content: flex-end; }
.wl-btns button { font-size: 12.5px; padding: 4px 10px; }

.wl-entry.pending { border-left-color: #b25a00; background: #fffaf4; }
.wl-with { font-size: 12.5px; color: #6a3ab8; margin-top: 3px; }
.dash-hours { color: var(--blue-dark); font-weight: 700; margin: -6px 0 12px; }

/* ---------- Bitácora lateral (editor de reportes) ---------- */
.wl-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100vw; z-index: 60;
  background: var(--bg); box-shadow: -4px 0 20px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
}
.wl-drawer-head {
  background: var(--blue-dark); color: #fff; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.wl-drawer-head button { background: transparent; border: none; color: #fff; font-size: 16px; cursor: pointer; }
.wl-drawer-body { overflow-y: auto; padding: 12px; }

/* ---------- Panel (dashboard) ---------- */
.dash-title { color: var(--blue-dark); margin: 6px 0 14px; }
.dash-nav, .dash-modes { display: flex; gap: 4px; }
.dash-modes button.active { background: var(--blue-dark); color: #fff; border-color: var(--blue-dark); }
.dash-chip { background: #f2f5fb; border-left: 3px solid var(--blue); border-radius: 6px; padding: 6px 8px; margin: 4px 0; font-size: 12.5px; }
.dash-chip .wl-time { margin-left: 6px; font-size: 12px; }
.dash-chip-notes { color: #46506a; font-size: 12px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
/* Miniaturas de adjuntos más pequeñas dentro de las tarjetas del calendario */
.dash-chip .attach-grid { margin-top: 5px; gap: 5px; }
.dash-chip .attach-thumb { width: 52px; height: 52px; }
.dash-chip .attach-thumb.file { font-size: 20px; }
.dash-user-day { background: #fff; border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.dash-user-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.dash-week-scroll { overflow-x: auto; }
.dash-week { width: 100%; min-width: 900px; border-collapse: collapse; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.dash-week th { background: var(--blue-dark); color: #fff; padding: 8px; font-size: 12.5px; }
.dash-week th.today { background: var(--blue); }
.dash-week td { border: 1px solid var(--border); padding: 5px; vertical-align: top; min-width: 110px; cursor: pointer; }
.dash-week td.today { background: #f2f7ff; }
.dash-week .dash-worker { font-weight: 700; color: var(--blue-dark); min-width: 130px; cursor: default; }
.dash-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dm-head { text-align: center; font-weight: 700; color: var(--blue-dark); font-size: 12.5px; padding: 4px; }
.dm-cell { background: #fff; border-radius: 8px; min-height: 84px; padding: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.07); cursor: pointer; }
.dm-cell:hover { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.dm-cell.other { opacity: .38; }
.dm-cell.today { outline: 2px solid var(--blue); }
.dm-num { font-weight: 700; font-size: 12.5px; color: #46506a; }
.dm-badge { background: #eaf0fb; color: var(--blue-dark); border-radius: 5px; font-size: 10.5px; padding: 2px 5px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Visor de fotos/adjuntos (lightbox) ---------- */
img[data-att-url] { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.lightbox .lb-content { max-width: 96vw; max-height: 92vh; display: flex; }
.lightbox img, .lightbox video { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 6px; }
.lb-close, .lb-download { position: absolute; top: 14px; width: 46px; height: 46px; border-radius: 50%; background: #fff; color: #1c2331; font-size: 22px; display: flex; align-items: center; justify-content: center; cursor: pointer; border: none; text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.lb-close { right: 16px; }
.lb-download { right: 74px; font-size: 20px; }

/* ---------- Ayuda / Manual de uso ---------- */
.help-modal { position: fixed; inset: 0; z-index: 150; background: rgba(10,20,50,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.help-box { background: #fff; border-radius: 14px; width: 900px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 12px 50px rgba(0,0,0,.35); overflow: hidden; }
.help-head { background: var(--blue-dark); color: #fff; padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; }
.help-head button { background: transparent; border: none; color: #fff; font-size: 17px; cursor: pointer; }
.help-body { display: flex; overflow: hidden; flex: 1; }
.help-index { width: 230px; min-width: 170px; border-right: 1px solid var(--border); overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; background: #f7f9fd; }
.help-index button { text-align: left; border: none; background: transparent; padding: 9px 10px; border-radius: 8px; font: inherit; font-size: 13.5px; cursor: pointer; }
.help-index button:hover { background: #e9eef8; }
.help-index button.active { background: var(--blue-dark); color: #fff; }
.help-content { flex: 1; overflow-y: auto; padding: 18px 22px; font-size: 14px; line-height: 1.55; }
.help-content h3 { margin-top: 0; color: var(--blue-dark); }
.help-content h4 { color: var(--blue); margin: 16px 0 6px; }
.help-content ul { margin: 6px 0; padding-left: 20px; }
.help-content li { margin-bottom: 5px; }
@media screen and (max-width: 700px) {
  .help-body { flex-direction: column; }
  .help-index { width: auto; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Login ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--blue-dark);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #fff; border-radius: 12px; padding: 34px 30px; width: 320px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.login-brand { font-size: 24px; font-weight: 900; color: var(--blue); text-align: center; }
.login-sub { font-size: 12px; font-weight: 700; color: var(--red); text-align: center; letter-spacing: 1px; margin-bottom: 10px; }
.login-box input { font: inherit; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; }
.login-box button { padding: 11px; font-size: 15px; }
.login-error { color: var(--red); text-align: center; margin: 0; font-size: 13px; }
.user-chip { color: #aebbdd; font-size: 12.5px; margin-left: 10px; }

/* ---------- Reportes ---------- */
.status-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.status-filter button { border-radius: 20px; font-size: 13px; padding: 6px 14px; }
.status-filter button.active { background: var(--blue-dark); color: #fff; border-color: var(--blue-dark); }
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.report-card {
  background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08);
  cursor: pointer; border-left: 4px solid var(--blue);
}
.report-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.15); }
.rc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.rc-title { font-weight: 700; color: var(--blue-dark); }
.rc-ref { font-size: 12.5px; color: #46506a; margin: 3px 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.rc-meta { font-size: 12px; color: #7a8398; }
.report-card.pending { border-left-color: #b25a00; background: #fffaf4; }
.pill-pending { font-size: 11px; padding: 1px 8px; border-radius: 20px; background: #ffe9d6; color: #b25a00; font-weight: 700; }
.sync-status { font-size: 13px; color: #b25a00; font-weight: 600; align-self: center; }
.st-PENDIENTE { background: #ffe9d6; color: #b25a00; }
.st-ENPROCESO { background: #dbe7ff; color: var(--blue); }
.st-ENTREGADO { background: #d7f2e0; color: var(--profit); }
.st-FACTURADO { background: #e8ddf7; color: #6a3ab8; }

.rep-section { background: #fff; border-radius: 8px; padding: 12px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 12px; }
.rs-head { display: flex; gap: 10px; margin-bottom: 8px; }
.rs-head .rs-title { flex: 1; font: inherit; font-weight: 700; text-transform: uppercase; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; }
.rep-section textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; box-sizing: border-box; }
.rep-section textarea:focus, .rs-title:focus { outline: none; border-color: var(--blue); }

/* ---------- Fotos del reporte ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.photo-card { background: #fff; border-radius: 10px; padding: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.photo-card img { width: 100%; height: 160px; object-fit: contain; background: #f2f4f8; border-radius: 6px; }
.photo-card .pc-num { font-size: 11.5px; font-weight: 700; color: var(--blue); margin-bottom: 4px; }
.photo-card input { width: 100%; font: inherit; font-size: 13px; padding: 6px 8px; margin-top: 6px; border: 1px solid var(--border); border-radius: 6px; box-sizing: border-box; }
.pc-actions { display: flex; gap: 4px; margin-top: 6px; justify-content: center; }
.pc-actions button { padding: 4px 10px; font-size: 13px; }

/* ---------- Anexo fotográfico impreso ---------- */
.annex-title { text-align: center; font-weight: 700; font-size: 15px; margin: 4px 0 14px; }
.annex-grid { display: grid; gap: 8mm; }
.annex-grid.per-1 { grid-template-columns: 1fr; }
.annex-grid.per-2 { grid-template-columns: 1fr; }
.annex-grid.per-4 { grid-template-columns: 1fr 1fr; }
.annex-fig { margin: 0; text-align: center; }
.annex-fig img { max-width: 100%; border: 1px solid #ccc; object-fit: contain; }
.per-1 .annex-fig img { max-height: 200mm; }
.per-2 .annex-fig img { max-height: 100mm; }
.per-4 .annex-fig img { max-height: 88mm; }
.annex-fig figcaption { font-size: 11.5px; font-style: italic; color: var(--blue-dark); margin-top: 4px; }

/* ---------- Móvil (SOLO pantalla: "screen" evita que estas reglas
     se cuelen al imprimir desde el celular y aplasten los márgenes) ---------- */
@media screen and (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 8px 10px; }
  .brand-sub { display: none; }
  nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .navbtn { padding: 8px 10px; font-size: 13px; margin-left: 0; }
  .view { padding: 0 10px 80px; margin-top: 12px; }
  .editor-head { flex-direction: column; align-items: stretch; }
  .editor-actions { justify-content: stretch; }
  .editor-actions button { flex: 1; padding: 12px; font-size: 15px; }
  .items-toolbar { flex-direction: column; }
  .grid { display: block; overflow-x: auto; }
  .totals-panel { flex-direction: column; }
  .photo-grid { grid-template-columns: 1fr 1fr; }
  .report-cards { grid-template-columns: 1fr; }
  button { min-height: 40px; }
  /* La hoja NO se deforma en el celular: mantiene su tamaño real de documento
     y se escala completa con zoom (ver fitSheets en app.js) */
}
