/* ==========================================================================
   Componentes
   ========================================================================== */

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast), opacity var(--dur-fast);
}
.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.btn:hover {
  background: var(--surface-hover);
}
.btn:active {
  transform: scale(0.98);
}
.btn[disabled],
.btn[aria-busy='true'] {
  opacity: 0.55;
  pointer-events: none;
}
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  font-weight: 600;
}
.btn-primary:hover {
  background: color-mix(in oklab, var(--accent) 88%, white);
}
.btn-secondary {
  background: var(--accent-2-soft);
  border-color: var(--accent-2-line);
  color: var(--text-primary);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}
.btn-danger {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 40%, transparent);
  color: var(--danger);
}
.btn-danger:hover {
  background: color-mix(in oklab, var(--danger) 22%, transparent);
}
.btn-sm {
  min-height: 34px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn-block {
  width: 100%;
}
.btn .spinner {
  width: 14px;
  height: 14px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--dur-fast), color var(--dur-fast);
  position: relative;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.icon-btn-sm {
  width: 34px;
  height: 34px;
}
.icon-btn-sm svg {
  width: 16px;
  height: 16px;
}
.icon-btn .dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--background);
}

.kbd {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

/* ---------------- Cards ---------------- */
.card {
  position: relative;
  min-width: 0;
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in oklab, var(--surface) 92%, white 1%), var(--surface));
}
.card-elevated {
  background: var(--surface-elevated);
}
.card-accent {
  border-color: var(--accent-line);
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in oklab, var(--accent) calc(9% * var(--glow-strength)), transparent), transparent 60%),
    var(--surface);
}
.card-purple {
  border-color: var(--accent-2-line);
  background:
    radial-gradient(120% 100% at 100% 0%, color-mix(in oklab, var(--accent-2) calc(16% * var(--glow-strength)), transparent), transparent 65%),
    var(--surface);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  min-height: 24px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
}
.card-title .label {
  color: var(--text-tertiary);
}
.card-link {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  transition: color var(--dur-fast);
}
.card-link:hover {
  color: var(--accent);
}
.card-link svg {
  width: 14px;
  height: 14px;
}
/* marcas técnicas en las esquinas */
.card-ticks::before,
.card-ticks::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--border-strong);
  border-style: solid;
  pointer-events: none;
}
.card-ticks::before {
  top: -1px;
  left: -1px;
  border-width: 1px 0 0 1px;
  border-top-left-radius: var(--radius);
}
.card-ticks::after {
  bottom: -1px;
  right: -1px;
  border-width: 0 1px 1px 0;
  border-bottom-right-radius: var(--radius);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
}

/* ---------------- KPI ---------------- */
.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.kpi-value {
  font-size: var(--text-lg);
  font-weight: 400;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  flex-wrap: wrap;
}
@media (min-width: 768px) {
  .kpi-value {
    font-size: var(--text-xl);
    font-weight: 300;
  }
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  white-space: nowrap;
}
.delta-good {
  color: var(--accent);
  background: var(--accent-soft);
}
.delta-bad {
  color: var(--danger);
  background: var(--danger-soft);
}
.delta-neutral {
  color: var(--text-secondary);
  background: var(--surface-hover);
}

