/* ============================================================
   El Diario del Capitán — sistema de diseño
   Cuaderno de bitácora digitalizado. Oscuro, cálido, con textura.
   ============================================================ */

:root {
  /* Paleta (brief) */
  --bg: #1C1A17;
  --surface: #252218;
  --surface-2: #2C281D;
  --border: #3D3830;
  --text: #E8DCC8;
  --text-dim: #8A7E6E;
  --amber: #C8922A;
  --amber-soft: #E8B84B;
  --done: #4A9B6F;
  --adapted: #C8922A;
  --missed: #4A3F35;

  /* Tipografía */
  --font-display: "Playfair Display", Georgia, serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Source Code Pro", ui-monospace, monospace;

  /* Espaciado / radios */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --maxw: 720px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Textura sutil de papel/bitácora */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background:
    radial-gradient(circle at 18% 12%, rgba(200, 146, 42, 0.05), transparent 42%),
    radial-gradient(circle at 85% 88%, rgba(200, 146, 42, 0.04), transparent 45%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
}

#app { position: relative; z-index: 1; }

button { font-family: inherit; color: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: inherit; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--amber-soft);
  outline-offset: 2px;
}

/* ---------- Layout base ---------- */
.shell {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px 18px 120px;
}

.scrim { color: var(--text-dim); }

/* ---------- Barra de sincronización (arriba) ---------- */
.syncbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 2px 14px;
}
.syncbar .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 6px;
  vertical-align: middle;
}
.syncbar.online .dot { background: var(--done); }
.syncbar.offline .dot { background: var(--missed); }
.syncbar.syncing .dot { background: var(--amber-soft); animation: pulse 1s infinite; }
.syncbar button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--text-dim);
  font-size: 12px;
}
.syncbar button:hover { color: var(--text); border-color: var(--amber); }

/* ---------- Header del día ---------- */
.day-header { margin-bottom: 22px; }
.day-header .top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.day-date {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(26px, 6vw, 38px);
  line-height: 1.1;
  letter-spacing: 0.2px;
  margin: 0;
}
.nav-btns { display: flex; gap: 8px; flex-shrink: 0; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--text-dim);
  transition: 0.15s;
}
.icon-btn:hover { color: var(--amber-soft); border-color: var(--amber); }
.icon-btn svg { width: 20px; height: 20px; }

/* Racha — el número más visible de la app */
.streak {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, rgba(200,146,42,0.14), rgba(200,146,42,0.06));
  border: 1px solid rgba(200, 146, 42, 0.35);
  border-radius: 999px;
}
.streak .flame { font-size: 20px; filter: saturate(1.2); }
.streak .count {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--amber-soft);
  font-variant-numeric: tabular-nums;
}
.streak .label { font-size: 13px; color: var(--text-dim); }
.streak.bump { animation: bump 0.5s ease; }

/* ---------- Intención ---------- */
.intention {
  margin: 22px 0;
  animation: fadeIn 0.6s ease;
}
.intention-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 2px;
  font-family: var(--font-display);
  font-size: clamp(17px, 3.6vw, 21px);
  font-weight: 500;
  color: var(--text);
}
.intention-input::placeholder { color: var(--text-dim); font-style: italic; opacity: 0.85; }
.intention-input:focus { outline: none; border-bottom-color: var(--amber); }
.intention-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* ---------- Franjas horarias ---------- */
.block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 14px;
  overflow: hidden;
}
.block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 14px 16px;
  text-align: left;
}
.block-head .ico { font-size: 16px; opacity: 0.9; }
.block-head .name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.4px;
  flex: 1;
}
.block-head .meta { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.block-head .chev { color: var(--text-dim); transition: transform 0.2s; }
.block.collapsed .chev { transform: rotate(-90deg); }
.block.collapsed .block-body { display: none; }
.block-body { padding: 0 12px 12px; }

/* ---------- Actividad ---------- */
.activity {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--r-md);
  position: relative;
  transition: background 0.15s;
}
.activity:hover { background: var(--surface-2); }

