:root {
  --sky: #2596f0;
  --sky-dark: #1c78c4;
  --sunset: #ff8a3d;
  --sunset-dark: #f06a1f;
  --palm: #1fa77a;
  --palm-light: #e4f7f0;
  --sand: #fff8ef;
  --ink: #1f2937;
  --ink-light: #5b6472;
  --line: #e7e2d8;
  --card-bg: #ffffff;
  --danger: #e0554f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(31, 41, 55, 0.08);
  --shadow-lg: 0 20px 45px rgba(31, 41, 55, 0.18);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #eaf6ff 0%, var(--sand) 320px);
  color: var(--ink);
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(120deg, var(--sky) 0%, #4fb8e8 55%, var(--palm) 130%);
  color: #fff;
  padding: 18px 24px 0;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-emoji { font-size: 2.4rem; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15)); }
.brand-text h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; }
.brand-sub { margin: 2px 0 0; font-size: 0.85rem; opacity: 0.92; }
.header-actions { display: flex; gap: 8px; }

.main-nav {
  max-width: 1200px;
  margin: 14px auto 0;
  display: flex;
  gap: 6px;
}
.nav-btn {
  background: rgba(255,255,255,0.16);
  border: none;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px 12px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.85;
  transition: background 0.15s, opacity 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.28); opacity: 1; }
