:root {
  --bg: #f4efe6;
  --surface: #fffdf9;
  --text: #1d2420;
  --muted: #6b716d;
  --line: #e4ddd0;
  --brand: #1f6f5c;
  --brand-ink: #ffffff;
  --brand-soft: #dcebe5;
  --late: #b4412b;
  --late-soft: #f8e1da;
  --done: #3c7d4c;
  --shadow: 0 1px 2px rgba(29, 36, 32, 0.06), 0 2px 8px rgba(29, 36, 32, 0.05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --surface: #1d2321;
    --text: #e9ece9;
    --muted: #9aa29d;
    --line: #2d3532;
    --brand: #4fb393;
    --brand-ink: #0d1411;
    --brand-soft: #1f3a31;
    --late: #f08a70;
    --late-soft: #3b231d;
    --done: #7cc48c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.topbar-user form { margin: 0; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head .muted { margin: 0; }
.page-head .muted::first-letter { text-transform: uppercase; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card.narrow { max-width: 420px; margin: 24px auto; }
.card.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.big { font-size: 2.2rem; margin: 0; }

.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 600; }
.eyebrow { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.eyebrow a { color: var(--muted); text-decoration: none; }

/* Buttons and forms */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.button:disabled { opacity: 0.6; }
.big-button { width: 100%; min-height: 56px; font-size: 1.1rem; }
.link-button { background: none; border: 0; padding: 6px 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }
.link-button.danger, .danger { color: var(--late); }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
label.inline { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
input.short { width: 80px; }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.photo-pick { flex-direction: row; align-items: center; cursor: pointer; color: var(--brand); }
.photo-pick input { width: auto; min-height: 0; border: 0; padding: 0; background: none; font-size: 0.85rem; }
.photo-preview, .history-photo { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--brand-soft); }
.flash-error { background: var(--late-soft); color: var(--late); }
.flash .pin { font-size: 1.3rem; letter-spacing: 0.1em; }

/* Section headings */
.section-title { display: flex; align-items: center; gap: 8px; margin: 20px 0 8px; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.section-title.late { color: var(--late); }
.section-title.done { color: var(--done); }
.count { display: inline-flex; min-width: 24px; height: 24px; padding: 0 7px; align-items: center; justify-content: center; border-radius: 12px; background: var(--line); color: var(--text); font-size: 0.8rem; font-weight: 700; }

/* Task lists */
.task-list, .done-list, .project-list, .history-list, .people-list { list-style: none; margin: 0; padding: 0; }
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px 10px 10px;
}
.task-row.is-done { opacity: 0.6; }
.quick-done { margin: 0; }
.check {
  flex: none; display: block; width: 32px; height: 32px;
  border: 2px solid var(--brand); border-radius: 50%;
  background: transparent; cursor: pointer; padding: 0;
}
.check:hover, .check:focus-visible { background: var(--brand-soft); }
.check.checked { background: var(--done); border-color: var(--done); position: relative; width: 22px; height: 22px; }
.check.checked::after { content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.task-link { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; color: var(--text); text-decoration: none; padding: 4px 0; }
.task-title { font-weight: 600; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.85rem; color: var(--muted); }
.task-meta .late { color: var(--late); font-weight: 600; }
.task-meta .repeat { color: var(--brand); }

.done-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.done-list a { color: var(--text); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); font-size: 0.85rem; font-weight: 600; }
.chip.late { background: var(--late-soft); color: var(--late); }
.chip.done { background: var(--done); color: #fff; }
.chip.small { font-size: 0.75rem; padding: 2px 8px; }

.description { border-top: 1px solid var(--line); padding-top: 12px; margin-bottom: 14px; }
.description ul { margin: 0 0 8px; padding-left: 22px; }
.description li { margin-bottom: 4px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }
.gallery form { margin: 0; }

.done-form { border-top: 1px solid var(--line); padding-top: 14px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.admin-actions form { margin: 0; }

.history-list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.history-list li:last-child { border-bottom: 0; }
.history-list form { margin: 4px 0 0; }
.history-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.history-head a { font-weight: 600; color: var(--text); }
.note { margin: 6px 0; padding: 8px 10px; background: var(--bg); border-radius: 8px; }
.day-nav { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

.project-list { padding: 4px 16px; }
.project-list li { border-bottom: 1px solid var(--line); }
.project-list li:last-child { border-bottom: 0; }
.project-list a { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 0 14px calc(var(--depth, 0) * 18px); color: var(--text); text-decoration: none; font-weight: 600; }
.project-list li.archived a { color: var(--muted); }

.people-list .username { font-weight: 700; min-width: 120px; }
.people-list input, .people-list select { width: auto; flex: 1; min-width: 120px; }
.people-list form { margin: 0 0 6px; }
.field-inline { flex: 1 1 100%; }
.field-inline input { width: 100%; }

/* Bottom tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  position: relative; flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.tabbar a.active { color: var(--brand); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .badge {
  position: absolute; top: 0; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--late); color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center;
}

/* Avisos */
.event-card.is-off { opacity: 0.7; }
.event-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.event-head .switch { font-size: 1.05rem; }
.small-text { font-size: 0.85rem; font-weight: 400; }
.recipients { margin-bottom: 10px; }
.recipients legend { font-weight: 600; font-size: 0.9rem; padding: 0 4px; }
.short-select { width: auto; }
.template-box { margin-top: 10px; }
.template-box summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.template-box .grid-2 { margin: 10px 0; }
.template-text { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 0.85rem; margin: 6px 0 0; }
.event-actions { margin-top: 8px; }
code { font-size: 0.9em; }
