@property --progress {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

:root {
  color-scheme: light;
  --ink: #102f3d;
  --ink-soft: #4f6872;
  --paper: #f3f6f4;
  --card: #ffffff;
  --line: #dbe4e1;
  --line-strong: #c7d5d1;
  --teal: #087b74;
  --teal-soft: #dff2ef;
  --coral: #ed6a5a;
  --coral-soft: #fff0ed;
  --amber: #b86608;
  --amber-soft: #fff5de;
  --shadow: 0 16px 40px rgba(16, 47, 61, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% -10%, rgba(8, 123, 116, .13), transparent 28rem),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.boot-view, .auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.boot-view { align-content: center; gap: 14px; color: var(--ink-soft); }
.boot-view p { margin: 0; font-size: .88rem; }
.auth-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; min-width: 0; align-items: center; gap: 16px; }
.auth-brand > * { min-width: 0; }
.auth-brand h1 { margin: 0; font-size: 1.65rem; letter-spacing: -.035em; }
.auth-copy { margin: 22px 0; color: var(--ink-soft); font-size: .9rem; }
.auth-form { display: grid; gap: 15px; }
.auth-form label, .password-form label { display: grid; gap: 6px; color: var(--ink-soft); font-size: .79rem; font-weight: 750; }
.auth-form .button { margin-top: 4px; }
.form-message { min-height: 22px; margin: 0; color: var(--teal); font-size: .8rem; }
.error-message { color: #a83225; }
body.busy { cursor: progress; }
body.busy button, body.busy input, body.busy select, body.busy textarea { cursor: progress; }

button, input, select, textarea { min-width: 0; max-width: 100%; font: inherit; }
button, select, input[type="checkbox"] { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(8, 123, 116, .22);
  outline-offset: 2px;
}

.app-shell { width: 100%; height: 100dvh; margin: 0 auto; padding: 0 18px 14px; display: flex; flex-direction: column; overflow: hidden; }
.app-shell > main { display: flex; flex: 1; min-height: 0; flex-direction: column; }

.topbar {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}
.topbar .brand-mark { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 11px; box-shadow: 4px 4px 0 var(--coral); }

.brand { display: flex; min-width: 0; flex: 1 1 auto; align-items: center; gap: 12px; overflow: visible; }
.brand > div:last-child { min-width: 0; overflow: hidden; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  box-shadow: 5px 5px 0 var(--coral);
}
.brand h1 { margin: 0; font-size: 1.04rem; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand p { margin: 1px 0 0; color: var(--ink-soft); font-size: .84rem; }
.top-actions, .week-nav, .filters, .dialog-actions, .data-actions { display: flex; min-width: 0; align-items: center; gap: 10px; }
.top-actions { max-width: 70%; flex: 0 0 auto; }
.profile-button { display: inline-flex; max-width: min(240px, 40vw); align-items: center; gap: 8px; }
#profileButtonName { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#newTaskButton { display: inline-flex; align-items: center; gap: 5px; }
.profile-avatar {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: .72rem;
  font-weight: 850;
}

.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 11px;
  min-height: 38px;
  padding: 7px 13px;
  background: transparent;
  color: var(--ink);
  font-weight: 720;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button-primary { background: var(--ink); color: white; box-shadow: 0 6px 16px rgba(16, 47, 61, .17); }
.button-primary:hover { background: #174454; }
.button-ghost { background: var(--card); border-color: var(--line-strong); }
.button-quiet { background: transparent; border-color: var(--line); }
.button-danger { color: #a83225; background: var(--coral-soft); border-color: #f4c4be; }
.icon-button { width: 38px; padding: 0; border-color: var(--line); background: var(--card); font-size: 1.15rem; }

.week-toolbar { position: relative; display: flex; flex: 0 0 auto; justify-content: space-between; align-items: flex-end; gap: 20px; padding: 10px 0 8px; }
.week-nav, .filters { align-items: flex-end; }
.week-nav > .icon-button, .week-nav > .button, .filters > .button { flex: 0 0 auto; }
.week-nav > div { display: grid; min-width: 0; align-content: end; }
.week-nav h2 { margin: 0; min-width: 250px; font-size: clamp(1.2rem, 1.7vw, 1.55rem); letter-spacing: -.035em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { margin: 0 0 2px; color: var(--teal); font-size: .73rem; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }
.filters label { display: grid; gap: 4px; color: var(--ink-soft); font-size: .72rem; font-weight: 750; }
select, input, textarea {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  padding: 9px 11px;
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='m2 2 5 5 5-5' fill='none' stroke='%234f6872' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 14px 9px;
}
select::-ms-expand { display: none; }
.filters label { min-width: 0; }
.filters select { min-width: 160px; }
.mobile-filters-button { display: none; }
textarea { resize: vertical; cursor: text; }

.stat-label { margin: 0 0 4px; color: var(--ink-soft); font-size: .74rem; font-weight: 720; }
.stat-value { margin: 0; font-size: 1.55rem; line-height: 1; font-weight: 820; letter-spacing: -.04em; }
.stat-value small { font-size: .82rem; letter-spacing: 0; }
.ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  background: conic-gradient(var(--coral) var(--progress), rgba(255,255,255,.15) 0);
  transition: --progress .65s cubic-bezier(.22, 1, .36, 1);
}
.ring.ring-reset { transition: none; }
.ring::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--ink); }
.ring span { position: relative; z-index: 1; font-size: .65rem; font-weight: 850; }

.content-toolbar { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 14px; margin: 5px 0 7px; }
.view-tabs { display: flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.72); }
.view-tab { min-width: 0; min-height: 34px; padding: 6px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-soft); font-size: .78rem; font-weight: 780; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-tab.active { background: var(--ink); color: white; box-shadow: 0 4px 12px rgba(16,47,61,.14); }
.tab-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 4px; padding: 0 5px; border-radius: 999px; background: rgba(8,123,116,.12); color: var(--teal); font-size: .67rem; }
.view-tab.active .tab-count { background: rgba(255,255,255,.16); color: white; }
.load-drawer-button::after {
  content: "";
  display: inline-block;
  width: 17px;
  height: 13px;
  margin-left: 8px;
  flex: 0 0 17px;
  color: currentColor;
  background:
    linear-gradient(currentColor 0 0) top / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) center / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) bottom / 100% 2px no-repeat;
}

