:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #f6821f;      /* naranja Cloudflare */
  --accent-hover: #ea6c0a;
  --accent-soft: #fff3e6;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  /* Tipografía fluida: escala suavemente entre móvil y pantallas grandes */
  font-size: clamp(14px, 0.4vw + 12.5px, 16px);
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.25rem; }
p { margin: 0.25rem 0 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--red); font-size: 0.9rem; }

.view[hidden] { display: none; }

/* ---------- Botones ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.5rem 0.95rem;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; border-color: var(--red); }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; }
.btn.ghost:hover { background: #f3f4f6; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Login ---------- */
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.08);
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
label { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
input[type="password"], input[type="text"], input[type="number"] {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
}
input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.15rem; }
.brand.inline { font-size: 1rem; }
.logo-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }

.content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}
.panel > p { margin-bottom: 1rem; }

/* ---------- Rejillas ---------- */
.grid { display: grid; gap: 0.75rem; }
.years-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* Meses: cuadrícula uniforme que crece con la pantalla
   (2 en móvil → 3 → 4 → 6 en escritorio, quedando en 2 filas). */
.months-grid { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 600px) { .months-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .months-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1200px) { .months-grid { grid-template-columns: repeat(6, 1fr); } }
.months-grid .box { aspect-ratio: 4 / 3; }

.box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
  font: inherit;
  color: inherit;
  min-height: 74px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
}
.box:hover { border-color: var(--accent); }
.box:active { transform: scale(0.99); }
.box .box-title { font-weight: 600; font-size: 1.02rem; }
.box .box-sub { font-size: 0.8rem; color: var(--muted); }
.box .box-title,
.box .box-sub,
.box .pct {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.box.empty { opacity: 0.72; }
.box .pct { font-weight: 600; font-size: 0.92rem; }
.pct.up { color: var(--green); }
.pct.down { color: var(--red); }
.pct.flat { color: var(--muted); }

/* ---------- Días ---------- */
.days-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.6rem;
}
@media (min-width: 1600px) {
  .days-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.75rem; }
}
.day-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0.6rem 0.5rem;
  min-height: 84px;
  cursor: pointer;
  font: inherit;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  transition: border-color 0.15s;
}
.day-box:hover { border-color: var(--accent); }
.day-box.empty { opacity: 0.72; }
.day-box.void { opacity: 0.38; } /* posterior al último día con datos: no se rellena */
.day-box .dnum { font-weight: 600; font-size: 0.76rem; color: var(--muted); }
.day-box .dval {
  font-weight: 600;
  font-size: 0.86rem;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-box .dval.prom { font-weight: 500; color: var(--muted); }
.day-box .dpct { font-size: 0.74rem; font-weight: 600; }
.dpct.up { color: var(--green); }
.dpct.down { color: var(--red); }
.dpct.flat { color: var(--muted); }

/* ---------- Modal ---------- */
.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 88vh;
  max-height: 88dvh; /* navegadores modernos: alto real del viewport móvil */
  box-shadow: 0 10px 40px rgba(17, 24, 39, 0.18);
}
.modal::backdrop { background: rgba(17, 24, 39, 0.35); }
.modal-inner { padding: 1.25rem 1.4rem 1.4rem; max-height: inherit; overflow-y: auto; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.modal-head h3 { flex: 0 1 auto; }
.pill {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  flex: 1 1 auto;
  text-align: center;
}
.pill.up { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.pill.down { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.pill.flat { color: var(--muted); }

.modal-summary {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
}
.autofill-note {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: #92400e;
  background: var(--accent-soft);
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
}

.modal-summary > div { display: flex; flex-direction: column; gap: 0.1rem; }
.modal-summary strong { font-size: 1.05rem; }
.modal-summary strong.up { color: var(--green); }
.modal-summary strong.down { color: var(--red); }
.modal-summary strong.flat { color: var(--muted); }
.modal-summary .muted { font-size: 0.75rem; }

.table-wrap { overflow-x: auto; }
.positions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.positions-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.positions-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.positions-table td.num { text-align: right; white-space: nowrap; }
.positions-table input {
  padding: 0.35rem 0.5rem;
  font-size: 0.88rem;
}
.positions-table input.n { text-align: right; }
.positions-table td.pctcell { text-align: right; font-weight: 600; white-space: nowrap; }
.row-del { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.row-del:hover { color: var(--red); }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
}
.modal-actions .spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.35);
  z-index: 50;
}

/* ---------- Adaptación a pantallas ---------- */
@media (max-width: 720px) {
  .topbar { padding: 0.7rem 0.9rem; }
  .content { padding: 1rem 0.9rem 3rem; }
  .modal-inner { padding: 1rem 0.9rem 1.1rem; }
  .modal-actions { flex-wrap: wrap; }
  .modal-summary { gap: 0.9rem; }
  .btn { padding: 0.55rem 0.9rem; } /* objetivos táctiles cómodos */
  h2 { font-size: 1.15rem; }
}

/* Pantallas muy estrechas: 3 columnas fijas de días, tipo calendario */
@media (max-width: 400px) {
  .days-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Monitores grandes: más espacio y contenido más ancho */
@media (min-width: 1600px) {
  :root { --radius: 10px; }
  .content { max-width: 1440px; padding: 2rem 2rem 5rem; }
}

/* Móvil horizontal (poco alto): el modal se recorta y hace scroll */
@media (max-height: 480px) {
  .modal { max-height: 92vh; max-height: 92dvh; }
  .modal-inner { padding: 0.8rem 1rem; }
}

/* Accesibilidad: menos movimiento si el usuario lo pide */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
