/* ---------- tokens ---------- */
:root {
  color-scheme: dark;
  --paper: #141A15;      /* pizarra de bar, verde-negro */
  --paper-0: rgba(20,26,21,0);
  --surface: #1F2721;
  --ink: #F0F1E8;        /* texto: hoja de laurel claro */
  --ink-soft: #A7B0A1;
  --line: #3A463C;
  --pimenton: #FF6B47;   /* solo para lo sin dueño y borrar */
  --pimenton-soft: rgba(255,107,71,.16);
  --oliva: #9CC25A;      /* asignado / seleccionado */
  --oliva-soft: rgba(156,194,90,.18);
  --focus: #8AB4FF;

  --display: "Bricolage Grotesque", "Arial Black", "Helvetica Neue", Arial, sans-serif;
  --body: "Karla", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 12px;
  --tap: 44px;           /* altura mínima táctil */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.35;
  padding: 0 12px calc(84px + var(--safe-b));
  max-width: 640px;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- cabecera ---------- */
.top { padding: 14px 0 4px; }

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(28px, 8vw, 38px);
  line-height: 1;
  letter-spacing: -.02em;
  font-variation-settings: "opsz" 96;
}
.banderilla { width: 18px; height: 30px; flex: none; color: var(--ink); transform: rotate(-12deg); }

.status {
  margin: 8px 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.2;
  font-variation-settings: "opsz" 24;
}
.status b { color: var(--pimenton); }
.status.ok b { color: var(--oliva); }

.sync { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); min-height: 1.2em; }
.sync.err { color: var(--pimenton); font-weight: 700; }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  background: linear-gradient(var(--paper) 85%, var(--paper-0));
}
.toolbar .select { flex: 1; min-width: 0; }

/* ---------- controles ---------- */
.field { display: block; margin: 0 0 12px; }
.field .label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field .label small { text-transform: none; letter-spacing: 0; font-weight: 400; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px; /* ≥16px: iOS no hace zoom */
}
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10'%3E%3Cpath d='M2 2l6 6 6-6' fill='none' stroke='%23F0F1E8' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.textarea { line-height: 1.45; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }

.btn {
  min-height: var(--tap);
  padding: 8px 14px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--ink); color: var(--paper); }
.btn--secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn--danger { background: var(--pimenton-soft); color: var(--pimenton); }
.btn--big { width: 100%; min-height: 52px; font-size: 17px; }
.btn[disabled] { opacity: .6; cursor: default; }

.row { display: flex; gap: 8px; }
.row .input { flex: 1; min-width: 0; }

/* ---------- lista ---------- */
.list { padding-top: 2px; }

.empty {
  margin: 14px 0;
  padding: 20px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-align: center;
}

.cat { margin: 0 0 14px; }
.cat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 5px 2px;
}
.cat-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .01em;
  font-variation-settings: "opsz" 24;
}
.cat-meta { font-size: 12px; color: var(--ink-soft); font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.cat-meta.warn { color: var(--pimenton); }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }

.item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 3px 5px 3px 0;
}
.item.orphan { border-color: var(--pimenton); border-left-width: 5px; }

.item-main {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 5px 8px 5px 10px;
  border: 0;
  background: transparent;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.item-name { font-weight: 700; font-size: 16px; line-height: 1.2; overflow-wrap: anywhere; }
.item-desc { font-size: 13px; line-height: 1.2; color: var(--ink-soft); overflow-wrap: anywhere; }

/* personas asignadas + botón de asignar, a la derecha */
.owners {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  max-width: 50%;
  flex: none;
}
.owner {
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 999px;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.owner--more { background: var(--line); color: var(--ink); }
.add-owner {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 999px;
  border: 1.5px dashed var(--ink-soft);
  background: transparent;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
}
.add-owner svg { width: 20px; height: 20px; }
.add-owner.orphan { background: var(--pimenton); border: 0; color: var(--paper); }

/* ---------- selector de personas (hoja) ---------- */
.picks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
  padding: 6px 12px 6px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 17px;
  font-weight: 700;
  text-align: left;
}
.pick.on { border-color: var(--oliva); background: var(--oliva-soft); }
.pick .mark {
  width: 26px; height: 26px;
  flex: none;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-size: 15px;
  color: var(--paper);
}
.pick.on .mark { background: var(--oliva); border-color: var(--oliva); }
.picks-empty { margin: 0 0 10px; color: var(--ink-soft); }

/* chips seleccionables dentro del formulario */
.chip-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-pick {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: transparent;
  font-weight: 700;
  font-size: 14px;
}
.chip-pick.on { background: var(--oliva-soft); border-color: var(--oliva); color: var(--oliva); }
.chip-picks-empty { color: var(--ink-soft); font-size: 14px; margin: 0; }

/* ---------- gente ---------- */
.people { margin-top: 8px; padding-top: 12px; border-top: 2px solid var(--line); }
.section-title {
  margin: 0 0 8px 2px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  font-variation-settings: "opsz" 24;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 38px;
  padding: 3px 3px 3px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}
.chip .count { font-weight: 400; opacity: .8; font-size: 12px; }
.chip .x {
  width: 32px; height: 32px;
  border: 0; border-radius: 999px;
  background: rgba(255,255,255,.16);
  color: inherit;
  font-size: 18px; line-height: 1;
  display: grid; place-items: center;
}
.chips-empty { color: var(--ink-soft); margin: 0 0 10px 2px; font-size: 14px; }

.foot { margin: 18px 0 0; color: var(--ink-soft); font-size: 13px; }

/* ---------- barra inferior ---------- */
.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 8px 12px calc(10px + var(--safe-b));
  background: linear-gradient(var(--paper-0), var(--paper) 40%);
  z-index: 6;
}
.bottom-bar .btn { max-width: 616px; margin-inline: auto; display: block; box-shadow: 0 8px 24px rgba(0,0,0,.45); }

/* ---------- hojas (dialog) ---------- */
.sheet {
  border: 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  margin: 0;
  width: 100%;
  max-width: 100%;
  position: fixed;
  inset: auto 0 0 0;
  max-height: 92dvh;
  overflow: auto;
  background: var(--surface);
  color: var(--ink);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
}
.sheet::backdrop { background: rgba(0,0,0,.6); }
.sheet[open] { animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet .input, .sheet .select { background: var(--paper); }
.sheet .pick { background: var(--paper); }
.sheet .pick.on { background: var(--oliva-soft); }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  font-variation-settings: "opsz" 24;
}
.btn-x {
  width: 42px; height: 42px;
  border: 0; border-radius: 999px;
  background: var(--paper);
  font-size: 24px; line-height: 1;
}
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.hint { margin: 0 0 10px; color: var(--ink-soft); font-size: 14px; }
.form-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--pimenton-soft);
  color: var(--pimenton);
  font-weight: 700;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 20;
  text-align: center;
}
.toast.err { background: var(--pimenton); color: var(--paper); }

/* ---------- pantallas anchas ---------- */
@media (min-width: 640px) {
  .sheet {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 480px;
    border-radius: 20px;
    max-height: 90vh;
  }
  .sheet[open] { animation: none; }
  .sheet-actions { flex-direction: row-reverse; }
  .sheet-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .btn { transition: none; }
}