/* ---------------- Badges / chips ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  font-size: var(--text-2xs);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge-accent {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.badge-purple {
  color: color-mix(in oklab, var(--accent-2) 80%, white);
  border-color: var(--accent-2-line);
  background: var(--accent-2-soft);
}
.badge-warning {
  color: var(--warning);
  border-color: color-mix(in oklab, var(--warning) 35%, transparent);
  background: var(--warning-soft);
}
.badge-danger {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 35%, transparent);
  background: var(--danger-soft);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.status-dot.live {
  box-shadow: 0 0 0 3px color-mix(in oklab, currentColor 25%, transparent);
}
.color-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: none;
  background: var(--c, var(--accent));
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  transition: all var(--dur-fast);
}
.chip:hover {
  color: var(--text-primary);
}
.chip[aria-pressed='true'],
.chip[aria-checked='true'],
.chip:has(input:checked) {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-soft);
}
.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip:has(input:focus-visible) {
  box-shadow: var(--focus-ring);
}

/* ---------------- Tabs / segmented ---------------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  flex: 1 0 auto;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.tab:hover {
  color: var(--text-primary);
}
.tab[aria-selected='true'] {
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 0 0 1px var(--border);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}
.segmented label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 0 var(--space-2);
  border-radius: 6px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  line-height: 1.15;
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label:has(input:checked) {
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--border-strong);
}
.segmented label:has(input:focus-visible) {
  box-shadow: var(--focus-ring);
}
.segmented[data-tone='need'] label:has(input[value='necessary']:checked) {
  color: var(--accent);
}
.segmented[data-tone='need'] label:has(input[value='unsure']:checked) {
  color: var(--warning);
}
.segmented[data-tone='need'] label:has(input[value='unnecessary']:checked) {
  color: var(--danger);
}

/* ---------------- Formularios ---------------- */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > label,
.field-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
}
.field-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.field-error {
  font-size: var(--text-xs);
  color: var(--danger);
}
.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.input,
.select,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 16px; /* evita zoom en iOS */
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  appearance: none;
  -webkit-appearance: none;
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-disabled);
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid='true'],
.select[aria-invalid='true'],
.textarea[aria-invalid='true'] {
  border-color: var(--danger);
}
.textarea {
  min-height: 110px;
  padding: var(--space-3);
  resize: vertical;
  line-height: 1.55;
}
.select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23a1a1aa' stroke-width='1.5'%3E%3Cpath d='M2 4.5 6 8l4-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.select option {
  background: var(--surface-elevated);
}
input[type='date'].input,
input[type='time'].input {
  min-width: 0;
}
input[type='date']::-webkit-calendar-picker-indicator,
input[type='time']::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
}
@media (min-width: 768px) {
  .input,
  .select {
    min-height: 42px;
    font-size: var(--text-sm);
  }
  .textarea {
    font-size: var(--text-sm);
  }
}

.money-input {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-3) 0 var(--space-2);
  border-bottom: 1px solid var(--border-strong);
  transition: border-color var(--dur-fast);
}
.money-input:focus-within {
  border-color: var(--accent);
}
.money-input .currency {
  font-size: var(--text-xl);
  font-weight: 300;
  color: var(--text-tertiary);
}
.money-input input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font-size: 2.5rem;
  font-weight: 300;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  padding: 0;
  color: var(--text-primary);
}
.money-input input:focus {
  box-shadow: none;
}
.money-input input::placeholder {
  color: var(--text-disabled);
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  cursor: pointer;
  font-size: var(--text-sm);
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-track {
  position: relative;
  width: 40px;
  height: 24px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  border: 1px solid var(--border-strong);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform var(--dur) var(--ease-out), background var(--dur-fast);
}
.switch input:checked + .switch-track {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.switch input:checked + .switch-track::after {
  transform: translateX(16px);
  background: var(--accent);
}
.switch input:focus-visible + .switch-track {
  box-shadow: var(--focus-ring);
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.swatch {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--c);
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
}
.swatch input {
  position: absolute;
  opacity: 0;
}
.swatch:has(input:checked) {
  border-color: var(--background);
  box-shadow: 0 0 0 2px var(--c);
}
.swatch:has(input:focus-visible) {
  box-shadow: var(--focus-ring);
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: var(--space-1);
}
.icon-picker label {
  position: relative;
  display: grid;
  place-items: center;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 16px;
}
.icon-picker input {
  position: absolute;
  opacity: 0;
}
.icon-picker label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.weekday-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-1);
}
.weekday-picker label {
  position: relative;
  display: grid;
  place-items: center;
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  cursor: pointer;
  color: var(--text-secondary);
}
.weekday-picker input {
  position: absolute;
  opacity: 0;
}
.weekday-picker label:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent-contrast);
  background: var(--accent);
}

details.more-fields > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
details.more-fields > summary::-webkit-details-marker {
  display: none;
}
details.more-fields > summary svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur);
}
details.more-fields[open] > summary svg {
  transform: rotate(90deg);
}
details.more-fields > .form {
  margin-top: var(--space-3);
}

.form-error {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid color-mix(in oklab, var(--danger) 30%, transparent);
  color: var(--danger);
  font-size: var(--text-sm);
}
.form-note {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ---------------- Dialog / sheet ---------------- */
dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
dialog.sheet:not([open]) {
  display: none;
}
dialog.sheet[open] {
  animation: sheet-up calc(var(--dur) * 1.4) var(--ease-out);
}
dialog.sheet[data-closing] {
  animation: sheet-down var(--dur) var(--ease-in-out) forwards;
}
dialog.sheet::backdrop {
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in var(--dur);
}
@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
@keyframes sheet-down {
  to {
    transform: translateY(40px);
    opacity: 0;
  }
}
.sheet-grabber {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
  margin: 8px auto 0;
  flex: none;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-2) var(--space-5);
  flex: none;
}
.sheet-header h2 {
  font-size: var(--text-md);
  font-weight: 500;
}
.sheet-body {
  padding: var(--space-2) var(--space-5) var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}
