/* ==========================================================================
   Plataforma de Gestion Bodegas Manzanos.
   Extiende el sistema de diseno MB (mb-styles.css). Todo lo de aqui usa sus
   tokens: no hay una segunda paleta ni una segunda tipografia.

   Contiene ademas el "Modo Bodega" (README seccion 8.3): alto contraste,
   objetivos tactiles de 56 px y modo oscuro para nave con poca luz.
   ========================================================================== */

/* ---------- Formularios (mb-styles solo trae input[type=search]) ---------- */
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
.field .help { font-size: 12px; color: var(--muted); margin: 5px 0 0; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=datetime-local], input[type=date], input[type=time],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(154, 123, 74, .18);
}
input:disabled, select:disabled { background: #f4f1ec; color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 180px; }

button.action.wide { width: 100%; padding: 13px 17px; font-size: 15px; }
button.action.danger { background: var(--danger); }
button.action.danger:hover { background: #74262e; }

a.action {
  display: inline-block;
  text-decoration: none;
  border-radius: 5px;
  padding: 9px 17px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}
a.action.secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }

/* ---------- Avisos ---------- */
.notice.error {
  background: var(--danger-soft);
  border-color: #e3c3c6;
  color: var(--danger);
}
.notice.ok { background: #e6ede2; border-color: #cbd9c3; color: var(--success); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Paginas sin la carcasa de la app (login, instalador) ---------- */
body.bare { display: block; }
.bare-wrap { max-width: 520px; margin: 0 auto; padding: 44px 20px 60px; }
.bare-brand { text-align: center; margin-bottom: 26px; }
.bare-brand img { height: 34px; }
.bare-brand .subtitle { margin-top: 10px; }
.bare-foot {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: 26px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 26px 28px;
}
.panel h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  margin: 0 0 4px;
}
.panel .lead { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

/* ---------- Instalador ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 22px; }
.steps li {
  flex: 1;
  list-style: none;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  border-top: 3px solid var(--border);
  padding-top: 7px;
  font-weight: 700;
}
.steps li.on { color: var(--accent); border-top-color: var(--accent); }
.steps li.done { color: var(--success); border-top-color: var(--success); }

.checklist { list-style: none; margin: 0 0 20px; padding: 0; font-size: 13px; }
.checklist li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: none; }
.checklist .mark { font-weight: 700; width: 16px; flex: none; }
.checklist .ok   { color: var(--success); }
.checklist .warn { color: var(--warn); }
.checklist .bad  { color: var(--danger); }
.checklist .what { flex: 1; }
.checklist .detail { color: var(--muted); font-size: 12px; }

.steplog { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.steplog li { padding: 6px 0 6px 20px; position: relative; border-bottom: 1px solid var(--border); }
.steplog li::before { content: "✓"; position: absolute; left: 0; color: var(--success); font-weight: 700; }

/* ---------- Carcasa de la aplicacion ---------- */
.app-header .winery-select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 13px;
  background: #fff;
  max-width: 220px;
}
.app-header .user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.app-header .user-chip a { color: var(--accent); text-decoration: none; font-weight: 600; }

.app-nav {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.app-nav a {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.app-nav a:hover { color: var(--accent); }
.app-nav a.on { color: var(--accent); border-bottom-color: var(--accent); }

.impersonation-bar {
  background: var(--danger);
  color: #fff;
  padding: 9px 28px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}
.impersonation-bar a { color: #fff; text-decoration: underline; }

/* Tarjetas grandes de modulo de la pantalla de inicio (seccion 6.1) */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.module-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: border-color .15s, transform .15s;
}
.module-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.module-card h3 { font-family: var(--serif); font-size: 18px; font-weight: 500; margin: 0 0 6px; }
.module-card p { color: var(--muted); font-size: 13px; margin: 0; }

/* Matriz de permisos (seccion 4.4) */
.matrix-wrap { overflow-x: auto; }
.matrix th.role { text-align: center; min-width: 92px; }
.matrix td.role { text-align: center; }
.matrix tr.group td {
  background: var(--accent-soft);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #6b5325;
}
.matrix input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--serif); font-size: 24px; font-weight: 500; margin: 0; flex: 1; }

/* ==========================================================================
   MODO BODEGA (README seccion 8.3)
   Se activa con [data-mode="cellar"] en <html>, y automaticamente por debajo
   de 820 px. Alto contraste, objetivos de 56 px, sin hover ni decoracion.
   ========================================================================== */
:root[data-mode="cellar"] {
  --bg: #14120f;
  --panel: #1e1b17;
  --border: #3b352c;
  --text: #f5f1e8;
  --muted: #b3a894;
  --accent: #d4a961;
  --accent-hover: #e2bd7e;
  --accent-soft: #2a251d;
  --danger: #e0666f;
  --danger-soft: #3a1f22;
  --success: #8fb180;
}
:root[data-mode="cellar"] body { background: var(--bg); color: var(--text); }
:root[data-mode="cellar"] th { background: #24201a; }
:root[data-mode="cellar"] tbody tr:hover { background: #24201a; }
:root[data-mode="cellar"] input,
:root[data-mode="cellar"] select,
:root[data-mode="cellar"] textarea { background: #14120f; color: var(--text); }
:root[data-mode="cellar"] .filter-btn { background: var(--panel); }
:root[data-mode="cellar"] button.action { color: #14120f; }

:root[data-mode="cellar"] input, :root[data-mode="cellar"] select,
:root[data-mode="cellar"] button.action, :root[data-mode="cellar"] .filter-btn,
:root[data-mode="cellar"] a.action {
  min-height: 56px;          /* se usa con guantes */
  font-size: 17px;
}
:root[data-mode="cellar"] .app-nav a { padding: 18px 16px; font-size: 15px; }
:root[data-mode="cellar"] main { padding: 18px; }

@media (max-width: 820px) {
  main { padding: 16px; }
  .app-header { padding: 12px 16px; gap: 12px; flex-wrap: wrap; }
  .app-nav { padding: 0 10px; }
  input, select, textarea, button.action, .filter-btn { min-height: 52px; font-size: 16px; }
  .page-head h2 { font-size: 20px; }
  .bare-wrap { padding: 26px 14px 40px; }
  .panel { padding: 20px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Impresion: etiquetas QR y fichas de fermentacion */
@media print {
  .app-header, .app-nav, .toolbar, .impersonation-bar, .bare-foot { display: none; }
  body { background: #fff; }
  .panel, .table-wrap { border: none; }
}

/* ==========================================================================
   Modulo de fermentacion: mapa de depositos (Fase 1)
   ========================================================================== */
.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.tank-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 6px solid var(--muted);   /* semaforo */
  border-radius: 6px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 132px;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.tank-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.tank-card.s-free     { border-left-color: #cfc7b8; opacity: .82; }
.tank-card.s-ok       { border-left-color: var(--success); }
.tank-card.s-warn     { border-left-color: var(--warn); }
.tank-card.s-critical { border-left-color: var(--danger); }

.tank-card .tc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tank-card .tc-code { font-weight: 700; font-size: 15px; }
/* Numero de deposito, protagonista de la tarjeta */
.tank-card .tc-number { font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1; }
.tank-card .tc-sub { color: var(--muted); font-size: 11px; font-family: monospace; margin-top: -2px; }
.tank-card .tc-cap  { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tank-card .tc-wine { font-size: 13px; color: var(--text); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tank-card .tc-free { color: var(--muted); font-style: italic; font-size: 13px; }
.tank-card .tc-status { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.tank-card .tc-metrics { display: flex; gap: 16px; margin-top: auto; align-items: flex-end; }
.tank-card .tc-metric .m-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tank-card .tc-metric .m-value { font-family: var(--serif); font-size: 26px; font-weight: 500; line-height: 1; }
.tank-card .tc-metric .m-value.oor { color: var(--danger); }
.tank-card .tc-ago { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tank-card .tc-ago.stale { color: var(--danger); font-weight: 600; }
.tank-card .tc-drop { font-size: 11px; color: var(--muted); }

.tank-loc-head {
  font-family: var(--serif); font-weight: 500; font-size: 17px; margin: 24px 0 12px;
}
.tank-loc-head span { color: var(--muted); font-size: 13px; font-family: system-ui, sans-serif; }

/* Formulario rapido de medida (movil, con guantes) */
.measure-primary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.measure-primary .field { flex: 1; min-width: 150px; margin-bottom: 8px; }
.measure-primary input { font-size: 30px; font-family: var(--serif); text-align: center; height: 64px; }
.measure-ref { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.measure-more { border: 1px solid var(--border); border-radius: 6px; margin: 14px 0; background: var(--panel); }
.measure-more > summary { padding: 14px 16px; cursor: pointer; font-weight: 600; color: var(--accent); }
.measure-more[open] > summary { border-bottom: 1px solid var(--border); }
.measure-more .more-body { padding: 16px; }
.measure-save {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%);
  padding: 16px 0 4px; margin-top: 10px;
}
.measure-save button { width: 100%; min-height: 60px; font-size: 18px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); }
.timeline .t-when { font-size: 12px; color: var(--muted); }

/* ==========================================================================
   Lanzador de modulos tipo ERP (pantalla de inicio, estilo TWIN-DMB)
   ========================================================================== */
.launcher-head { margin-bottom: 26px; }
.launcher-head h2 { font-family: var(--serif); font-size: 28px; font-weight: 500; margin: 0 0 2px; }

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}
.launcher-grid.sub { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

/* Mosaico tipo ERP: cuadrado, icono grande centrado sobre banda de acento,
   etiqueta debajo. */
.launcher-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  transition: border-color .15s, transform .12s, box-shadow .15s;
}
.launcher-tile:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 22px rgba(0,0,0,.12);
}
/* Banda superior con el icono, en oro MB */
.launcher-tile .lt-icon {
  width: 100%;
  flex: 1;
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-hover));
}
.launcher-tile .lt-icon svg { width: 52px; height: 52px; }
.launcher-tile .lt-name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  padding: 14px 12px 4px;
  line-height: 1.15;
}
.launcher-tile .lt-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  padding: 0 14px;
}
.launcher-tile .lt-items {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 12px 14px;
  margin-top: auto;
}

/* Etiqueta de seccion en la barra de navegacion */
.app-nav .nav-section {
  padding: 12px 6px 12px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
  border-left: 1px solid var(--border);
  margin-left: 6px;
  white-space: nowrap;
  align-self: center;
}

:root[data-mode="cellar"] .launcher-tile .lt-icon { background: #2a251d; }

/* ==========================================================================
   Registro de entrada de uva: tabla ancha, pegable desde Excel
   ========================================================================== */
.intake-grid { border-collapse: collapse; font-size: 13px; }
.intake-grid th {
  position: sticky; top: 0;
  background: #faf7f1;
  white-space: nowrap;
  font-size: 10px;
  padding: 6px 6px;
  z-index: 1;
}
.intake-grid td { padding: 2px; border: 1px solid var(--border); }
.intake-grid input {
  border: none; background: transparent; padding: 6px 6px;
  min-width: 70px; font-size: 13px; border-radius: 0;
}
.intake-grid input.chem { min-width: 64px; text-align: right; }
.intake-grid input:focus {
  outline: 2px solid var(--accent); outline-offset: -2px;
  background: var(--accent-soft); box-shadow: none;
}
.intake-grid tr:nth-child(even) td { background: rgba(0,0,0,.015); }
:root[data-mode="cellar"] .intake-grid th { background: #24201a; }

/* Columnas de control (Densidad, Temperatura, Grado) en la entrada de uva */
.intake-grid th.control { background: var(--accent-soft); color: #6b5325; }
.intake-grid td:has(input.control) { background: rgba(154,123,74,.07); }
.intake-grid input.control { font-weight: 600; }

/* Fecha de llenado en la tarjeta del mapa */
.tank-card .tc-fill { font-size: 11px; color: var(--muted); margin-top: -2px; }
.tank-card.s-free .tc-fill { color: var(--muted); }

/* Tooltip de la curva de fermentación */
.chart-wrap { position: relative; }
.chart-wrap circle.pt { cursor: pointer; transition: r .1s; }
.chart-wrap circle.pt:hover { stroke: #fff; stroke-width: 2; }
.chart-tip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #211e1a;
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.chart-tip strong { color: #d4a961; }