.nav-btn.active { background: var(--sand); color: var(--ink); opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--sunset); color: #fff; box-shadow: 0 4px 12px rgba(255,138,61,0.35); }
.btn-primary:hover { background: var(--sunset-dark); }
.btn-ghost { background: rgba(255,255,255,0.2); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,0.32); }
.btn-secondary { background: #eef1f5; color: var(--ink); }
.btn-secondary:hover { background: #e2e6ec; }
.btn-danger { background: #fde8e7; color: var(--danger); }
.btn-danger:hover { background: #fbd7d5; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Main / Views ---------- */
.app-main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.view-header { margin-bottom: 18px; }
.view-header h2 { margin: 0 0 4px; font-size: 1.5rem; }
.view-subtitle { margin: 0 0 12px; color: var(--ink-light); font-size: 0.92rem; }
.view-header-buttons { display: flex; gap: 10px; }

/* ---------- Day tabs ---------- */
.day-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.day-tab {
  flex: 0 0 auto;
  background: var(--card-bg);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  text-align: center;
  font-weight: 600;
  color: var(--ink-light);
  position: relative;
  min-width: 108px;
}
.day-tab .dow { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.day-tab .dnum { display: block; font-size: 1.15rem; color: var(--ink); }
.day-tab:hover { border-color: var(--sky); }
.day-tab.active { border-color: var(--sunset); background: #fff4ea; color: var(--sunset-dark); }
.day-tab.active .dnum { color: var(--sunset-dark); }
.day-tab .dot {
  position: absolute; top: 6px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--palm);
}

/* ---------- Timeline ---------- */
.timeline-wrapper {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow-x: auto;
}
.timeline-grid {
  display: grid;
  grid-template-columns: 70px 1fr;
  grid-auto-rows: 42px;
  position: relative;
  background-image: repeating-linear-gradient(
    to bottom,
    var(--line) 0,
    var(--line) 1px,
    transparent 1px,
    transparent 42px
  );
  background-position: 70px 0;
  min-width: 480px;
}
.hour-label {
  grid-column: 1;
  font-size: 0.75rem;
  color: var(--ink-light);
  padding-right: 10px;
  text-align: right;
  transform: translateY(-8px);
  user-select: none;
}
.hour-cell {
  grid-column: 2;
}
.hour-cell.clickable { cursor: pointer; border-radius: 6px; }
.hour-cell.clickable:hover { background: var(--palm-light); }

.activity-block {
  grid-column: 2;
  margin: 2px 6px 2px 10px;
  border-radius: 10px;
  padding: 6px 10px;
  background: linear-gradient(135deg, #ffe4cc, #ffd2b0);
  border: 1px solid #ffb87a;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.activity-block:nth-child(6n+2) { background: linear-gradient(135deg, #cdeee1, #b7e6d4); border-color: #7fd2af; }
.activity-block:nth-child(6n+3) { background: linear-gradient(135deg, #cfe7fb, #b3d9f7); border-color: #7cb8ec; }
.activity-block:nth-child(6n+4) { background: linear-gradient(135deg, #f3d7fb, #e7b9f5); border-color: #cd8ce8; }
.activity-block:nth-child(6n+5) { background: linear-gradient(135deg, #fff0b8, #ffe58a); border-color: #f0cd4c; }
.activity-block:nth-child(6n+0) { background: linear-gradient(135deg, #ffd6d6, #ffb8b8); border-color: #f19292; }

.activity-block.clickable { cursor: pointer; }
.activity-block.clickable:hover { filter: brightness(0.97); box-shadow: var(--shadow); }
.activity-title { font-weight: 700; font-size: 0.85rem; line-height: 1.15; }
.activity-time { font-size: 0.72rem; color: var(--ink-light); font-weight: 600; }
.activity-notes { font-size: 0.72rem; color: var(--ink-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline-empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--ink-light);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 24, 32, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h3 { margin-top: 0; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.form-group input[type=text],
.form-group input[type=number],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  background: #fff;
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.form-hint { font-size: 0.78rem; color: var(--ink-light); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 8px; min-height: 1em; }

.emoji-select-row { display: flex; gap: 8px; flex-wrap: wrap; }
.emoji-choice {
  width: 40px; height: 40px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
}
.emoji-choice.selected { border-color: var(--sunset); background: #fff4ea; }

.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.checkbox-row label { font-weight: 500; margin: 0; }

/* ---------- Ficha de detalle de actividad ---------- */
.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
}
.detail-emoji {
  font-size: 2rem;
  background: var(--palm-light);
  border-radius: 12px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.detail-title { margin: 0; font-size: 1.2rem; line-height: 1.25; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.detail-item {
  background: var(--sand);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.detail-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-value { font-size: 0.95rem; font-weight: 600; }

.detail-block { margin-bottom: 16px; }
.detail-block .detail-label { display: block; margin-bottom: 7px; }

.detail-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-chip {
  background: #eaf6ff;
  border: 1px solid #bfe0f7;
  color: var(--sky-dark);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.78rem;
  font-weight: 600;
}

.detail-notes {
  margin: 0;
  background: var(--sand);
  border-left: 3px solid var(--sunset);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 11px 13px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-notes.vacio { color: var(--ink-light); font-style: italic; border-left-color: var(--line); }

/* ---------- Participants table ---------- */
.participants-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.86rem; }
.participants-table th, .participants-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.participants-table th { color: var(--ink-light); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.participants-table td.num { text-align: right; }
.participants-table input[type=number] { width: 80px; padding: 5px 8px; text-align: right; border: 1px solid var(--line); border-radius: 6px; }
.participants-table tr.excluded { opacity: 0.45; }
.pill { padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.pill.ok { background: var(--palm-light); color: var(--palm); }
.pill.pending { background: #fff1e0; color: var(--sunset-dark); }

.total-line { display: flex; justify-content: space-between; font-weight: 700; margin-top: 8px; padding-top: 8px; border-top: 2px solid var(--line); }

/* ---------- Valores ---------- */
.summary-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.summary-tile {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.summary-tile .label { font-size: 0.78rem; color: var(--ink-light); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.summary-tile .value { font-size: 1.6rem; font-weight: 800; margin-top: 4px; }
.summary-tile.total .value { color: var(--sky-dark); }
.summary-tile.paid .value { color: var(--palm); }
.summary-tile.pending .value { color: var(--sunset-dark); }

.people-summary {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 22px;
  overflow-x: auto;
}
.people-summary h3 { margin: 0 0 10px; font-size: 1rem; }

.expense-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.expense-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.expense-card h3 { margin: 0; font-size: 1.05rem; }
.expense-card .exp-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--ink-light); }
.expense-card .exp-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  width: fit-content;
}
.exp-status.done { background: var(--palm-light); color: var(--palm); }
.exp-status.pending { background: #fff1e0; color: var(--sunset-dark); }
.expense-card .exp-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-light);
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty-state .emoji { font-size: 2.4rem; display: block; margin-bottom: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  font-size: 0.88rem;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, 8px); }

/* ---------- Lock screen ---------- */
#appRoot.locked { display: none; }
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--sky) 0%, #4fb8e8 55%, var(--palm) 130%);
}
.lock-screen.hidden { display: none; }
.lock-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 30px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.lock-emoji { font-size: 2.6rem; margin-bottom: 6px; }
.lock-title { font-size: 1.15rem; margin: 0 0 6px; line-height: 1.3; }
.lock-subtitle { font-size: 0.85rem; color: var(--ink-light); margin: 0 0 18px; }
.lock-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  text-align: center;
  letter-spacing: 0.15em;
  margin-bottom: 14px;
}
.lock-input:focus { outline: none; border-color: var(--sky); }
.lock-card .form-error { min-height: 1.2em; margin-top: 10px; }
.lock-card.shake { animation: shake 0.4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .brand-text h1 { font-size: 1.1rem; }
  .app-main { padding: 14px; }
  .nav-btn { flex: 1; padding: 12px 8px; font-size: 0.85rem; }
  .form-row { flex-direction: column; gap: 0; }
  .modal { padding: 16px; max-height: 94vh; }
  .timeline-wrapper { padding: 10px; }
  .timeline-grid { grid-template-columns: 52px 1fr; min-width: 0; grid-auto-rows: 46px; }
  .hour-label { font-size: 0.68rem; padding-right: 6px; }
  .activity-title { font-size: 0.8rem; }
  .activity-time { font-size: 0.68rem; }
  .activity-notes { white-space: normal; }
  .day-tab { min-width: 88px; padding: 8px 12px; }
  .emoji-choice { width: 44px; height: 44px; }
  .btn { min-height: 40px; }
  .participants-table th, .participants-table td { padding: 8px 4px; font-size: 0.8rem; }
  .participants-table input[type=number] { width: 64px; }
  .summary-panel { grid-template-columns: repeat(2, 1fr); }
  .expense-cards { grid-template-columns: 1fr; }
  .view-header-buttons { flex-wrap: wrap; }
}

@media (max-width: 400px) {
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; justify-content: center; }
  .summary-panel { grid-template-columns: 1fr; }
}
