:root {
  --bg: #f3f0ea;
  --surface: #fffcf7;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e0d6;
  --shadow: 0 12px 40px rgba(28, 25, 23, 0.08);
  --fis: #7eb8de;
  --mat: #7dcb9e;
  --port: #e8a78a;
  --qui: #6dbfb5;
  --fq: #9aa8c4;
  --prep: #c4b5a5;
  --desc: #b5aed0;
  --radius: 14px;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -10%, #ffe8d2 0%, transparent 40%),
    radial-gradient(circle at 90% 0%, #d7efe6 0%, transparent 35%),
    var(--bg);
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #1c1917, #44403c);
  color: #fff; font-family: var(--font-display); font-weight: 700;
}
.brand h1 {
  margin: 0; font-family: var(--font-display); font-size: 1.35rem; letter-spacing: -0.02em;
}
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }

.topbar-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.month-nav {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 8px; box-shadow: var(--shadow);
}
.month-nav h2 {
  margin: 0; min-width: 160px; text-align: center;
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 600;
}

.btn, .icon-btn {
  font: inherit; cursor: pointer; border: 1px solid transparent;
}
.btn {
  border-radius: 10px; padding: 9px 14px; background: #fff; border-color: var(--line);
  color: var(--ink); font-weight: 500;
}
.btn:hover { background: #faf7f2; }
.btn.primary {
  background: #1c1917; color: #fff; border-color: #1c1917;
}
.btn.primary:hover { background: #292524; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.danger { color: #b91c1c; border-color: #fecaca; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 999px; background: transparent;
  font-size: 1.25rem; line-height: 1; color: var(--ink);
}
.icon-btn:hover { background: #f5f1ea; }

.legend {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 0; flex: 1;
}
.legend-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}
.legend-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 0.8rem; font-weight: 500;
}
.legend-dot {
  width: 9px; height: 9px; border-radius: 50%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 14px;
  align-items: start;
}

.calendar-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
  width: 100%;
}