.status-btn {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  display: grid; place-items: center;
  font-size: 13px;
  margin-top: 1px;
  transition: 0.18s;
  color: var(--text-dim);
}
.status-btn.done { background: var(--done); border-color: var(--done); color: #0e1f16; }
.status-btn.adapted { background: var(--adapted); border-color: var(--adapted); color: #2a1c05; }
.status-btn.missed { background: var(--missed); border-color: #564a3d; color: var(--text-dim); }
.status-btn.pulse { animation: pulse-ring 0.45s ease; }

.activity-main { flex: 1; min-width: 0; }
.activity-name {
  background: none;
  border: none;
  width: 100%;
  font-size: 15px;
  padding: 2px 0;
  color: var(--text);
  transition: color 0.2s;
}
.activity-name:focus { outline: none; }
.activity.done .activity-name { color: var(--done); }
.activity.adapted .activity-name { color: var(--amber-soft); }
.activity.missed .activity-name { color: var(--text-dim); }
/* Nunca tachado (decisión del brief) */
.activity-name { text-decoration: none !important; }

.activity-note {
  display: block;
  width: 100%;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 3px;
  padding: 2px 0;
  resize: none;
  line-height: 1.4;
}
.activity-note::placeholder { color: var(--text-dim); opacity: 0.55; }
.activity-note:focus { outline: none; color: var(--text); }
.activity-note.hidden { display: none; }

.del-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  opacity: 0;
  font-size: 16px;
  padding: 2px 4px;
  transition: 0.15s;
}
.activity:hover .del-btn, .del-btn:focus { opacity: 0.6; }
.del-btn:hover { opacity: 1; color: #b5654d; }

/* Añadir actividad inline */
.add-activity {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-top: 2px;
}
.add-activity .plus { color: var(--text-dim); font-size: 18px; }
.add-input {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 1px dashed transparent;
  font-size: 14px;
  padding: 4px 0;
  color: var(--text);
}
.add-input::placeholder { color: var(--text-dim); opacity: 0.7; }
.add-input:focus { outline: none; border-bottom-color: var(--border); }

/* ---------- Puntuación del día ---------- */
.score {
  margin: 22px 0 8px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.score-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.score-frac { font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.score-frac .total { color: var(--text-dim); font-size: 16px; }
.score-bar {
  height: 6px;
  background: var(--missed);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 8px;
}
.score-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--amber), var(--amber-soft));
  border-radius: 999px;
  transition: width 0.5s ease;
}
.score-hint { font-size: 12.5px; color: var(--text-dim); }

/* ---------- Cierre del día ---------- */
.closing {
  margin-top: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  position: relative;
}
.closing h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  margin: 0 0 14px;
}
.closing-q { margin-bottom: 14px; }
.closing-q label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.closing-q input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font-size: 14px;
}
.closing-q input:focus { outline: none; border-color: var(--amber); }

.btn {
  background: var(--amber);
  color: #211705;
  border: none;
  border-radius: var(--r-md);
  padding: 11px 20px;
  font-weight: 600;
  font-size: 14px;
  transition: 0.15s;
}
.btn:hover { background: var(--amber-soft); }
.btn.ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn.ghost:hover { color: var(--text); border-color: var(--amber); }
.btn.block-w { width: 100%; }

.collapse-cta {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  border-radius: var(--r-md);
  padding: 12px;
  margin-top: 18px;
  font-size: 14px;
}
.collapse-cta:hover { color: var(--amber-soft); border-color: var(--amber); }

/* Día sellado */
.sealed-bg .closing { background: linear-gradient(180deg, var(--surface-2), var(--surface)); }

/* ---------- Sello de fecha (elemento firma) ---------- */
#overlay-root { position: relative; z-index: 50; }
.seal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 13, 11, 0.55);
  z-index: 100;
  animation: fadeIn 0.25s ease;
}
.seal-stamp {
  width: 180px; height: 180px;
  display: grid; place-items: center;
  text-align: center;
  border: 4px double var(--amber);
  border-radius: 50%;
  color: var(--amber-soft);
  font-family: var(--font-display);
  transform: scale(0.2) rotate(-18deg);
  opacity: 0;
  box-shadow: 0 0 0 6px rgba(200,146,42,0.08);
  animation: stamp 0.55s cubic-bezier(.2,1.4,.4,1) forwards;
}
.seal-stamp .seal-word { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; }
.seal-stamp .seal-date { font-size: 26px; font-weight: 700; margin: 4px 0; }
.seal-stamp .seal-sub { font-size: 11px; letter-spacing: 1px; color: var(--amber); opacity: 0.8; }

