/* Terra Collective · Operations Hub
   Sistema visual "Sand / Terracotta / Earth" (v1.0, 27-sep-2026):
   - Earth y Sand cargan el texto. Linen es fondo secundario.
   - Terracotta y Olive son solo superficie (puntos, barras, franjas): nunca texto.
   - Texto alineado a la izquierda. Playfair Display para títulos, Work Sans para leer. */

:root {
  --sand: #F5EFE7;
  --panel: #F0E9DF;
  --linen: #D8C9B7;
  --line: #E1D6C6;
  --earth: #4B3A2E;
  --ink: #241E1F;
  --muted: #6B5A4C;
  --terra: #B76E4E;
  --olive: #8A8F72;
  --ok: #2E6E4E;
  --bad: #B23A3A;
  --radius: 10px;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Work Sans', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--sand);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.side {
  background: var(--earth);
  color: var(--sand);
  padding: 28px 18px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
}
.side .brand img { width: 150px; }
.side .brand small {
  display: block; margin-top: 10px;
  font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: #CBBBA8;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  background: none; border: 0; text-align: left; cursor: pointer;
  color: var(--sand); padding: 10px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; font-size: 0.92rem;
  border-left: 3px solid transparent;
}
.nav button:hover { background: rgba(245, 239, 231, 0.08); }
.nav button.on { background: rgba(245, 239, 231, 0.12); border-left-color: var(--terra); }
.nav .ico { width: 18px; text-align: center; opacity: 0.85; }
.side .foot { margin-top: auto; font-size: 0.72rem; color: #CBBBA8; line-height: 1.6; }
.side .foot button {
  background: none; border: 1px solid rgba(245,239,231,0.3); color: var(--sand);
  border-radius: 6px; padding: 5px 9px; font-size: 0.72rem; cursor: pointer; margin: 6px 6px 0 0;
}

.main { padding: 36px 44px 80px; max-width: 1180px; width: 100%; }

.head { margin-bottom: 26px; }
.eyebrow {
  font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.eyebrow::before { content: '✧'; color: var(--terra); font-size: 0.9rem; letter-spacing: 0; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 2.3rem; line-height: 1.1; margin: 8px 0 6px; color: var(--earth); }
h2 { font-family: var(--serif); font-weight: 400; font-size: 1.35rem; margin: 0 0 4px; color: var(--earth); }
h3 { font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 1.1rem; margin: 0 0 6px; color: var(--earth); }
.lead { color: var(--muted); max-width: 640px; margin: 0; }
.note { color: var(--muted); font-size: 0.85rem; }

/* ---------- Bloques ---------- */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.span2 { grid-column: span 2; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px;
}
.card.dark { background: var(--earth); color: var(--sand); border-color: var(--earth); }
.card.dark h2, .card.dark h3 { color: var(--sand); }
.card.dark .note { color: #D8C9B7; }
.section { margin-top: 30px; }
.section > .row-between { margin-bottom: 12px; }

.kpi .label { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .val { font-family: var(--serif); font-size: 2.1rem; color: var(--earth); line-height: 1.15; margin-top: 6px; }
.kpi .sub { font-size: 0.82rem; color: var(--muted); }
.kpi { position: relative; overflow: hidden; }
.kpi::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--terra); }
.kpi.olive::after { background: var(--olive); }
.kpi.linen::after { background: var(--linen); }

.countdown { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 4px; }
.countdown .n { font-family: var(--serif); font-size: 3.2rem; line-height: 1; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Chips: Earth sobre Linen; el color lo pone el punto, nunca el texto */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--sand); border: 1px solid var(--line); color: var(--earth);
  border-radius: 99px; padding: 2px 10px 2px 8px; font-size: 0.75rem; font-weight: 500; white-space: nowrap;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--linen); display: inline-block; }
.chip.t i { background: var(--terra); }
.chip.o i { background: var(--olive); }
.chip.ok i { background: var(--ok); }
.chip.bad i { background: var(--bad); }
.chip.e i { background: var(--earth); }

/* Alertas */
.alerts { display: flex; flex-direction: column; gap: 10px; }
.alert {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 12px 0;
  overflow: hidden;
}
.alert .bar { align-self: stretch; background: var(--terra); }
.alert.o .bar { background: var(--olive); }
.alert.e .bar { background: var(--earth); }
.alert b { color: var(--earth); }
.alert .sm { font-size: 0.82rem; color: var(--muted); }

/* Tablas */
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb { width: 40px; min-width: 40px; height: 50px; max-width: none; object-fit: cover; border-radius: 4px; background: var(--linen); }
.strike { text-decoration: line-through; color: var(--muted); font-size: 0.78rem; margin-right: 4px; }
.id { font-family: 'Courier New', monospace; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* Botones */
.btn {
  background: var(--earth); color: var(--sand); border: 1px solid var(--earth);
  border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 500; font-size: 0.88rem;
}
.btn:hover { background: var(--ink); }
.btn.ghost { background: transparent; color: var(--earth); border-color: var(--linen); }
.btn.ghost:hover { background: var(--panel); }
.btn.sm { padding: 5px 10px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Filtros y formularios */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.82rem; color: var(--muted); }
.seg button.on { background: var(--sand); color: var(--earth); font-weight: 600; box-shadow: 0 1px 2px rgba(75,58,46,0.12); }
input[type=text], input[type=number], input[type=date], select, textarea {
  background: var(--sand); border: 1px solid var(--linen); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--earth); outline-offset: 1px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 0.76rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Barras de tallas */
.sizes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; align-items: end; height: 130px; margin-top: 12px; }
.sizes .col { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-end; height: 100%; gap: 6px; }
.sizes .b { background: var(--olive); border-radius: 4px 4px 0 0; min-height: 3px; }
.sizes .b.low { background: var(--terra); }
.sizes .lbl { font-size: 0.75rem; color: var(--muted); display: flex; justify-content: space-between; }

