:root {
  --white: #ffffff;
  --beige: #f5f0e6;
  --sand: #d8cdb5;
  --olive: #6b7040;
  --navy: #1f2a44;
  --ink: #111111;
  --muted: #6f6a5c;
  --hour: 48px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--beige); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.app { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }

.top { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; }
.sub { margin: 0; color: var(--olive); font-size: 14px; text-transform: capitalize; }
h1 { margin: 2px 0 0; font-size: 34px; font-weight: 600; letter-spacing: -0.02em; text-transform: capitalize; }
.add { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--navy); color: var(--white); font-size: 26px; line-height: 1; }

.bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs, .nav { display: flex; background: var(--white); border: 1px solid var(--sand); border-radius: 10px; overflow: hidden; }
.tabs button, .nav button { border: 0; background: none; padding: 8px 14px; }
.tabs button.on { background: var(--navy); color: var(--white); }
.nav button + button { border-left: 1px solid var(--sand); }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--sand); background: var(--white); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.off { opacity: .4; }
.chip.off i { background: transparent; border: 1px solid var(--c); }

#view { background: var(--white); border: 1px solid var(--sand); border-radius: 14px; overflow: hidden; }
.note { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* Cuadrícula horaria (día y semana) */
.tg-head, .tg-body { display: grid; grid-template-columns: 44px repeat(var(--cols), 1fr); }
.tg-head { border-bottom: 1px solid var(--sand); }
.tg-head div { padding: 8px 4px; text-align: center; font-size: 13px; color: var(--muted); }
.tg-head div.today { color: var(--navy); font-weight: 600; }
.tg-head div b { display: block; font-size: 18px; color: var(--ink); font-weight: 600; }
.tg-allday { display: grid; grid-template-columns: 44px repeat(var(--cols), 1fr); border-bottom: 1px solid var(--sand); }
.tg-allday div { padding: 4px; min-height: 8px; }
.tg-body { position: relative; max-height: 70vh; overflow-y: auto; }
.tg-hours div { height: var(--hour); font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.tg-col { position: relative; border-left: 1px solid var(--beige); height: calc(var(--hour) * var(--n)); background-image: linear-gradient(var(--beige) 1px, transparent 1px); background-size: 100% var(--hour); cursor: pointer; }
.tg-col.today { background-color: #faf7f0; }
.ev { position: absolute; left: 2px; right: 2px; overflow: hidden; border-radius: 6px; padding: 2px 6px; font-size: 12px; color: var(--white); background: var(--c); border: 0; text-align: left; }
.ev small { display: block; opacity: .8; }
.ev.chipev { position: static; display: block; width: 100%; margin-bottom: 2px; }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--olive); pointer-events: none; }

/* Mes */
.m-head, .m-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.m-head div { padding: 8px; font-size: 12px; color: var(--muted); text-align: center; border-bottom: 1px solid var(--sand); }
.m-cell { min-height: 92px; border-right: 1px solid var(--beige); border-bottom: 1px solid var(--beige); padding: 4px; cursor: pointer; background: none; text-align: left; border-top: 0; border-left: 0; }
.m-cell.out { background: #fbf9f4; color: #aaa; }
.m-cell .n { font-size: 13px; display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 50%; }
.m-cell.today .n { background: var(--navy); color: var(--white); }
.m-ev { display: block; font-size: 11px; padding: 1px 4px; margin-top: 2px; border-radius: 4px; color: var(--white); background: var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-more { font-size: 11px; color: var(--muted); }

/* Año */
.y-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; padding: 16px; }
.y-month h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; text-transform: capitalize; cursor: pointer; }
.y-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: 11px; text-align: center; }
.y-days span { padding: 3px 0; border-radius: 4px; cursor: pointer; position: relative; }
.y-days .h { color: var(--muted); cursor: default; }
.y-days .t { background: var(--navy); color: var(--white); }
.y-days .has::after { content: ""; position: absolute; left: 50%; bottom: 0; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--c, var(--olive)); }