.sheet-footer {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) calc(var(--space-4) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface-elevated);
  flex: none;
}
.sheet-footer .btn {
  flex: 1;
}
.sheet-footer .btn-ghost,
.sheet-footer .icon-btn {
  flex: none;
}

@media (min-width: 768px) {
  dialog.sheet {
    inset: 0;
    margin: auto;
    width: min(560px, calc(100vw - 48px));
    max-height: min(820px, calc(100dvh - 64px));
    height: fit-content;
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border-strong);
  }
  dialog.sheet.sheet-wide {
    width: min(760px, calc(100vw - 48px));
  }
  dialog.sheet.sheet-narrow {
    width: min(420px, calc(100vw - 48px));
  }
  .sheet-grabber {
    display: none;
  }
  .sheet-header {
    padding-top: var(--space-4);
  }
  .sheet-footer {
    padding-bottom: var(--space-4);
    justify-content: flex-end;
  }
  .sheet-footer .btn {
    flex: none;
  }
  @keyframes sheet-up {
    from {
      transform: translateY(12px) scale(0.98);
      opacity: 0;
    }
  }
  @keyframes sheet-down {
    to {
      transform: translateY(8px) scale(0.98);
      opacity: 0;
    }
  }
}

/* ---------------- Toast ---------------- */
.toasts {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--space-4));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
@media (min-width: 768px) {
  .toasts {
    left: auto;
    right: var(--space-6);
    bottom: var(--space-6);
    transform: none;
  }
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: fade-up var(--dur) var(--ease-out);
}
.toast[data-leaving] {
  opacity: 0;
  transform: translateY(6px);
  transition: all var(--dur);
}
.toast .status-dot {
  color: var(--accent);
}
.toast[data-tone='error'] .status-dot {
  color: var(--danger);
}
.toast[data-tone='warning'] .status-dot {
  color: var(--warning);
}
.toast .btn {
  min-height: 32px;
  margin-left: auto;
}

/* ---------------- Progreso ---------------- */
.progress {
  position: relative;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--heat-empty);
  overflow: hidden;
}
.progress-bar {
  position: absolute;
  inset: 0;
  transform-origin: left;
  border-radius: inherit;
  background: var(--c, var(--accent));
  width: var(--w, 0%);
  transition: width var(--dur-slow) var(--ease-out);
  animation: grow-x var(--dur-slow) var(--ease-out) both;
}
.progress[data-over] .progress-bar {
  background: var(--danger);
}
.progress-thin {
  height: 3px;
}
.progress-lg {
  height: 10px;
}
.progress-segments {
  display: flex;
  gap: 3px;
}
.progress-segments span {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: var(--heat-empty);
}
.progress-segments span[data-on] {
  background: var(--c, var(--accent));
}
.progress-segments span[data-next] {
  background: color-mix(in oklab, var(--c, var(--accent)) 30%, transparent);
}

