/* c4p1app — estilos. Misma paleta cálida de App φ, con tema claro y oscuro. */
:root {
  --bg: #F4EFE7; --card: #FBF8F3; --field: #FFFFFF; --ink: #231F1A; --ink2: #4A433B; --muted: #5E564C;
  --line: #D9CFC1; --line2: #E3D9CB; --seg: #E9E1D5; --chip: #F1E6DA; --box: #A89C8C;
  --accent: #9C3F1F; --accent-ink: #FFFFFF; --danger: #C2362B; --ok: #2F7D5B;
  --shadow: rgba(80, 35, 15, .28); --scrim: rgba(35, 31, 26, .45);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191613; --card: #231F1B; --field: #2B2621; --ink: #F2ECE3; --ink2: #D6CDC1; --muted: #B0A596;
    --line: #40382F; --line2: #342D26; --seg: #0F0D0B; --chip: #33291F; --box: #7D7263;
    --accent: #D9774F; --accent-ink: #1A0F0A; --danger: #F08B82; --ok: #4FB386;
    --shadow: rgba(0, 0, 0, .5); --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
svg { display: block; }

h1 {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: -.01em;
}
h2 { margin: 0; font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 22px; }
.small { font-size: 13px; color: var(--muted); margin: 0; }
.err { color: var(--danger); font-size: 14px; margin: 0; min-height: 1.3em; }

label, .field > label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.field { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
input[type=text], input[type=url], input[type=password], input[type=search], textarea, select {
  font-weight: 400;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  font-size: 16px; /* 16px evita el zoom automático en iOS */
}
textarea { height: auto; padding: 12px 14px; resize: none; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.primary {
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
}
.primary:disabled { opacity: .6; cursor: default; }
.ghost {
  min-height: 48px;
  min-width: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.danger {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--danger);
  font-size: 15px;
  font-weight: 600;
}
.danger.armed { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.plain {
  width: 44px; height: 44px; flex-shrink: 0;
  border: 0; background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.plain svg, .ghost svg { width: 20px; height: 20px; }

/* Entrada */
.login {
  max-width: 420px;
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}
.login h1 { font-size: 44px; }
.login form { display: flex; flex-direction: column; gap: 14px; }

/* Aplicación */
.shell { max-width: 560px; margin: 0 auto; padding-top: env(safe-area-inset-top); }
.top { padding: 24px 16px 12px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top .small { margin-top: 6px; }

/* Estado de la sincronización */
.status {
  margin-top: 4px; min-height: 32px; padding: 0; border: 0; background: none;
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); text-align: left;
}
.sdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--ok); }
.sdot.wait { background: #C98A1B; }
.sdot.off { background: var(--box); }
.sdot.err { background: var(--danger); }

/* Búsqueda y filtros */
.searchbar { padding: 0 16px 10px; }
.searchbar input { width: 100%; }
.filters { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.fchip {
  height: 40px; padding: 0 14px; border-radius: 20px; flex-shrink: 0; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.fchip[aria-pressed=true] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.fchip .n { font-weight: 500; opacity: .7; }
.fchip.clear { border-style: dashed; color: var(--muted); }
.pickgrid { display: flex; flex-wrap: wrap; gap: 8px; }

/* Interruptor sin ver / visto (ojo cerrado / ojo abierto) */
.seg { margin: 0 16px 12px; padding: 4px; background: var(--seg); border-radius: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.seg button {
  height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; font-weight: 600;
}
.seg button svg { width: 22px; height: 22px; }
.seg button[aria-pressed=true] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

main { padding: 0 16px calc(120px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.empty { padding: 48px 12px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.5; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--line2); border-radius: 16px; padding: 12px 12px 12px 6px; display: flex; gap: 4px; align-items: flex-start; }
.check { width: 44px; height: 44px; flex-shrink: 0; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; }
.box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--box); background: var(--field); display: flex; align-items: center; justify-content: center; }
.box svg { width: 16px; height: 16px; opacity: 0; }
.done .box { background: var(--ok); border-color: var(--ok); }
.done .box svg { opacity: 1; }
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
.title { font-size: 17px; font-weight: 600; line-height: 1.3; border: 0; background: none; padding: 0; text-align: left; overflow-wrap: anywhere; }
.done .title { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.cat { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--box); flex-shrink: 0; }
.link { display: inline-flex; align-items: center; gap: 5px; min-height: 28px; max-width: 100%; text-decoration: none; font-weight: 500; }
.link svg { width: 14px; height: 14px; flex-shrink: 0; }
.link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { font-size: 14px; line-height: 1.4; color: var(--ink2); white-space: pre-wrap; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 2px 10px; border-radius: 999px; background: var(--chip); font-size: 12px; font-weight: 500; color: var(--ink2); }

/* Botón flotante */
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(24px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 22px 0 18px; border: 0; border-radius: 28px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 18px var(--shadow);
}
.fab svg { width: 20px; height: 20px; }

/* Ajustes */
.settings-body { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.block {
  margin: 0 16px 16px; padding: 14px; background: var(--card); border: 1px solid var(--line2);
  border-radius: 16px; display: flex; flex-direction: column; gap: 12px;
}
.block h2 { font-size: 18px; }
.rows { display: flex; flex-direction: column; gap: 10px; }
.rowitem { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rowitem input[type=text] { flex: 1 1 130px; min-width: 0; height: 44px; }
.swatch { width: 44px; height: 44px; padding: 3px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.count { min-width: 24px; text-align: right; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 6px; margin-left: auto; }
.iconbtn {
  width: 44px; height: 44px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink2); display: flex; align-items: center; justify-content: center;
}
.iconbtn:disabled { opacity: .4; cursor: default; }
.iconbtn svg { width: 18px; height: 18px; }
.confirm { padding: 12px; border: 1px dashed var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }
.confirm p { margin: 0; font-size: 14px; }
.confirm .row button { flex: 1; }
.addrow { display: flex; gap: 8px; align-items: center; }
.addrow input[type=text] { flex: 1; min-width: 0; height: 44px; }
.msg { margin: 0; font-size: 14px; color: var(--ink2); white-space: pre-wrap; overflow-wrap: anywhere; }
.block button:disabled, .block input:disabled { opacity: .5; }

/* Formulario */
.scrim { position: fixed; inset: 0; background: var(--scrim); display: flex; flex-direction: column; justify-content: flex-end; z-index: 10; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; max-height: 92vh; overflow-y: auto;
}
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); align-self: center; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }

.tagbox { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 48px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.tagbox:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.tagchips { display: contents; }
.tagbox input { flex: 1; min-width: 120px; height: 36px; border: 0; padding: 0 4px; background: transparent; outline: none; }
.tagbox input:focus { outline: none; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px 0 10px; height: 32px; border-radius: 999px; background: var(--chip); font-size: 13px; font-weight: 500; }
.chip button { width: 28px; height: 28px; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 20; box-shadow: 0 6px 18px var(--shadow);
}