/* Diálogo */
dialog { border: 1px solid var(--sand); border-radius: 16px; padding: 20px; width: min(420px, 92vw); background: var(--white); }
dialog::backdrop { background: rgba(17, 17, 17, .35); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog label:not(.sub-pill) { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
dialog input:not([type="checkbox"]), dialog select, dialog textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--sand); border-radius: 8px; background: var(--white); font-size: 16px; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.grow { flex: 1; }
.primary { background: var(--navy); color: var(--white); border: 0; border-radius: 8px; padding: 9px 16px; }
.ghost { background: none; border: 1px solid var(--sand); border-radius: 8px; padding: 9px 14px; }

@media (max-width: 600px) {
  h1 { font-size: 26px; }
  .m-cell { min-height: 64px; }
  .m-ev { font-size: 0; height: 6px; padding: 0; }
  .app { padding: 16px 10px 40px; }
}

/* Pie, estado y acceso */
.foot { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 12px; color: var(--muted); }
.link { background: none; border: 0; color: var(--navy); text-decoration: underline; padding: 0; font-size: 12px; }
.auth { position: fixed; inset: 0; background: var(--beige); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.auth[hidden] { display: none; }
.authbox { background: var(--white); border: 1px solid var(--sand); border-radius: 16px; padding: 24px; width: min(380px, 100%); }
.authbox h1 { margin: 0 0 4px; }
.authbox .sub { margin-bottom: 16px; color: var(--muted); text-transform: none; }
.authbox label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.authbox input { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--sand); border-radius: 8px; font-size: 16px; background: var(--white); }
.msg { min-height: 18px; margin: 0 0 8px; font-size: 13px; color: var(--navy); }

/* Estilos para feed Apple Calendar */
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.hint.small { font-size: 11px; margin-top: 14px; line-height: 1.4; }
ol.hint { padding-left: 20px; margin: 8px 0 14px; }
ol.hint li { margin-bottom: 4px; }
#feedUrl { font-size: 12px; color: var(--navy); background: var(--beige); border: 1px solid var(--sand); padding: 8px 10px; border-radius: 8px; width: 100%; margin-bottom: 12px; }

/* Importador PDF */
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { font-size: 13px; font-weight: 500; padding: 8px 12px; }
.wide-dialog { width: min(640px, 94vw); max-height: 85vh; overflow-y: auto; }
.upload-zone { border: 2px dashed var(--sand); border-radius: 12px; padding: 24px 16px; text-align: center; background: #faf7f0; cursor: pointer; transition: background .15s; }
.upload-zone.dragover { background: #ede7d8; border-color: var(--olive); }
.upload-icon { font-size: 36px; display: block; margin-bottom: 8px; }
.upload-prompt p { margin: 4px 0; font-size: 14px; }
.link-btn { background: none; border: 0; color: var(--navy); text-decoration: underline; font-weight: 600; cursor: pointer; padding: 0; }
.muted-text { font-size: 12px; color: var(--muted); }
.parse-progress { padding: 12px; font-size: 14px; color: var(--olive); font-weight: 500; }
.preview-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.preview-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.preview-list { max-height: 240px; overflow-y: auto; border: 1px solid var(--sand); border-radius: 8px; background: var(--white); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.preview-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-radius: 6px; background: #faf8f5; border-left: 4px solid var(--c); font-size: 13px; }
.preview-item .p-title { font-weight: 500; }
.preview-item .p-meta { color: var(--muted); font-size: 11px; }
.preview-item .p-del { background: none; border: 0; color: #a33; cursor: pointer; font-size: 15px; padding: 0 4px; }

/* Asistente paso a paso de importación UCLM */
.import-step { display: flex; flex-direction: column; gap: 14px; }
.sub-tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.sub-pill {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 6px 14px !important;
  border-radius: 20px !important;
  border: 1px solid var(--sand) !important;
  background: var(--white) !important;
  font-size: 13px !important;
  cursor: pointer !important;
  user-select: none !important;
  margin: 0 !important;
  width: auto !important;
}
.sub-pill input[type="checkbox"] {
  display: inline-block !important;
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 4px !important;
  cursor: pointer !important;
}
.sub-pill span {
  display: inline !important;
  line-height: 1.3 !important;
  color: var(--ink) !important;
}
.sub-pill.checked { background: #e8ede0 !important; border-color: var(--olive) !important; color: var(--ink) !important; font-weight: 500 !important; }
.btn-toggle-group { display: flex; gap: 8px; margin: 6px 0; }
.btn-toggle-group button { border: 1px solid var(--sand); background: var(--white); border-radius: 8px; padding: 6px 12px; font-size: 12px; }
.btn-toggle-group button.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.config-box { background: #faf7f0; border: 1px solid var(--sand); border-radius: 10px; padding: 12px; font-size: 13px; }
.config-box h4 { margin: 0 0 8px; font-size: 13px; color: var(--navy); }