/* ---------- Toast / aviso suave ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--amber);
  color: var(--text);
  padding: 13px 18px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  font-size: 14px;
  width: min(440px, 92vw);
  line-height: 1.4;
  z-index: 120;
  display: flex;
  gap: 14px;
  align-items: center;
  animation: riseIn 0.3s ease;
}
.toast > span:first-child { flex: 1; min-width: 0; }
.toast button { background: none; border: none; color: var(--amber-soft); font-weight: 600; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
.toast .dismiss { color: var(--text-dim); }

/* ---------- Barra de navegación inferior ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(28, 26, 23, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.tab {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-dim);
  font-size: 10.5px;
  padding: 5px 14px;
  border-radius: var(--r-sm);
  transition: 0.15s;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--amber-soft); }
.tab:hover { color: var(--text); }

/* ---------- Vista semanal ---------- */
.week-grid { display: flex; flex-direction: column; gap: 10px; }
.week-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.week-day.today { border-color: var(--amber); }
.week-day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.week-day-name { font-weight: 600; font-size: 14px; }
.week-day-name .dow { color: var(--text-dim); font-weight: 400; font-size: 12px; margin-left: 6px; }
.week-day-score { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.week-day .mini-intention { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); margin: 4px 0; }
.week-day .mini-acts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.mini-act {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.mini-act.done { color: var(--done); border-color: rgba(74,155,111,0.4); }
.mini-act.adapted { color: var(--amber-soft); border-color: rgba(200,146,42,0.4); }
.week-day .open-day { background:none;border:none;color:var(--amber-soft);font-size:12px;margin-top:8px; }

/* ---------- Histórico (calendario) ---------- */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.cal-head h2 { font-family: var(--font-display); font-weight: 500; font-size: 22px; margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-dim); padding-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.cal-cell {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 13px;
  position: relative;
  color: var(--text);
}
.cal-cell.empty { background: transparent; border: none; }
.cal-cell.has-data { cursor: pointer; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--amber); }
.cal-cell.sealed::after {
  content: "•";
  position: absolute; bottom: 3px;
  color: var(--amber); font-size: 10px;
}
.cal-cell .streakdot {
  position: absolute; top: 4px; right: 5px;
  font-size: 8px;
}
.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 16px; font-size: 12px; color: var(--text-dim); }
.cal-legend .swatch { display:inline-block; width:12px;height:12px;border-radius:3px;margin-right:5px;vertical-align:middle;border:1px solid var(--border); }

/* ---------- Badges ---------- */
.badges { margin-top: 24px; }
.badges h3 { font-family: var(--font-display); font-weight: 500; font-size: 18px; margin: 0 0 12px; }
.badge-list { display: flex; flex-wrap: wrap; gap: 10px; }
.badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}
.badge.earned { border-color: rgba(200,146,42,0.5); }
.badge.locked { opacity: 0.4; }
.badge .b-ico { font-size: 16px; }
.badge .b-name { font-weight: 500; }

/* ---------- Plantilla semanal ---------- */
.tpl-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 12px; padding: 14px; }
.tpl-day h4 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.tpl-band { margin-bottom: 10px; }
.tpl-band .band-name { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 5px; }
.tpl-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 13px; margin: 0 5px 5px 0; }
.tpl-chip button { background: none; border: none; color: var(--text-dim); font-size: 14px; }
.tpl-chip button:hover { color: #b5654d; }
.tpl-add { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 9px; font-size: 13px; width: 150px; }
.tpl-add:focus { outline: none; border-color: var(--amber); }

/* ---------- Auth / Ajustes ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 16px;
}
.panel h2 { font-family: var(--font-display); font-weight: 500; margin: 0 0 6px; font-size: 22px; }
.panel p.sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 18px; line-height: 1.5; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.6px; }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px 12px;
  font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--amber); }
.auth-switch { background: none; border: none; color: var(--amber-soft); font-size: 13px; margin-top: 4px; }
.auth-msg { font-size: 13px; padding: 10px 12px; border-radius: var(--r-sm); margin-bottom: 14px; }
.auth-msg.err { background: rgba(181,101,77,0.15); color: #d99178; border: 1px solid rgba(181,101,77,0.4); }
.auth-msg.ok { background: rgba(74,155,111,0.13); color: #7fc7a0; border: 1px solid rgba(74,155,111,0.4); }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.account-row .email { font-family: var(--font-mono); font-size: 13px; color: var(--text); }

.app-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  text-align: center;
  margin: 10px 0 4px;
}
.app-tagline { text-align: center; color: var(--text-dim); font-style: italic; margin-bottom: 26px; font-size: 14px; }

/* ---------- Vista de solo lectura (histórico) ---------- */
.readonly-banner {
  background: rgba(200,146,42,0.1);
  border: 1px solid rgba(200,146,42,0.35);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--amber-soft);
  margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 20px; font-size: 14px; line-height: 1.6; }

/* ---------- Animaciones ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes riseIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes bump { 0%,100% { transform: scale(1); } 35% { transform: scale(1.12); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 rgba(200,146,42,0.5); } 100% { box-shadow: 0 0 0 12px rgba(200,146,42,0); } }
@keyframes stamp {
  0% { transform: scale(0.2) rotate(-18deg); opacity: 0; }
  60% { transform: scale(1.08) rotate(-9deg); opacity: 1; }
  100% { transform: scale(1) rotate(-7deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
