:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #ebebed;
  --border-2: #e0e0e3;
  --text: #18181b;
  --muted: #8e8e93;
  --muted-2: #b4b4b9;
  --accent: #1a1a1a;
  --hi: #fff7e6;
  --pri-alta: #ef4444;
  --pri-alta-bg: #fef2f2;
  --pri-media: #f59e0b;
  --pri-media-bg: #fffbeb;
  --pri-baja: #10b981;
  --pri-baja-bg: #ecfdf5;
  --blue: #3b82f6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
input, textarea, select, button { font-family: inherit; }

/* ---------- Login ---------- */
#login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 200; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 44px 40px; width: 100%; max-width: 360px; text-align: center; }
.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-card p { color: var(--muted); font-size: 14px; margin: 6px 0 24px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 14px; }
.login-error { color: var(--pri-alta); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- Controles base ---------- */
input, textarea, select {
  font-size: 14px; color: var(--text); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
textarea { resize: vertical; }
button { font-weight: 600; font-size: 14px; cursor: pointer; border: none; border-radius: var(--radius-sm); padding: 10px 16px; background: var(--accent); color: #fff; transition: opacity .15s, transform .05s, background .15s; }
button:hover { opacity: .9; }
button:active { transform: translateY(1px); }
button.small { padding: 7px 12px; font-size: 13px; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border-2); }
button.ghost:hover { color: var(--text); background: #f0f0f2; opacity: 1; }
button.primary { background: var(--blue); }
button.danger { color: var(--pri-alta); border-color: #f3c4c4; }
button.danger:hover { background: var(--pri-alta-bg); }

/* ---------- Layout ---------- */
#app { display: none; max-width: 1280px; margin: 0 auto; padding: 22px 22px 80px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 22px; }
.top h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; outline: none; border-radius: 6px; padding: 2px 6px; }
.top h1:focus { background: var(--hi); }
.top-right { display: flex; align-items: center; gap: 10px; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }

.viewbar { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 22px; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; gap: 2px; box-shadow: var(--shadow); }
.seg button { background: transparent; color: var(--muted); border-radius: 999px; padding: 7px 15px; font-weight: 500; }
.seg button.active { background: var(--accent); color: #fff; }
.seg button:hover:not(.active) { color: var(--text); opacity: 1; }
.viewbar-actions { display: flex; align-items: center; gap: 10px; }
.groupby { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 4px 4px 10px; box-shadow: var(--shadow); }
.groupby-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.groupby button { background: transparent; color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 500; }
.groupby button.active { background: var(--accent); color: #fff; }
.groupby button:hover:not(.active) { color: var(--text); opacity: 1; }
/* Punto de color en cabeceras de columna */
.kb-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; background: var(--muted-2); }
.kb-status-sin-empezar { background: #94a3b8; }
.kb-status-en-progreso { background: var(--blue); }
.kb-status-en-pausa { background: var(--pri-media); }
.kb-status-acabado { background: var(--pri-baja); }
.kb-priority-alta { background: var(--pri-alta); }
.kb-priority-media { background: var(--pri-media); }
.kb-priority-baja { background: var(--pri-baja); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-head h2 { font-size: 18px; font-weight: 700; }

.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; align-items: start; }
.kb-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 120px; min-width: 0; transition: background .15s; }
.kb-col.drop-target { background: #eef4ff; outline: 2px dashed var(--blue); outline-offset: -3px; }
.kb-col h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 4px 12px; display: flex; justify-content: space-between; align-items: center; }
.kb-col h3 .count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); }

.task { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--muted-2); border-radius: var(--radius-sm); padding: 11px 12px; margin-bottom: 9px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.03); transition: box-shadow .15s, transform .08s, border-color .15s; position: relative; }
.task:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.task.dragging { opacity: .4; }
.task.pri-alta { border-left-color: var(--pri-alta); }
.task.pri-media { border-left-color: var(--pri-media); }
.task.pri-baja { border-left-color: var(--pri-baja); }
.task .t-top { display: flex; gap: 8px; align-items: flex-start; }
.task .t-icon { font-size: 16px; line-height: 1.4; flex-shrink: 0; }
.task .t-title { font-size: 14px; font-weight: 500; flex: 1; word-break: break-word; }
.task .t-meta { display: flex; gap: 7px; align-items: center; margin-top: 9px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.chip.pri-alta { background: var(--pri-alta-bg); color: var(--pri-alta); }
.chip.pri-media { background: var(--pri-media-bg); color: #b45309; }
.chip.pri-baja { background: var(--pri-baja-bg); color: #047857; }
.chip.date { background: #eff6ff; color: #1d4ed8; }
.chip.subs { background: #f4f4f5; color: var(--muted); }
.chip.owner { background: #faf5ff; color: #7c3aed; }
.task .progbar { height: 4px; background: #eee; border-radius: 999px; margin-top: 9px; overflow: hidden; }
.task .progbar > span { display: block; height: 100%; background: var(--pri-baja); border-radius: 999px; transition: width .3s; }
.add-task-line { color: var(--muted); font-size: 13px; cursor: pointer; padding: 8px 6px; border-radius: 8px; display: block; text-align: center; border: 1px dashed var(--border-2); margin-top: 4px; }
.add-task-line:hover { color: var(--text); background: var(--surface); }

/* ---------- Semanas ---------- */
.weeks { display: flex; flex-direction: column; gap: 14px; }
.week { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.week h3 { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.week .wk-range { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.week .wk-tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: 9px; }
.week.empty .wk-tasks::after { content: "Sin tareas esta semana"; color: var(--muted-2); font-size: 13px; }
.week .nodate-note { font-size: 12px; color: var(--muted); }

/* ---------- Calendario ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-head h2 { font-size: 17px; font-weight: 700; flex: 1; min-width: 120px; text-transform: capitalize; }
.cal-grid-head { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 0; margin-bottom: 4px; }
.cal-grid-head span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: center; padding: 4px 0; overflow: hidden; }
/* Calendario tipo Notion: cada semana = celdas de día + capa de barras continuas encima */
.cal-grid { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.cal-week { position: relative; }
.cal-days { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); }
.cal-cell { background: var(--surface); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-height: 104px; min-width: 0; padding: 4px 6px; }
.cal-days > .cal-cell:last-child { border-right: none; }
.cal-cell.out { background: var(--surface-2); }
.cal-cell.out .daynum { opacity: .4; }
.cal-cell.today { background: #eff6ff; }
.cal-cell .daynum { font-size: 12px; font-weight: 600; color: var(--muted); display: block; text-align: right; }
.cal-cell.today .daynum { color: var(--blue); font-weight: 700; }
/* Capa de barras superpuesta sobre las celdas */
.cal-bars { position: absolute; top: 24px; left: 0; right: 0; display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 2px 0; padding: 0 3px; pointer-events: none; }
.cal-bar { pointer-events: auto; height: 18px; line-height: 18px; color: #fff; font-size: 11px; font-weight: 500; cursor: pointer; overflow: hidden; margin: 0 1px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.cal-bar .cb-label { display: block; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-bar:hover { filter: brightness(1.08); }
.cal-more { pointer-events: auto; font-size: 10px; color: var(--muted); font-weight: 600; padding-left: 6px; align-self: center; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--blue); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; }
.kpi .del { position: absolute; top: 12px; right: 14px; cursor: pointer; color: var(--muted-2); font-size: 16px; opacity: 0; transition: opacity .15s; }
.kpi:hover .del { opacity: 1; }
.kpi-name { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; outline: none; margin-bottom: 10px; }
.kpi-name:focus { background: var(--hi); border-radius: 4px; }
.kpi-big { display: flex; align-items: baseline; gap: 4px; }
.kpi-actual { font-size: 30px; font-weight: 800; letter-spacing: -.02em; outline: none; min-width: 20px; }
.kpi-actual:focus { background: var(--hi); border-radius: 4px; }
.kpi-unit { font-size: 18px; font-weight: 700; color: var(--muted); }
.kpi-sub { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.kpi-sub [contenteditable]:focus { background: var(--hi); border-radius: 4px; outline: none; }
.kpi-bar { height: 8px; background: #eef0f2; border-radius: 999px; overflow: hidden; }
.kpi-bar > span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.kpi-pct { font-size: 12px; font-weight: 600; color: var(--muted); text-align: right; margin-top: 5px; }
.kpi-unit-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.kpi-unit-row label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-unit-sel { width: auto; padding: 4px 8px; font-size: 12px; flex: 1; }
.kpi-note { font-size: 13px; color: var(--text); margin-top: 12px; outline: none; white-space: pre-wrap; min-height: 20px; border-top: 1px solid var(--border); padding-top: 10px; }
.kpi-note:empty::before { content: attr(data-ph); color: var(--muted-2); }
.kpi-note:focus { background: var(--hi); border-radius: 4px; }

/* ---------- Ideas (con saltos de línea) ---------- */
.ideas { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); }
.idea-row { display: flex; gap: 10px; padding: 11px 14px; border-radius: 10px; position: relative; align-items: flex-start; }
.idea-row:hover { background: var(--surface-2); }
.idea-row .dot { color: var(--muted-2); margin-top: 2px; }
.idea-row .txt { flex: 1; font-size: 15px; outline: none; white-space: pre-wrap; word-break: break-word; }
.idea-row .txt:focus { background: var(--hi); border-radius: 4px; }
.idea-row .del { position: absolute; top: 11px; right: 14px; cursor: pointer; color: var(--muted-2); font-size: 16px; opacity: 0; transition: opacity .15s; }
.idea-row:hover .del { opacity: 1; }

/* ---------- Panel de detalle ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.28); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 90; }
.overlay.show { opacity: 1; pointer-events: auto; }
.detail { position: fixed; top: 0; right: 0; height: 100%; width: 420px; max-width: 92vw; background: var(--surface); box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1); z-index: 100; display: flex; flex-direction: column; }
.detail.show { transform: none; }
.detail-head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.icon-pick { background: var(--surface-2); border: 1px solid var(--border); font-size: 20px; width: 42px; height: 42px; border-radius: var(--radius-sm); flex-shrink: 0; padding: 0; }
.icon-pick:hover { background: #f0f0f2; }
.detail-title { flex: 1; font-size: 17px; font-weight: 700; outline: none; padding: 8px; border-radius: 8px; }
.detail-title:focus { background: var(--hi); }
.detail-body { padding: 18px; overflow-y: auto; flex: 1; }
.field-row { margin-bottom: 18px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row > label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: block; margin-bottom: 7px; }
.color-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pills button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer; transition: transform .1s; }
.color-pills button:hover { transform: scale(1.12); opacity: 1; }
.color-pills button.on { border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }
.pri-pills { display: flex; gap: 6px; }
.pri-pills button { flex: 1; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-2); font-size: 13px; padding: 8px; }
.pri-pills button.on[data-p=alta] { background: var(--pri-alta-bg); color: var(--pri-alta); border-color: var(--pri-alta); }
.pri-pills button.on[data-p=media] { background: var(--pri-media-bg); color: #b45309; border-color: var(--pri-media); }
.pri-pills button.on[data-p=baja] { background: var(--pri-baja-bg); color: #047857; border-color: var(--pri-baja); }
.subtasks { display: flex; flex-direction: column; gap: 6px; }
.subtask { display: flex; align-items: center; gap: 9px; padding: 7px 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.subtask input[type=checkbox] { width: 17px; height: 17px; flex-shrink: 0; cursor: pointer; accent-color: var(--pri-baja); }
.subtask .st-text { flex: 1; font-size: 14px; outline: none; }
.subtask .st-text.done { text-decoration: line-through; color: var(--muted-2); }
.subtask .st-del { color: var(--muted-2); cursor: pointer; opacity: 0; }
.subtask:hover .st-del { opacity: 1; }
.add-sub { color: var(--blue); font-size: 13px; cursor: pointer; padding: 7px 2px; font-weight: 500; }
.add-sub:hover { text-decoration: underline; }
.prog { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.comments { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.comment { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 14px; position: relative; }
.comment .c-time { font-size: 11px; color: var(--muted-2); margin-top: 3px; }
.comment .c-del { position: absolute; top: 6px; right: 8px; color: var(--muted-2); cursor: pointer; opacity: 0; font-size: 14px; }
.comment:hover .c-del { opacity: 1; }
#dDelete { width: 100%; margin-top: 6px; }

/* ---------- Selector de iconos ---------- */
.icon-panel { position: fixed; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 10px; display: none; grid-template-columns: repeat(8, 1fr); gap: 4px; z-index: 150; max-width: 320px; }
.icon-panel.show { display: grid; }
.icon-panel button { background: transparent; font-size: 20px; padding: 6px; border-radius: 8px; }
.icon-panel button:hover { background: #f0f0f2; }

/* ---------- Flash ---------- */
.saved-flash { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px); background: var(--accent); color: #fff; padding: 9px 18px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; z-index: 160; }
.saved-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
/* Tablet */
@media (max-width: 900px) {
  #app { padding: 18px 16px 70px; }
  .kanban { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .cal-cell { min-height: 78px; }
  .cal-bar { font-size: 10px; padding: 2px 4px; }
}
/* Móvil */
@media (max-width: 600px) {
  #app { padding: 14px 12px 70px; }
  .top h1 { font-size: 19px; }
  .viewbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .seg { width: 100%; overflow-x: auto; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
  .seg button { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
  .viewbar-actions { display: flex; }
  .viewbar-actions button { flex: 1; }
  .kanban { grid-template-columns: 1fr; }
  .objetivos { grid-template-columns: 1fr; }
  .week .wk-tasks { grid-template-columns: 1fr; }
  /* Calendario: celdas más compactas, día arriba, barras en puntos para no romper */
  .cal-grid-head span { font-size: 10px; }
  .cal-cell { min-height: 58px; padding: 4px; border-radius: 8px; }
  .cal-cell .daynum { font-size: 11px; }
  .cal-bar { font-size: 0; padding: 0; height: 7px; border-radius: 999px; margin-top: 1px; }
  /* Panel de detalle ocupa toda la pantalla */
  .detail { width: 100%; max-width: 100%; }
  .field-row.two { grid-template-columns: 1fr; }
}
/* Móvil pequeño */
@media (max-width: 380px) {
  .seg button { padding: 7px 9px; font-size: 12px; }
  .cal-cell { min-height: 48px; }
}
