:root {
  /* Dark mode fijo (modo tenue de design-system.md) — la app es de uso nocturno. */
  --bg: #14191C;
  --surface: #1C2327;
  --surface-2: #232B30;
  --text: #D7DEE1;
  --text-soft: #94A2A9;
  --border: #2C363B;
  --primary: #7FA9BC;
  --primary-strong: #9BC0D0;
  --accent-noche: #8E9BC0;
  --accent-siesta: #D9A877;
  --ok: #7FC29A;
  --warn: #E0A06E;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 999px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .28);
  --gap: 14px;
  --pad-card: 16px;

  --font-display: 'Nunito', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* nada debe poder empujar la página entera de costado en mobile */
  max-width: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .num {
  font-family: var(--font-display);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select, button {
  font-size: 16px;
}

[hidden] {
  display: none !important;
}

.container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: var(--gap);
}

/* ---------- Auth ---------- */
#auth-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 20px;
}

.auth-card h1 {
  font-size: 24px;
  margin: 0 0 4px;
  text-align: center;
}

.auth-card .subtitle {
  color: var(--text-soft);
  text-align: center;
  font-size: 14px;
  margin: 0 0 20px;
}

.field {
  margin-bottom: var(--gap);
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.btn-primary {
  width: 100%;
  min-height: 44px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background .15s ease;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.btn-primary:disabled {
  opacity: .6;
  cursor: default;
}

.error-msg {
  color: var(--warn);
  font-size: 14px;
  margin: 10px 0 0;
  text-align: center;
}

/* ---------- App shell ---------- */
#app-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header-row {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px var(--gap);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  color: var(--text-soft);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--gap) 12px;
}

.tab {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-soft);
  font-weight: 600;
  font-size: 15px;
}

.tab.is-active {
  background: var(--primary);
  color: #fff;
}

main {
  flex: 1;
  min-width: 0; /* si no, un flex item no se achica por debajo del contenido (ej. la tabla ancha) y empuja todo el layout */
}

/* ---------- Tarjeta de sección (Fase 3) ---------- */
.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad-card);
  margin-bottom: var(--gap);
}

.section-card h2 {
  font-size: 18px;
  margin: 0 0 10px;
}

/* ---------- Estado de guardado ---------- */
.save-indicator {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-soft);
}

.save-indicator.is-ok { color: var(--ok); }
.save-indicator.is-error { color: var(--warn); }

.btn-volver-historial {
  display: block;
  background: none;
  border: none;
  padding: 0 0 10px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

.day-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.day-header-row #fecha-input {
  flex: 1;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.campo-hora {
  margin-bottom: var(--gap);
}

.campo-hora:last-child {
  margin-bottom: 0;
}

.campo-hora label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.campo-hora-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.campo-hora-row input[type="time"] {
  flex: 1;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.readonly-calc {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--text-soft);
}

.readonly-calc strong {
  color: var(--text);
  font-family: var(--font-display);
}

/* ---------- Botón "ahora" ---------- */
.btn-ahora {
  min-height: 36px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ---------- Campo de texto simple ---------- */
.campo-texto {
  margin-bottom: var(--gap);
}

.campo-texto:last-child {
  margin-bottom: 0;
}

.campo-texto label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.campo-texto textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
}

/* ---------- Switch ---------- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.switch-row:last-child {
  margin-bottom: 0;
}

.switch-row .switch-label {
  font-size: 15px;
  color: var(--text);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  transition: background .15s ease;
  cursor: pointer;
}

.switch-track::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--text-soft);
  border-radius: 50%;
  transition: transform .15s ease, background .15s ease;
}

.switch input:checked + .switch-track {
  background: var(--primary);
  border-color: var(--primary);
}

.switch input:checked + .switch-track::before {
  transform: translateX(18px);
  background: #fff;
}

/* ---------- Comidas: "qué + hora" (apilado: texto arriba, hora+ahora abajo) ---------- */
.que-hora-row {
  margin-bottom: var(--gap);
}

.que-hora-row:last-child {
  margin-bottom: 0;
}

.que-hora-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.que-hora-top .que-label {
  width: 72px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-soft);
}

.que-hora-top input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.que-hora-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.que-hora-bottom input[type="time"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- Bloque colapsable de sección ---------- */
.section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 10px;
  text-align: left;
}

.section-toggle h2 {
  margin: 0;
}

.section-toggle .section-resumen {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
}

.section-body[hidden] {
  display: none;
}

/* ---------- Lista de despertares ---------- */
.despertares-lista {
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.despertar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.despertar-row input[type="time"] {
  width: 90px;
  min-height: 40px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.despertar-row .despertar-dur {
  font-size: 13px;
  color: var(--text-soft);
  flex: 1;
  text-align: center;
}

.btn-quitar {
  min-height: 32px;
  min-width: 32px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--warn);
  font-size: 16px;
  line-height: 1;
}

.btn-agregar {
  min-height: 40px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  width: 100%;
}

/* ---------- Total calculado + override ---------- */
.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.total-row .total-label {
  font-size: 14px;
  color: var(--text-soft);
}

.total-row .total-valor {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.total-row .btn-editar-total {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
}

.total-override {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.total-override input {
  width: 90px;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.total-override .total-override-hint {
  font-size: 12px;
  color: var(--text-soft);
}

/* ---------- Historial / Dashboard ---------- */
.filtros-row select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.filtros-rango {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--gap);
  color: var(--text-soft);
}

.filtros-rango input[type="date"] {
  flex: 1;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.resumen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.resumen-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.resumen-num {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.resumen-label {
  font-size: 12px;
  color: var(--text-soft);
}

.dia-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad-card);
  margin-bottom: 10px;
  cursor: pointer;
}

.dia-card:active {
  background: var(--surface-2);
}

.dia-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dia-card-fecha {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-transform: capitalize;
}

.dia-card-metricas {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 14px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.dia-card-metricas strong {
  color: var(--text);
  font-weight: 700;
}

.dia-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-soft);
}

.chip.is-lleno {
  background: var(--primary);
  color: #fff;
}

.historial-vacio {
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
  padding: 24px 0;
}

.dia-card-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-eliminar-card {
  min-height: 28px;
  min-width: 28px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--warn);
  font-size: 14px;
  line-height: 1;
}

/* ---------- Botón eliminar día (formulario) ---------- */
.btn-eliminar-dia {
  width: 100%;
  min-height: 44px;
  margin-top: var(--gap);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--warn);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Toggle Tarjetas / Tabla ---------- */
.vista-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}

.vista-toggle-btn {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
}

.vista-toggle-btn.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---------- Vista de tabla del historial ---------- */
.tabla-scroll {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.tabla-historial {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
  font-size: 14px;
}

.tabla-historial th,
.tabla-historial td {
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.tabla-historial th {
  color: var(--text-soft);
  font-weight: 600;
  font-size: 12px;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.tabla-historial tbody tr {
  cursor: pointer;
}

.tabla-historial tbody tr:hover {
  background: var(--surface-2);
}

.tabla-historial td:last-child,
.tabla-historial th:last-child {
  text-align: center;
}