.workspace { display: block; flex: 1 1 auto; min-width: 0; min-height: 0; }
.calendar-panel, .deadlines-panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.calendar-panel { display: flex; width: 100%; height: 100%; min-height: 0; padding: 12px; flex-direction: column; overflow: hidden; }
.deadlines-panel { flex: 1 1 auto; min-height: 0; padding: 16px; overflow-y: auto; }
.section-heading, .side-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.section-heading > *, .side-heading > * { min-width: 0; }
.section-heading h2, .side-heading h2 { margin: 0; font-size: 1.12rem; letter-spacing: -.025em; overflow-wrap: anywhere; }
.section-help { margin: 0; color: var(--ink-soft); font-size: .78rem; }
.week-grid { display: grid; flex: 1 1 auto; min-height: 0; grid-template-columns: repeat(7, minmax(145px, 1fr)); gap: 8px; overflow-x: auto; overflow-y: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 2px 2px 5px; }
.day-column { display: flex; width: 100%; max-width: 100%; height: 100%; min-width: 0; min-height: 0; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #fafcfa; flex-direction: column; overflow: hidden; }
.day-column.today { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.day-column.overloaded { background: var(--amber-soft); border-color: #efc56e; }
.day-header { display: flex; min-width: 0; align-items: start; justify-content: space-between; gap: 6px; min-height: 56px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.day-toggle { display: flex; width: 100%; min-width: 0; min-height: 0; padding: 0; border: 0; align-items: start; justify-content: space-between; gap: 6px; background: transparent; color: var(--ink); text-align: left; }
.day-toggle:disabled { cursor: default; opacity: 1; }
.day-heading { min-width: 0; }
.day-status { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.day-chevron { display: none; width: 9px; height: 9px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .16s ease; }
.day-name { display: block; font-size: .82rem; font-weight: 820; text-transform: capitalize; }
.day-date { display: block; color: var(--ink-soft); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-load { padding: 2px 7px; border-radius: 999px; background: var(--teal-soft); color: var(--teal); font-size: .69rem; font-weight: 820; white-space: nowrap; }
.overloaded .day-load { background: #f8d58c; color: #805000; }
.task-list { display: grid; flex: 1 1 auto; min-height: 0; align-content: start; gap: 8px; padding-top: 9px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.task-card {
  position: relative;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--module-color, var(--teal));
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 3px 12px rgba(16,47,61,.04);
  overflow: hidden;
}
.task-card > *, .task-top > *, .task-meta > * { min-width: 0; max-width: 100%; }
.task-card:hover { border-top-color: var(--line-strong); border-right-color: var(--line-strong); border-bottom-color: var(--line-strong); transform: translateY(-1px); }
.task-card.done { opacity: .62; }
.task-card.done .task-title { text-decoration: line-through; }
.task-card.urgent::after { content: ""; position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--coral); top: 8px; right: 8px; }
.task-top { display: flex; min-width: 0; gap: 7px; align-items: start; }
.task-check { width: 17px; min-height: auto; height: 17px; margin: 2px 0 0; accent-color: var(--teal); flex: 0 0 auto; }
.task-title { display: block; padding-right: 7px; font-size: .78rem; font-weight: 760; line-height: 1.32; overflow-wrap: anywhere; }
.task-module { display: block; margin-top: 7px; color: var(--ink-soft); font-size: .66rem; line-height: 1.25; overflow-wrap: anywhere; }
.task-meta { display: flex; min-width: 0; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.tag { padding: 2px 6px; border-radius: 999px; background: #edf2f0; color: var(--ink-soft); font-size: .63rem; font-weight: 750; overflow-wrap: anywhere; }
.tag.overdue { background: var(--coral-soft); color: #ad392d; }
.add-day-task { width: 100%; margin-top: 9px; padding: 7px; border: 1px dashed var(--line-strong); border-radius: 9px; background: transparent; color: var(--ink-soft); font-size: .72rem; font-weight: 720; }
.empty-day { margin: 14px 0 2px; color: #8ba09f; font-size: .72rem; text-align: center; }

.module-summary { display: grid; gap: 13px; }
.module-row { display: grid; min-width: 0; gap: 5px; }
.module-line { display: flex; min-width: 0; justify-content: space-between; gap: 12px; font-size: .76rem; }
.module-name { font-weight: 720; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-hours { color: var(--ink-soft); white-space: nowrap; }
.bar { height: 7px; border-radius: 999px; background: #edf2f0; overflow: hidden; }
.bar > span { display: block; height: 100%; width: var(--width); border-radius: inherit; background: var(--color); }
.upcoming-list { display: grid; gap: 8px; }
.deadlines-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.upcoming-item { width: 100%; min-width: 0; padding: 14px; border: 1px solid var(--line); border-left: 4px solid var(--module-color, var(--teal)); border-radius: 13px; background: #f7faf8; color: var(--ink); text-align: left; overflow: hidden; }
.upcoming-item > * { min-width: 0; max-width: 100%; }
.upcoming-item:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.upcoming-item strong { display: block; font-size: .86rem; line-height: 1.3; overflow-wrap: anywhere; }
.upcoming-item span { display: block; margin-top: 5px; color: var(--ink-soft); font-size: .72rem; overflow-wrap: anywhere; }
.upcoming-item .deadline-primary { color: var(--teal); font-weight: 780; }
.upcoming-item .deadline-primary.overdue { color: #ad392d; }
.upcoming-item .deadline-notes { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.empty-state { padding: 18px 10px; border: 1px dashed var(--line-strong); border-radius: 11px; color: var(--ink-soft); font-size: .77rem; text-align: center; }
.deadlines-list .empty-state { grid-column: 1 / -1; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(8,30,40,.35); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.load-drawer { position: fixed; top: 0; right: 0; z-index: 41; width: min(390px, calc(100% - 20px)); height: 100dvh; padding: 22px; background: var(--card); box-shadow: -20px 0 60px rgba(16,47,61,.2); transform: translateX(105%); transition: transform .22s ease; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.load-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; min-width: 0; align-items: start; justify-content: space-between; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.drawer-header > * { min-width: 0; }
.drawer-header h2 { margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.drawer-copy { margin: 16px 0 20px; color: var(--ink-soft); font-size: .82rem; }
.load-summary {
  display: flex;
  min-width: 0;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
  padding: 13px 15px;
  border-radius: 16px;
  background: var(--ink);
  color: white;
  box-shadow: 0 10px 24px rgba(16,47,61,.14);
}
.load-summary > * { min-width: 0; }
.load-summary .stat-label { color: #bcd1d8; }
.load-summary .ring { width: 50px; }
body.drawer-open { overflow: hidden; }

.dialog { width: min(660px, calc(100% - 24px)); max-width: calc(100% - 24px); max-height: calc(100dvh - 30px); padding: 0; border: 0; border-radius: 20px; color: var(--ink); box-shadow: 0 30px 90px rgba(16,47,61,.28); overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.dialog::backdrop { background: rgba(8, 30, 40, .52); backdrop-filter: blur(3px); }
.dialog form, .dialog > div, .dialog > p { margin-left: 22px; margin-right: 22px; }
.dialog-header { display: flex; min-width: 0; align-items: start; justify-content: space-between; gap: 20px; padding: 22px 22px 0; }
.dialog-header > * { min-width: 0; }
.dialog-header h2 { margin: 0; font-size: 1.45rem; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px 22px; }
.form-grid label { display: grid; min-width: 0; gap: 6px; color: var(--ink-soft); font-size: .79rem; font-weight: 750; }
.form-grid small { font-weight: 550; }
.form-grid .field-help { color: var(--ink-soft); font-size: .7rem; line-height: 1.35; }
.full-field { grid-column: 1 / -1; }
.input-suffix { position: relative; min-width: 0; }
.input-suffix input { padding-right: 60px; }
.input-suffix span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-size: .75rem; }
.dialog-actions { padding: 16px 22px 22px; border-top: 1px solid var(--line); }
.dialog-spacer { flex: 1; }
.task-form-scroll { min-width: 0; }
.dialog-small { max-width: 480px; padding-bottom: 24px; }
.dialog-copy { color: var(--ink-soft); font-size: .9rem; }
.data-actions { padding: 8px 0; }
.data-message { min-height: 24px; color: var(--teal); font-size: .82rem; }
.confirm-dialog { width: min(420px, calc(100% - 28px)); padding: 0; overflow: hidden; }
.confirm-dialog[open] { animation: confirm-in .18s ease-out; }
.confirm-dialog > .confirm-dialog-content { margin: 0; padding: 26px; text-align: center; }
.confirm-symbol { display: grid; width: 46px; height: 46px; margin: 0 auto 14px; place-items: center; border-radius: 50%; background: var(--coral-soft); color: #a83225; font-size: 1.45rem; font-weight: 850; }
.confirm-symbol.primary { background: var(--teal-soft); color: var(--teal); }
.confirm-dialog h2 { margin: 3px 0 8px; font-size: 1.3rem; letter-spacing: -.025em; }
.confirm-dialog #confirmMessage { margin: 0; color: var(--ink-soft); font-size: .86rem; line-height: 1.5; overflow-wrap: anywhere; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
@keyframes confirm-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.module-picker { margin: 0; padding: 0; border: 0; }
.module-picker legend { color: var(--ink-soft); font-size: .79rem; font-weight: 750; }
.module-picker > p { margin: 3px 0 10px; color: var(--ink-soft); font-size: .75rem; font-weight: 500; }
.module-options { display: grid; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.module-option {
  display: flex !important;
  min-width: 0;
  grid-template-columns: none !important;
  align-items: center;
  gap: 9px !important;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--module-color);
  border-radius: 10px;
  color: var(--ink) !important;
  background: #fafcfa;
}
.module-option input { width: 17px; height: 17px; min-height: auto; margin: 0; accent-color: var(--teal); }
.module-option span { min-width: 0; font-size: .75rem; overflow-wrap: anywhere; }
.password-section { margin: 0 22px 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.password-section h3 { margin: 0; font-size: 1rem; }
.password-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; margin-top: 12px; }
.password-form .form-message { grid-column: 1 / -1; }
.install-section { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 18px; margin: 0 22px 24px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--teal-soft); }
.install-section > * { min-width: 0; }
.install-section h3 { margin: 0; font-size: 1rem; }
.install-section p:last-child { margin: 4px 0 0; color: var(--ink-soft); font-size: .76rem; }
.install-section .button { flex: 0 0 auto; }
.hidden { display: none !important; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; transform: translate(-50%, 30px); padding: 11px 16px; border-radius: 999px; background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; font-size: .84rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.toast-error { background: #8f2f25; }

/* Tablet horizontal y portátiles estrechos. */
@media (max-width: 1100px) {
  .app-shell { padding-inline: 14px; }
  .week-toolbar { gap: 12px; }
  .week-nav, .filters { gap: 7px; }
  .week-nav h2 { min-width: 205px; font-size: 1.22rem; }
  .filters select { min-width: 135px; }
  .deadlines-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .week-grid { grid-template-columns: repeat(7, minmax(155px, 1fr)); }
}

/* Tablet vertical: herramientas en dos filas, calendario aún horizontal. */
@media (max-width: 900px) {
  .topbar { min-height: 62px; }
  .brand p { display: none; }
  .profile-button { max-width: 180px; }
  .button { padding-inline: 11px; }
  .week-toolbar { align-items: stretch; flex-direction: column; gap: 7px; padding-top: 8px; }
  .week-nav { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px auto; align-items: end; }
  .week-nav h2 { min-width: 0; }
  .filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; }
  .filters select { min-width: 0; }
  .section-help { display: none; }
}

/* Móvil: panel superior a dos columnas y días apilados dentro del área disponible. */
@media (max-width: 680px) {
  .boot-view, .auth-view {
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .app-shell {
    padding-top: env(safe-area-inset-top);
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
  }
  .button, .icon-button, .add-day-task, select, input:not([type="checkbox"]) { min-height: 44px; }
  .icon-button { width: 44px; flex: 0 0 44px; }
  .brand h1 { font-size: .94rem; }
  .top-actions { gap: 6px; }
  .top-actions #dataButton { display: none; }
  .profile-button { width: 44px; padding: 6px; justify-content: center; }
  .profile-button > span:last-child { display: none; }
  .week-nav { grid-template-columns: 44px minmax(0, 1fr) 44px auto auto; }
  .mobile-filters-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
  .mobile-filters-button::before {
    content: "";
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M2 3h12L9.5 8v4l-3 1V8L2 3Z' fill='none' stroke='%23102f3d' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  .mobile-filters-button::after { content: ""; width: 7px; height: 7px; margin: -3px 1px 0 2px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .16s ease; }
  .mobile-filters-button[aria-expanded="true"]::after { margin-top: 3px; transform: rotate(225deg); }
  .filters {
    position: absolute;
    top: calc(100% + 2px);
    right: 0;
    z-index: 25;
    display: none;
    width: min(380px, 100%);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding: 12px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: rgba(255,255,255,.98);
    box-shadow: 0 18px 45px rgba(16,47,61,.2);
  }
  .filters.open { display: grid; }
  .filters .button { grid-column: 1 / -1; }
  .week-toolbar { padding-bottom: 6px; }
  .content-toolbar { gap: 6px; margin-block: 4px 6px; }
  .view-tabs { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-width: 0; }
  .view-tab { min-height: 40px; padding-inline: 7px; white-space: nowrap; }
  .load-drawer-button { width: 44px; min-width: 44px; height: 44px; padding: 0; overflow: hidden; color: transparent; font-size: 0; white-space: nowrap; }
  .load-drawer-button::after { width: 18px; height: 14px; margin: 0; flex-basis: 18px; color: var(--ink); }
  .calendar-panel { padding: 9px; }
  .section-heading { align-items: start; margin-bottom: 9px; }
  .week-grid { grid-template-columns: 1fr; grid-auto-rows: max-content; align-content: start; overflow-x: hidden; overflow-y: auto; }
  .day-column { height: max-content; min-height: 165px; flex: none; overflow: visible; }
  .task-list { grid-template-columns: 1fr; grid-auto-rows: max-content; min-height: auto; flex: none; overflow: visible; }
  .task-card { height: auto; min-height: 44px; }
  .task-check { width: 20px; height: 20px; }
  .add-day-task { grid-column: 1 / -1; }
  .deadlines-list { grid-template-columns: 1fr; }
  .upcoming-item { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button { flex: 1 1 120px; }
  .dialog-spacer { display: none; }
  .module-options, .password-form { grid-template-columns: 1fr; }
  .password-form .form-message { grid-column: auto; }
  .auth-card { padding: 24px; }
  .load-drawer {
    width: 100%;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-right: max(18px, env(safe-area-inset-right));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    padding-left: max(18px, env(safe-area-inset-left));
  }
  .dialog {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 760px);
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }
  .dialog form, .dialog > div, .dialog > p { margin-left: 16px; margin-right: 16px; }
  .dialog-header { padding: 18px 16px 0; }
  .dialog-header h2 { font-size: 1.28rem; }
  .form-grid { gap: 12px; padding: 17px 16px; }
  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: rgba(255,255,255,.96);
    box-shadow: 0 -8px 18px rgba(16,47,61,.05);
  }
  .password-section { margin: 0 16px max(20px, env(safe-area-inset-bottom)); }
  .install-section { align-items: stretch; margin: 0 16px max(20px, env(safe-area-inset-bottom)); flex-direction: column; }
  .toast { bottom: max(16px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 28px); text-align: center; }

  /* Editor estable: cabecera y acciones visibles; sólo los campos se desplazan. */
  #taskDialog {
    position: fixed;
    top: auto;
    right: 0;
    bottom: var(--visual-viewport-bottom-inset, 0px);
    left: 0;
    width: 100%;
    height: min(720px, calc(var(--visual-viewport-height, 100dvh) - 12px));
    max-height: min(720px, calc(var(--visual-viewport-height, 100dvh) - 12px));
    margin: 0 auto;
    overflow: hidden;
  }
  #taskDialog form { display: flex; height: 100%; max-height: none; margin-inline: 0; flex-direction: column; overflow: hidden; }
  .virtual-keyboard-controlled #taskDialog {
    bottom: var(--keyboard-height, 0px);
    height: min(720px, calc(var(--keyboard-available-height, 100dvh) - 12px));
    max-height: min(720px, calc(var(--keyboard-available-height, 100dvh) - 12px));
  }
  #taskDialog .dialog-header { flex: 0 0 auto; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); background: white; }
  #taskDialog .dialog-header h2 { font-size: 1.18rem; line-height: 1.15; }
  #taskDialog .eyebrow { margin-bottom: 0; font-size: .66rem; }
  #taskDialog .task-form-scroll { min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; scroll-padding-block: 12px; -webkit-overflow-scrolling: touch; }
  #taskDialog .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 9px; padding: 12px 16px; }
  #taskDialog .form-grid label { gap: 3px; font-size: .7rem; }
  #taskDialog .full-field { grid-column: 1 / -1; }
  #taskDialog input, #taskDialog select, #taskDialog textarea { min-height: 40px; padding-block: 6px; font-size: .78rem; }
  #taskDialog select { padding-right: 34px; background-position: right 11px center; }
  #taskDialog textarea { height: 52px; min-height: 52px; }
  #taskDialog .dialog-actions { position: static; flex: 0 0 auto; gap: 8px; padding-block: 9px max(9px, env(safe-area-inset-bottom)); }
  #taskDialog .dialog-actions .button { min-height: 42px; padding-inline: 8px; font-size: .78rem; white-space: nowrap; }
  .confirm-dialog > .confirm-dialog-content { margin: 0; padding: 22px 18px max(18px, env(safe-area-inset-bottom)); }

  /* Un único día abierto reduce el desplazamiento sin ocultar información. */
  .week-grid { gap: 6px; }
  .day-column { padding: 0 10px 10px; transition: border-color .16s ease, background .16s ease; }
  .day-header { min-height: 0; padding-bottom: 7px; }
  .day-toggle { min-height: 45px; align-items: center; }
  .day-chevron { display: block; margin-right: 3px; transform: rotate(225deg); }
  .day-column.collapsed { min-height: 47px; padding-bottom: 0; }
  .day-column.collapsed .day-header { padding-bottom: 0; border-bottom-color: transparent; }
  .day-column.collapsed .day-chevron { transform: rotate(45deg); }
  .day-column.collapsed .task-list { display: none; }
}

@media (max-width: 440px) {
  .topbar .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .brand h1 { font-size: .86rem; }
  .top-actions .button-primary { width: 44px; padding: 0; justify-content: center; }
  .new-task-label { display: none; }
  .week-nav { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .week-nav #todayButton { grid-column: 1 / 3; width: 100%; }
  .mobile-filters-button { grid-column: 3; grid-row: 2; width: 44px; padding: 0; }
  .mobile-filters-button span, .mobile-filters-button::after { display: none; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .button { grid-column: 1 / -1; }
  .auth-card { padding: 20px 16px; border-radius: 18px; }
}

/* Pantallas muy bajas (móvil apaisado): se preserva área útil para el plan. */
@media (max-height: 560px) and (max-width: 900px) {
  .topbar { min-height: 54px; }
  .week-toolbar { gap: 5px; padding-block: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