.ring {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
}
.ring svg {
  transform: rotate(-90deg);
}
.ring-track {
  stroke: var(--heat-empty);
}
.ring-value {
  stroke: var(--c, var(--accent));
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slow) var(--ease-out);
  filter: drop-shadow(0 0 calc(4px * var(--glow-strength)) color-mix(in oklab, var(--c, var(--accent)) 50%, transparent));
}
.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------------- Listas ---------------- */
.list {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child {
  border-bottom: 0;
}
button.list-item,
a.list-item {
  width: 100%;
  text-align: left;
  border-radius: 0;
  transition: background var(--dur-fast);
}
button.list-item:hover,
a.list-item:hover {
  background: linear-gradient(90deg, transparent, var(--surface-hover) 12%, var(--surface-hover) 88%, transparent);
}
.list-icon {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--c, var(--accent-2)) 14%, transparent);
  color: var(--c, var(--accent-2));
  font-size: 15px;
}
.list-icon svg {
  width: 16px;
  height: 16px;
}
.list-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.list-title {
  font-size: var(--text-sm);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-end {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex: none;
  text-align: right;
}
.amount {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.amount-in {
  color: var(--accent);
}
.day-group {
  padding: var(--space-4) 0 var(--space-1);
  display: flex;
  justify-content: space-between;
}

/* ---------------- Habit check ---------------- */
.check-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.habit-check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 60px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  transition: border-color var(--dur), background var(--dur);
}
.habit-check:hover {
  border-color: var(--border-strong);
}
.habit-check[aria-checked='true'] {
  border-color: color-mix(in oklab, var(--c, var(--accent)) 38%, transparent);
  background: color-mix(in oklab, var(--c, var(--accent)) 7%, var(--surface-2));
}
.habit-box {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  border: 1.5px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--accent-contrast);
  transition: background var(--dur), border-color var(--dur);
}
.habit-box svg {
  width: 16px;
  height: 16px;
  opacity: 0;
  transform: scale(0.6);
}
.habit-check[aria-checked='true'] .habit-box {
  background: var(--c, var(--accent));
  border-color: var(--c, var(--accent));
}
.habit-check[aria-checked='true'] .habit-box svg {
  opacity: 1;
  animation: check-pop var(--dur) var(--ease-out) both;
  transform: none;
}
.habit-check[data-status='2'] .habit-box {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--c, var(--accent)) 25%, transparent), 0 0 calc(14px * var(--glow-strength)) color-mix(in oklab, var(--c, var(--accent)) 55%, transparent);
}
.habit-name {
  font-size: var(--text-base);
}
.habit-check[aria-checked='true'] .habit-name {
  color: var(--text-secondary);
}
.habit-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.habit-icon {
  width: 22px;
  text-align: center;
  color: var(--c, var(--accent));
  flex: none;
}

/* ---------------- Heatmap ---------------- */
.heatmap-months {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-4);
}
@media (min-width: 560px) {
  .heatmap-months {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (min-width: 1000px) {
  .heatmap-months {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
@media (min-width: 1440px) {
  .heatmap-months {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
.heat-month h4 {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}
.heat-month h4 span:last-child {
  color: var(--text-disabled);
}
.heat-month[data-current] h4 span:first-child {
  color: var(--accent);
}
.heat-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}
.heat-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--heat-empty);
  position: relative;
  padding: 0;
  min-width: 0;
}
.heat-cell[data-pad] {
  background: transparent;
  pointer-events: none;
}
.heat-cell[data-level='0'] {
  background: var(--heat-miss);
}
.heat-cell[data-level='1'] {
  background: var(--heat-1);
}
.heat-cell[data-level='2'] {
  background: var(--heat-2);
}
.heat-cell[data-future] {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--heat-empty);
}
.heat-cell[data-today] {
  outline: 1px solid var(--text-primary);
  outline-offset: 1px;
}
button.heat-cell:hover {
  outline: 1px solid var(--text-secondary);
  outline-offset: 1px;
}
.heat-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.heat-legend .heat-cell {
  width: 11px;
  height: 11px;
}

/* Heatmap semanal (tipo GitHub) para desktop */
.heat-weeks {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  overflow-x: auto;
  padding-bottom: var(--space-2);
}
.heat-weeks .heat-cell {
  width: 13px;
  height: 13px;
}

.tooltip {
  position: fixed;
  z-index: 300;
  min-width: 160px;
  max-width: 260px;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-xs);
  pointer-events: none;
  animation: fade-in var(--dur-fast);
}
.tooltip strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: 4px;
}

/* ---------------- Charts ---------------- */
.chart {
  position: relative;
  width: 100%;
}
.chart svg {
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart-grid line {
  stroke: var(--grid-line);
}
.chart-axis text {
  fill: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 10px;
}
.chart-bar {
  transform-box: fill-box;
  transform-origin: bottom;
  animation: grow-y var(--dur-slow) var(--ease-out) both;
}
.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-area {
  opacity: 0.18;
}
.chart-hit {
  fill: transparent;
  cursor: crosshair;
}
.chart-hit:hover + .chart-hover,
.chart-col:hover .chart-hover {
  opacity: 1;
}
.chart-hover {
  opacity: 0;
  fill: rgba(255, 255, 255, 0.04);
  pointer-events: none;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--c);
  display: inline-block;
}

.hbars {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.hbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px var(--space-3);
  align-items: center;
}
.hbar .progress {
  grid-column: 1 / -1;
}
.hbar-name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  min-width: 0;
}