/* Curaduría paso a paso */
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; grid-template-columns: 34px 1fr auto; gap: 14px; align-items: start; }
.step .n { width: 30px; height: 30px; border-radius: 50%; background: var(--sand); border: 1px solid var(--linen); display: grid; place-items: center; font-family: var(--serif); color: var(--earth); }
.step.yes .n { background: var(--olive); border-color: var(--olive); color: var(--ink); }
.step.no .n { background: var(--terra); border-color: var(--terra); color: var(--ink); }
.step.locked { opacity: 0.45; }
.step ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.85rem; color: var(--muted); }
.yn { display: flex; gap: 6px; }
.quote { font-family: var(--serif); font-style: italic; font-size: 1.15rem; color: var(--earth); border-left: 3px solid var(--terra); padding: 4px 0 4px 14px; margin: 10px 0; }

/* Checklist */
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check:last-child { border-bottom: 0; }
.check .box { width: 20px; height: 20px; border-radius: 5px; border: 1.5px solid var(--earth); flex: none; margin-top: 2px; display: grid; place-items: center; font-size: 0.8rem; }
.check.done .box { background: var(--earth); color: var(--sand); }
.check.done .t { color: var(--muted); text-decoration: line-through; }
.check .who { font-size: 0.75rem; color: var(--muted); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.progress span { display: block; height: 100%; background: var(--olive); }

/* Políticas */
.pol dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 12px 0 0; font-size: 0.88rem; }
.pol dt { color: var(--muted); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.04em; }
.pol dd { margin: 0; color: var(--ink); }
.md { width: 100%; font-size: 0.82rem; margin-top: 8px; }

/* Avisos */
.banner { background: var(--linen); color: var(--earth); border-radius: var(--radius); padding: 10px 16px; font-size: 0.84rem; margin-bottom: 22px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: var(--earth); color: var(--sand); padding: 10px 18px; border-radius: 8px; font-size: 0.86rem; opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { padding: 28px; text-align: left; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(36,30,31,0.45); display: none; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--sand); border-radius: 12px; padding: 24px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }

/* ---------- Celular ---------- */
.mobile-top { display: none; }
@media (max-width: 980px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; background: var(--earth); padding: 14px 16px; position: sticky; top: 0; z-index: 20; }
  .mobile-top img { width: 96px; }
  .mobile-top span { color: #CBBBA8; font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; }
  .tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--earth); display: flex; overflow-x: auto; z-index: 20; padding-bottom: env(safe-area-inset-bottom, 0); }
  .tabbar button { flex: 1 0 auto; min-width: 64px; background: none; border: 0; color: #CBBBA8; padding: 9px 6px 10px; font-size: 0.64rem; display: flex; flex-direction: column; align-items: center; gap: 3px; border-top: 2px solid transparent; }
  .tabbar button.on { color: var(--sand); border-top-color: var(--terra); }
  .tabbar .ico { font-size: 1rem; }
  .main { padding: 22px 16px 96px; }
  h1 { font-size: 1.8rem; }
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .g4.kpis { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: auto; }
  .form { grid-template-columns: 1fr; }
  .pol dl { grid-template-columns: 1fr; gap: 2px; }
  .pol dd { margin-bottom: 8px; }
  .step { grid-template-columns: 30px 1fr; }
  .step .yn { grid-column: 2; }
  .kpi .val { font-size: 1.7rem; }
}
@media (min-width: 761px) { .tabbar { display: none; } }

/* Que las tablas anchas se desplacen dentro de su caja, nunca la página */
.main, .grid > *, .app > * { min-width: 0; }
@media (max-width: 760px) { .tablewrap table { min-width: 680px; } }

/* ---------- Inicio de sesión (Supabase) ---------- */
body.locked .app, body.locked .tabbar, body.locked .mobile-top { display: none; }
#login:empty { display: none; }
#login { position: fixed; inset: 0; background: var(--earth); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.login-card { width: 100%; max-width: 360px; background: var(--sand); border-radius: var(--radius); padding: 28px 24px; }
.login-card img { height: 28px; display: block; background: var(--earth); padding: 6px 10px; border-radius: 6px; }
.login-card small { display: block; color: var(--muted); margin: 6px 0 18px; }
.login-card h2 { font-family: var(--serif); font-weight: 600; margin: 0 0 12px; color: var(--earth); }
.login-card .f { display: block; margin-bottom: 12px; font-size: 0.85rem; color: var(--earth); }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--linen); border-radius: 8px; background: #fff; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-msg { color: var(--earth); font-size: 0.9rem; }