.calendar-head, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  width: 100%;
}
.calendar-head {
  background: #1c1917; color: #fafaf9;
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
.calendar-head span {
  min-width: 0;
  padding: 10px 4px; text-align: center; border-right: 1px solid #292524;
}
.calendar-head span:last-child { border-right: none; }

.day-cell {
  min-width: 0;
  min-height: 118px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 6px;
  background: #fffcf7;
  cursor: pointer;
  transition: background 0.15s ease;
  overflow: hidden;
}
.day-cell:nth-child(7n) { border-right: none; }
.day-cell:hover { background: #f8f4ee; }
.day-cell.outside { background: #f1ece4; color: #a8a29e; }
.day-cell.selected {
  outline: 2px solid #1c1917;
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}
.day-cell.today .day-num {
  background: #1c1917; color: #fff; border-radius: 999px;
  width: 26px; height: 26px; display: grid; place-items: center;
}

.day-num {
  font-family: var(--font-display); font-weight: 600; font-size: 0.92rem;
  margin-bottom: 6px;
}
.day-chips {
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0; max-width: 100%;
}
.chip {
  display: block;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 0.68rem; line-height: 1.2; padding: 3px 6px; border-radius: 6px;
  color: #1c1917; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 600;
}
.chip.done { opacity: 0.45; text-decoration: line-through; }
.chip-more {
  font-size: 0.68rem; color: var(--muted); padding-left: 2px;
}

.side-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 420px;
  position: sticky; top: 12px;
  padding: 16px;
}
.side-empty h3, .side-header h3 {
  margin: 0; font-family: var(--font-display); letter-spacing: -0.02em;
}
.side-empty p { color: var(--muted); line-height: 1.45; }
.side-eyebrow {
  margin: 0 0 4px; color: var(--muted); font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.side-header {
  display: flex; justify-content: space-between; gap: 8px; align-items: flex-start;
  margin-bottom: 10px;
}
.side-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px;
}
.hidden { display: none !important; }

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  background: #fff;
}
.task-card.done { opacity: 0.65; }
.task-card-top {
  display: flex; gap: 10px; align-items: flex-start;
}
.task-card input[type="checkbox"] {
  margin-top: 3px; width: 16px; height: 16px; accent-color: #1c1917;
}
.task-meta {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px;
}
.tag {
  font-size: 0.72rem; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: #f5f1ea; color: var(--ink);
}
.tag.type { background: #eceff3; }
.task-card h4 {
  margin: 0; font-size: 0.95rem; font-family: var(--font-display); font-weight: 600;
}
.task-card p {
  margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.4; white-space: pre-wrap;
}
.task-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.reorder-btns {
  display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}
.reorder-btn {
  width: 28px; height: 28px; font-size: 0.85rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.reorder-btn:hover:not(:disabled) { background: #f5f1ea; }
.reorder-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.task-card.drop-before {
  box-shadow: inset 0 3px 0 #0f7a45;
}
.duration { font-size: 0.75rem; color: var(--muted); }

.modal {
  border: none; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px));
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(28, 25, 23, 0.45); }
.modal form {
  display: flex; flex-direction: column; gap: 12px; padding: 20px;
}
.modal h3 { margin: 0; font-family: var(--font-display); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-close {
  flex-shrink: 0;
  font-size: 1.5rem;
  line-height: 1;
}
.modal label {
  display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 500;
}
.modal input, .modal textarea, .modal select {
  font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
  background: #fff;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 4px;
}
.modal-actions-right { display: flex; gap: 8px; }

.disc-FIS { background: var(--fis); }
.disc-MAT { background: var(--mat); }
.disc-PORT { background: var(--port); }
.disc-QUI { background: var(--qui); }
.disc-FQ { background: var(--fq); }
.disc-PREP { background: var(--prep); }
.disc-DESC { background: var(--desc); }

/* Tabs & view toggle */
.tabs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.tab {
  font: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 8px 14px; font-weight: 500; color: var(--ink);
}
.tab:hover { background: #faf7f2; }
.tab.active {
  background: #1c1917; color: #fff; border-color: #1c1917;
}
.view-toggle {
  display: inline-flex; gap: 0; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; background: var(--surface);
}
.view-btn {
  border: none !important; border-radius: 0 !important; margin: 0;
  background: transparent;
}
.view-btn.active {
  background: #1c1917 !important; color: #fff !important;
}

.filter-chip {
  cursor: pointer; font: inherit; transition: opacity 0.15s, transform 0.15s;
}
.filter-chip.dim { opacity: 0.4; }
.filter-chip.active {
  outline: 2px solid #1c1917; outline-offset: 1px;
}

.chip { cursor: grab; }
.chip.dragging, .task-card.dragging { opacity: 0.5; }
.day-cell.drop-target {
  background: #e8f5e9 !important;
  outline: 2px dashed #0f7a45;
  outline-offset: -2px;
}

.week-grid {
  grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
}
.week-cell {
  min-height: 280px !important;
}
.side-progress {
  font-size: 0.8rem; color: var(--muted); font-weight: 600;
}

.tools-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.tools-header {
  display: flex; flex-wrap: wrap; justify-content: space-between;
  align-items: flex-start; gap: 12px; margin-bottom: 16px;
}
.tools-header h2 {
  margin: 0; font-family: var(--font-display); letter-spacing: -0.02em;
}
.tools-header p { margin: 4px 0 0; color: var(--muted); }
.cards-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.tool-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff;
}
.tool-card h3 {
  margin: 8px 0 6px; font-family: var(--font-display); font-size: 1rem;
}
.tool-card p { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.4; }
.tool-card-top {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.tool-card.done-exam { border-color: #86efac; background: #f0fdf4; }
.empty-hint {
  color: var(--muted); padding: 12px; grid-column: 1 / -1;
}
.check-row {
  display: flex !important; flex-direction: row !important; align-items: center;
  gap: 8px; font-weight: 500; font-size: 0.88rem;
}
.check-row.tight { margin: 0; }
.score-label {
  display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; margin-top: 8px;
}
.score-label input {
  font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; max-width: 120px;
}
.score-pct { font-weight: 700; color: var(--ink) !important; margin-top: 6px !important; }
.sims-summary { margin-bottom: 16px; overflow-x: auto; }
.sims-table {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
  background: #fff; border-radius: 10px; overflow: hidden;
}
.sims-table th, .sims-table td {
  border: 1px solid var(--line); padding: 10px 12px; text-align: center;
}
.sims-table th { background: #1c1917; color: #fff; }
.sims-table td:first-child, .sims-table th:first-child { text-align: left; }

.progress-modes { gap: 8px; }
.progress-summary {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}
.progress-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.progress-row {
  display: grid;
  grid-template-columns: minmax(88px, 140px) 1fr auto;
  gap: 10px 12px;
  align-items: center;
}
.progress-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
  font-size: 0.9rem;
}
.progress-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.progress-track {
  height: 14px;
  border-radius: 999px;
  background: #efe9e0;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-fill {
  height: 100%;
  border-radius: inherit;
  width: 0;
  transition: width 0.35s ease;
  min-width: 0;
}
.progress-meta {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
  min-width: 5.5rem;
}
.progress-empty {
  color: var(--muted);
  padding: 8px 0;
}

@media (max-width: 640px) {
  .progress-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "label meta"
      "bar bar";
  }
  .progress-label { grid-area: label; }
  .progress-meta { grid-area: meta; }
  .progress-track { grid-area: bar; }
}
.tools-header-actions {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.save-status {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}
.save-status.flash {
  color: #15803d;
}
.data-menu {
  position: relative;
}
.data-menu > summary {
  list-style: none;
  cursor: pointer;
}
.data-menu > summary::-webkit-details-marker { display: none; }
.data-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  width: min(280px, 80vw);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.data-menu-hint {
  margin: 0 0 4px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.storage-banner {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start;
  justify-content: space-between;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #f0d9a8;
  background: #fff8eb;
  color: #5c4813;
  font-size: 0.92rem;
  line-height: 1.45;
}
.storage-banner p { margin: 0; flex: 1; min-width: 220px; }
.storage-banner strong { color: #3f2e0a; }
.storage-banner .banner-actions {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.tag.diff-facil { background: #d8f3e0; color: #14532d; }
.tag.diff-medio { background: #fef3c7; color: #92400e; }
.tag.diff-dificil { background: #fde2e1; color: #9f1239; }
.chip-hard { box-shadow: inset 3px 0 0 #e11d48; }
.chip-easy { box-shadow: inset 3px 0 0 #16a34a; }
.iave-links {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.iave-links .btn:disabled,
.iave-links a.btn.disabled {
  opacity: 0.45; pointer-events: none;
}
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.modal-hint {
  margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.4;
}
.color-fieldset {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  margin: 0;
}
.color-fieldset legend {
  padding: 0 6px; font-size: 0.85rem; font-weight: 500;
}
.color-swatches {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.color-swatch {
  width: 28px; height: 28px; border-radius: 999px; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.color-swatch.selected {
  outline: 2px solid #1c1917; outline-offset: 2px;
}
.subject-list-wrap {
  padding: 0;
  border-top: none;
  margin: 0;
}
.subject-list-top { margin-bottom: 4px; }
.subject-list-wrap h4, .modal-subhead {
  margin: 8px 0; font-family: var(--font-display); font-size: 0.95rem;
}
.modal-sep {
  border: none; border-top: 1px solid var(--line); margin: 14px 0;
}
.subject-list { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; }
.subject-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  flex-wrap: wrap;
}
.subject-row-left {
  display: flex; align-items: center; gap: 8px; font-weight: 500; min-width: 120px;
}
.subject-row-colors {
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
}
.subject-row .color-swatch {
  width: 22px; height: 22px;
}
.subject-row-actions {
  display: flex; gap: 6px; align-items: center; margin-left: auto;
}
.subject-row input[type="text"] {
  font: inherit; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 8px; max-width: 140px;
}
.chip-custom, .tag-custom {
  /* color set inline */
}

.scope-row {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px;
}
.scope-chip {
  font-weight: 600;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(260px, 300px); }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side-panel { position: static; min-height: auto; }
  .day-cell { min-height: 96px; }
  .week-grid {
    grid-template-columns: 1fr !important;
    gap: 0;
  }
  .week-cell { min-height: 140px !important; }
  .calendar-head { display: none; }
  .topbar { gap: 10px; }
  .topbar-actions { width: 100%; }
  .month-nav { flex: 1; justify-content: space-between; }
  .month-nav h2 { min-width: 0; flex: 1; font-size: 0.95rem; }
}

@media (max-width: 640px) {
  .app { padding: 12px 10px 28px; }
  .brand h1 { font-size: 1.1rem; }
  .brand p { display: none; }
  .chip { font-size: 0.72rem; padding: 5px 7px; }
  .day-cell { min-height: 88px; padding: 8px; }
  .week-cell { min-height: 160px !important; }
  .form-row { grid-template-columns: 1fr; }
  .btn.ghost#btn-backup,
  .btn.ghost#btn-restore,
  #btn-export { font-size: 0.8rem; padding: 8px 10px; }
  .tabs { gap: 4px; }
  .tab { padding: 8px 10px; font-size: 0.85rem; }
  .side-panel { min-height: 0; }
}

@media (min-width: 768px) and (max-width: 1100px) {
  .week-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
  }
  .week-cell { min-height: 220px !important; }
  .calendar-head { display: grid; }
}
