/* Layout: barra superior fija + área de trabajo a pantalla completa (listas con scroll horizontal propio). */
:root {
  --bg: #e9efed;
  --surface: #ffffff;
  --list: #dbe3e0;
  --raised: #f4f7f6;
  --fg: #16201d;
  --muted: #56655f;
  --line: #c6d1cd;
  --accent: #0d6b5f;
  --accent-fg: #ffffff;
  --accent-soft: #d3ebe6;
  --danger: #b3261e;
  --danger-bg: #fbe3e1;
  --warn: #8a5a00;
  --warn-bg: #fbefcf;
  --ok: #1d6f39;
  --ok-bg: #d9f0df;
  --ph: #c3cfcb;
  --scrim: rgba(12, 20, 18, .48);
  --shadow: rgba(16, 32, 28, .14);
  --shadow-strong: rgba(16, 32, 28, .28);
  --label-fg: #17211e;
  --lb-verde: #7fd08f;
  --lb-amarillo: #f0cf63;
  --lb-naranja: #f4a560;
  --lb-rojo: #ef7f7c;
  --lb-morado: #b8a1de;
  --lb-azul: #7eaaf0;
  --lb-celeste: #6fcfd6;
  --lb-rosa: #f19cc3;
  --lb-lima: #b8d96e;
  --lb-gris: #b4bdba;

  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1513; --surface: #1c2422; --list: #151c1a; --raised: #232d2a;
    --fg: #e1e9e6; --muted: #92a29c; --line: #2c3834; --accent: #43b7a3; --accent-fg: #06211c;
    --accent-soft: #173a34; --danger: #ff8f86; --danger-bg: #3d1c1a; --warn: #f0c35a; --warn-bg: #3a2e12;
    --ok: #74d394; --ok-bg: #173323; --ph: #2b3633; --scrim: rgba(0, 0, 0, .6);
    --shadow: rgba(0, 0, 0, .35); --shadow-strong: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1513; --surface: #1c2422; --list: #151c1a; --raised: #232d2a;
  --fg: #e1e9e6; --muted: #92a29c; --line: #2c3834; --accent: #43b7a3; --accent-fg: #06211c;
  --accent-soft: #173a34; --danger: #ff8f86; --danger-bg: #3d1c1a; --warn: #f0c35a; --warn-bg: #3a2e12;
  --ok: #74d394; --ok-bg: #173323; --ph: #2b3633; --scrim: rgba(0, 0, 0, .6);
  --shadow: rgba(0, 0, 0, .35); --shadow-strong: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--bg); }
body {
  height: 100%; margin: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; text-wrap: balance; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Barra superior ---------- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding-block: 10px 8px; }