.stacked {
  display: flex;
  height: 12px;
  border-radius: var(--radius-full);
  overflow: hidden;
  gap: 2px;
  background: var(--heat-empty);
}
.stacked span {
  height: 100%;
  background: var(--c);
  width: var(--w);
  transform-origin: left;
  animation: grow-x var(--dur-slow) var(--ease-out) both;
}

/* ---------------- Empty state ---------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-secondary);
}
.empty-compact {
  padding: var(--space-5) var(--space-3);
}
.empty-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  color: var(--text-tertiary);
  background:
    radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 1.5px) 0 0 / 6px 6px,
    var(--surface-2);
}
.empty-mark svg {
  width: 20px;
  height: 20px;
}
.empty h3 {
  font-size: var(--text-base);
  color: var(--text-primary);
  font-weight: 500;
}
.empty p {
  font-size: var(--text-sm);
  max-width: 340px;
}

/* ---------------- Insights / Next move ---------------- */
.insight {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.insight:last-child {
  border-bottom: 0;
}
.insight-marker {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  flex: none;
  display: grid;
  place-items: center;
  margin-top: 1px;
  background: var(--surface-hover);
  color: var(--text-secondary);
}
.insight-marker svg {
  width: 14px;
  height: 14px;
}
.insight[data-tone='positive'] .insight-marker {
  background: var(--accent-soft);
  color: var(--accent);
}
.insight[data-tone='warning'] .insight-marker {
  background: var(--warning-soft);
  color: var(--warning);
}
.insight[data-tone='critical'] .insight-marker {
  background: var(--danger-soft);
  color: var(--danger);
}
.insight[data-tone='info'] .insight-marker {
  background: var(--accent-2-soft);
  color: var(--accent-2);
}
.insight-text {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-primary);
}
.insight-text b {
  font-weight: 600;
}
.insight-action {
  margin-top: 6px;
}

.next-move {
  counter-reset: move;
}
.next-move .move {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.next-move .move:last-child {
  border-bottom: 0;
}
.next-move .move::before {
  counter-increment: move;
  content: counter(move, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--accent);
}

/* ---------------- Month picker ---------------- */
.month-picker {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}
.month-picker .icon-btn {
  width: 36px;
  height: 36px;
}
.month-picker-label {
  min-width: 132px;
  text-align: center;
  font-size: var(--text-sm);
  font-weight: 500;
}
.month-picker-label small {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-weight: 400;
}

/* ---------------- Command palette ---------------- */
.palette-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
}
.palette-input svg {
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  flex: none;
}
.palette-input input {
  flex: 1;
  min-height: 48px;
  border: 0;
  background: none;
  font-size: 16px;
}
.palette-input input:focus {
  box-shadow: none;
}
.palette-results {
  margin-top: var(--space-3);
  min-height: 120px;
}
.palette-results [aria-selected='true'] {
  background: var(--surface-hover);
}
.palette-group {
  padding: var(--space-3) 0 var(--space-1);
}
.palette-results mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 2px;
}

/* ---------------- Quick add ---------------- */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.quick-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  min-height: 104px;
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.quick-option:hover {
  border-color: var(--accent-line);
  background: var(--surface-hover);
}
.quick-option svg {
  width: 22px;
  height: 22px;
  color: var(--c, var(--accent));
}
.quick-option strong {
  display: block;
  font-weight: 500;
  font-size: var(--text-sm);
}
.quick-option span {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ---------------- Skeleton / loading ---------------- */
.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}
.boot-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-tertiary);
}
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-hover) 50%, var(--surface) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.offline-banner {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--warning-soft);
  border: 1px solid color-mix(in oklab, var(--warning) 35%, transparent);
  color: var(--warning);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.table-wrap {
  overflow-x: auto;
  margin: 0 calc(var(--space-4) * -1);
  padding: 0 var(--space-4);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td:first-child,
.table th:first-child {
  padding-left: 0;
}
.table .r {
  text-align: right;
}

.menu {
  position: fixed;
  z-index: 260;
  min-width: 180px;
  padding: var(--space-1);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-pop);
  animation: fade-in var(--dur-fast);
}
.menu button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: left;
}
.menu button:hover,
.menu button:focus-visible {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.menu button svg {
  width: 16px;
  height: 16px;
}
.menu button[data-danger] {
  color: var(--danger);
}
