:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #22262f;
  --text: #f2f3f5;
  --text-dim: #9aa0ab;
  --accent: #6c8cff;
  --green: #2ecc71;
  --red: #e74c3c;
  --black-state: #1a1a1a;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(90px + var(--safe-bottom));
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: calc(12px + var(--safe-top)) 16px 8px;
  border-bottom: 1px solid #2a2d35;
}

.switch {
  display: flex;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 12px;
}

.switch-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 0;
  border-radius: 999px;
  transition: background .25s ease, color .25s ease;
}

.switch-btn.active {
  background: var(--accent);
  color: #fff;
}

.category-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.category-filters::-webkit-scrollbar { display: none; }

.cat-btn {
  flex: 0 0 auto;
  border: 1px solid #2e323c;
  background: var(--surface);
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.cat-btn.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

/* ---------- Lista de tareas ---------- */
.task-list {
  padding: 14px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  margin-top: 60px;
  font-size: 15px;
}

.task-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: transform .35s ease, opacity .35s ease, max-height .35s ease, margin .35s ease, padding .35s ease;
  max-height: 100px;
}

.task-item .accent-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: var(--radius) 0 0 var(--radius);
}

.task-checkbox {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.task-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--text-dim);
  background: transparent;
  position: relative;
  cursor: pointer;
}

.task-checkbox input[type="checkbox"]::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
}

.task-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  z-index: 2;
  cursor: pointer;
}

.task-icon {
  font-size: 20px;
  flex: 0 0 auto;
}

.task-title {
  flex: 1;
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-counter {
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.25);
  white-space: nowrap;
}

.task-item.completed-view .task-title {
  text-decoration: line-through;
  color: var(--text-dim);
}

.task-revert {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  z-index: 2;
  padding: 4px;
}

/* ---------- Animación de completar ---------- */
.complete-overlay {
  position: absolute;
  inset: 0;
  background: var(--green);
  clip-path: circle(0% at 30px 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}

.complete-text {
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .5px;
  opacity: 0;
  transform: translate(0,0) scale(.3);
}

.task-item.completing .complete-overlay {
  animation: fillGreen .55s ease forwards;
}

.task-item.completing .complete-text {
  animation: popText .35s ease .3s forwards;
}

@keyframes fillGreen {
  from { clip-path: circle(0% at 30px 50%); }
  to   { clip-path: circle(150% at 30px 50%); }
}

@keyframes popText {
  0%   { opacity: 0; transform: scale(.3); }
  100% { opacity: 1; transform: scale(1); }
}

.task-item.imploding {
  animation: implode .4s ease forwards;
  animation-delay: .75s;
}

@keyframes implode {
  0%   { transform: scale(1); opacity: 1; max-height: 100px; margin-bottom: 10px; }
  60%  { transform: scale(.82); opacity: .5; }
  100% { transform: scale(0); opacity: 0; max-height: 0; margin: 0; padding-top: 0; padding-bottom: 0; }
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(108,140,255,.45);
  z-index: 30;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(28px + var(--safe-bottom));
  position: relative;
  animation: slideUp .25s ease;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 15px;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 40px;
  margin-bottom: 8px;
}

.modal-cat-icon { font-size: 26px; }
.modal-header h2 { margin: 0; font-size: 20px; }

.modal-description {
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 8px 0 16px;
  white-space: pre-wrap;
}

.modal-dates {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.date-block {
  flex: 1;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.date-block .label {
  font-size: 11.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.secondary-btn, .danger-btn, .submit-btn, .split-toggle {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
}

.secondary-btn { background: var(--surface-2); color: var(--text); flex: 1; }
.danger-btn { background: rgba(231,76,60,.15); color: var(--red); flex: 1; }
.submit-btn { background: var(--accent); color: #fff; width: 100%; margin-top: 8px; }
.split-toggle { background: var(--surface-2); color: var(--text); width: 100%; margin-top: 6px; }

.edit-container, .split-container {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #2a2d35;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.split-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 4px;
}

label {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 6px;
}

input[type="text"], input[type="datetime-local"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid #2e323c;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}

textarea { min-height: 70px; resize: vertical; }

.subtask-row {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  position: relative;
}

.subtask-row .remove-subtask {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
}

/* ---------- Selector de categoría (crear tarea) ---------- */
.category-select {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.cat-option {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 64px;
}

.cat-option-icon { font-size: 20px; }
.cat-option-label { font-size: 10.5px; color: var(--text-dim); }

.cat-option.selected {
  border-color: var(--accent);
}
.cat-option.selected .cat-option-label { color: var(--text); }