.brand { font: 600 13px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.brand svg { color: var(--accent); }
.board-pick { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 200px; }
.board-pick select {
  min-width: 0; max-width: 100%; flex: 0 1 auto; font-size: 17px; font-weight: 600; padding: 6px 30px 6px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}
.tabs { display: inline-flex; background: var(--list); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; color: var(--muted); font-weight: 500; }
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px var(--shadow); }
.search { display: flex; align-items: center; gap: 6px; flex: 1 1 220px; min-width: 0; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; }
.search input { border: 0; background: transparent; padding: 7px 0; min-width: 0; flex: 1; outline: none; }
.search svg { color: var(--muted); flex: none; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.icon-btn:hover { border-color: var(--muted); }
.icon-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.badge-n { font: 600 11px/1 var(--font-mono); background: var(--accent); color: var(--accent-fg); border-radius: 99px; padding: 3px 6px; }
.sync { font: 12px/1 var(--font-mono); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.sync[data-s="saving"] i { background: var(--warn); }
.sync[data-s="offline"] i, .sync[data-s="auth"] i { background: var(--danger); }
.spacer { flex: 1 1 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 10px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.filters .grp { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filters .lbl { font: 600 11px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chip { border: 1px solid var(--line); background: var(--raised); border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.lb { color: var(--label-fg); border-color: transparent; }
.chip.lb[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 1px; color: var(--label-fg); }

.banner { padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--danger-bg); color: var(--danger); }
.banner button { border: 1px solid currentColor; background: transparent; border-radius: 6px; padding: 3px 10px; color: inherit; }

/* ---------- Área principal ---------- */
main { flex: 1 1 auto; min-height: 0; position: relative; }
main.scroll { overflow-y: auto; padding-bottom: 24px; }
.lists { display: flex; gap: 12px; align-items: flex-start; height: 100%; overflow-x: auto; overflow-y: hidden; padding-bottom: 14px; scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
.list { flex: 0 0 min(84vw, 286px); max-height: 100%; display: flex; flex-direction: column; background: var(--list); border-radius: var(--r); scroll-snap-align: start; }
.list-h { display: flex; align-items: center; gap: 6px; padding: 9px 8px 6px 12px; cursor: grab; touch-action: pan-x pan-y; user-select: none; -webkit-user-select: none; }
.list-h h2 { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: text; }
.list-h input { flex: 1; min-width: 0; font-weight: 600; padding: 4px 6px; border: 1px solid var(--accent); border-radius: 6px; background: var(--surface); }
.list-h .n { font: 12px/1 var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.list-h .icon-btn { height: 28px; min-width: 28px; border: 0; background: transparent; }
.list-h .icon-btn:hover { background: var(--ph); }
.list-cards { overflow-y: auto; padding: 2px 8px; display: flex; flex-direction: column; gap: 8px; min-height: 6px; }
.list-foot { padding: 6px 8px 8px; }
.add-btn { width: 100%; text-align: left; border: 0; background: transparent; color: var(--muted); padding: 7px 8px; border-radius: 7px; }
.add-btn:hover { background: var(--ph); color: var(--fg); }
.composer textarea, .composer input { width: 100%; resize: none; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--accent); background: var(--surface); box-shadow: 0 1px 0 var(--shadow); }
.composer .row { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 6px 12px; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.new-list { flex: 0 0 min(84vw, 286px); }
.new-list .add-btn { background: var(--list); color: var(--fg); padding: 10px 12px; border-radius: var(--r); opacity: .85; }
.new-list .composer { background: var(--list); padding: 8px; border-radius: var(--r); }

.card {
  background: var(--surface); border-radius: 8px; padding: 8px 10px 8px; box-shadow: 0 1px 0 var(--shadow), 0 0 0 1px var(--line);
  cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
.card:hover { box-shadow: 0 1px 0 var(--shadow), 0 0 0 1px var(--muted); }
.card .t { overflow-wrap: anywhere; }
.c-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.lbl-pill { font-size: 11px; font-weight: 600; color: var(--label-fg); padding: 1px 7px; border-radius: 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 8px; }
.lbl-pill:empty { width: 36px; }
.c-badges { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; font: 12px/1 var(--font-mono); color: var(--muted); align-items: center; }
.c-badges:empty { display: none; }
.bdg { display: inline-flex; align-items: center; gap: 4px; padding: 3px 5px; border-radius: 4px; }
.bdg.over { background: var(--danger-bg); color: var(--danger); }
.bdg.today, .bdg.soon { background: var(--warn-bg); color: var(--warn); }
.bdg.done { background: var(--ok-bg); color: var(--ok); }
.bdg.full { background: var(--ok-bg); color: var(--ok); }
.c-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.drag-ghost { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; box-shadow: 0 14px 30px var(--shadow-strong) !important; opacity: .96; max-height: 70vh; overflow: hidden; }
.ph-card { border-radius: 8px; background: var(--ph); flex: none; }
.ph-list { border-radius: var(--r); background: var(--ph); flex: 0 0 min(84vw, 286px); align-self: stretch; }
body.dragging, body.dragging * { cursor: grabbing !important; }

.empty { max-width: 460px; margin: 8vh auto 0; text-align: center; display: grid; gap: 12px; justify-items: center; color: var(--muted); }
.empty h2 { color: var(--fg); font-size: 20px; }
.hidden-note { font-size: 12px; color: var(--muted); padding: 0 12px 4px; }

/* ---------- Calendario ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-head h2 { font-size: 18px; text-transform: capitalize; min-width: 150px; }
.cal-head label { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--list); font: 600 11px/1 var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 7px 6px; }
.cal .day { background: var(--surface); min-height: 104px; padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.out { background: var(--raised); }
.cal .day.out .d { opacity: .5; }
.cal .d { font: 12px/1 var(--font-mono); color: var(--muted); padding: 2px 3px; font-variant-numeric: tabular-nums; }
.cal .day.today .d { background: var(--accent); color: var(--accent-fg); border-radius: 99px; align-self: flex-start; padding: 3px 6px; }
.cal-chip { border: 0; text-align: left; font-size: 12px; line-height: 1.25; padding: 2px 5px; border-radius: 4px; background: var(--raised); border-left: 3px solid var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
.cal-chip.over { background: var(--danger-bg); }
.cal-chip.done { text-decoration: line-through; opacity: .7; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.agenda { margin-top: 18px; display: grid; gap: 4px; }
.agenda h3 { font: 600 11px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 10px 0 4px; }
.ag-row { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 7px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-align: left; width: 100%; }
.ag-row .when { font: 12px/1.2 var(--font-mono); color: var(--muted); }
.ag-row .what { overflow-wrap: anywhere; }

/* ---------- Archivo ---------- */
.arch { display: grid; gap: 6px; max-width: 860px; }
.arch h3 { font: 600 11px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 4px; display: flex; gap: 10px; align-items: center; }
.arch-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.arch-row .what { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.arch-row .what small { display: block; color: var(--muted); }
.arch-row .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Modal de tarjeta y diálogos ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: var(--scrim); display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: max(28px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 28px max(12px, env(safe-area-inset-left, 0px)); overscroll-behavior: contain; }
.sheet { background: var(--surface); border-radius: 12px; width: min(780px, 100%); padding: 18px 20px 20px; box-shadow: 0 20px 50px var(--shadow-strong); position: relative; }
.sheet.narrow { width: min(440px, 100%); }
.sheet .x { position: absolute; top: 10px; right: 10px; border: 0; background: transparent; width: 34px; height: 34px; border-radius: 8px; font-size: 20px; color: var(--muted); }
.sheet .x:hover { background: var(--raised); color: var(--fg); }
.m-title { width: calc(100% - 36px); font-size: 19px; font-weight: 600; border: 1px solid transparent; border-radius: 7px; padding: 4px 6px; margin-left: -6px; resize: none; background: transparent; overflow: hidden; }
.m-title:hover, .m-title:focus { border-color: var(--line); background: var(--raised); }
.m-sub { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }
.m-grid { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 22px; }
.m-sec { display: grid; gap: 8px; margin-bottom: 20px; }
.m-sec > h3, .side h3 { font: 600 11px/1 var(--font-mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.side { display: grid; gap: 18px; align-content: start; }
.side .grp { display: grid; gap: 6px; }
.field { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--raised); }
.field:focus { border-color: var(--accent); background: var(--surface); outline: none; }
textarea.field { resize: vertical; min-height: 90px; line-height: 1.5; }
.lb-pick { display: flex; flex-wrap: wrap; gap: 5px; }
.lb-pick button { border: 0; color: var(--label-fg); font-size: 12px; font-weight: 600; border-radius: 5px; padding: 4px 8px; min-width: 40px; opacity: .45; }
.lb-pick button[aria-pressed="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--fg); }
.progress { display: flex; align-items: center; gap: 8px; font: 12px/1 var(--font-mono); color: var(--muted); }
.progress .bar { flex: 1; height: 6px; background: var(--raised); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress .bar i { display: block; height: 100%; background: var(--accent); }
.progress .bar i.full { background: var(--ok); }
.ci { display: flex; gap: 8px; align-items: center; }
.ci input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.ci .ci-t { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 6px; }
.ci .ci-t:hover { background: var(--raised); }
.ci .ci-t:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.ci.done .ci-t { text-decoration: line-through; color: var(--muted); }
.mini-x { border: 0; background: transparent; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; flex: none; }
.mini-x:hover { background: var(--danger-bg); color: var(--danger); }
.add-row { display: flex; gap: 6px; flex-wrap: wrap; }
.add-row .field { flex: 1 1 160px; min-width: 0; }
.link-row { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.link-row .lt { flex: 1; min-width: 0; }
.link-row a { font-weight: 500; overflow-wrap: anywhere; }
.link-row small { display: block; color: var(--muted); font: 11px/1.3 var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmt { padding: 8px 10px; background: var(--raised); border-radius: 8px; }
.cmt .when { font: 11px/1 var(--font-mono); color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.cmt p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.due-row { display: flex; gap: 6px; flex-wrap: wrap; }
.due-row .field { flex: 1 1 110px; min-width: 0; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.confirm { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--danger); }
.menu-list { display: grid; gap: 4px; margin-top: 10px; }
.menu-list button { text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; }
.menu-list button:hover { background: var(--raised); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.lb-edit { display: grid; gap: 8px; }
.lb-edit .r { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lb-edit .r .field { flex: 1 1 120px; min-width: 0; }
.sw { width: 22px; height: 22px; border-radius: 5px; border: 0; padding: 0; }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--fg); }
.dlg-h { font-size: 17px; font-weight: 600; padding-right: 30px; }
.dlg-p { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
pre.json { max-height: 200px; overflow: auto; background: var(--raised); padding: 8px; border-radius: 8px; font: 11px/1.4 var(--font-mono); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 80; background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 9px; font-size: 13px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px var(--shadow-strong); }

@media (max-width: 680px) {
  .m-grid { grid-template-columns: minmax(0, 1fr); }
  .side { order: -1; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .overlay { padding: 0; }
  .sheet { border-radius: 0; min-height: 100%; padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
  .sheet .x { top: calc(8px + env(safe-area-inset-top, 0px)); }
  .cal .day { min-height: 62px; padding: 2px; }
  .cal-chip { font-size: 10px; padding: 1px 3px; border-left-width: 2px; }
  .brand span { display: none; }
  .search { max-width: none; order: 5; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

@media (max-width: 680px) {
  .board-pick { flex: 1 1 0; order: 0; }
  .sync, .top > [data-act="boardMenu"] { order: 1; }
  .sync > span { display: none; }
  .tabs, #filterBtn { order: 2; }
}
