:root {
  --bg: #f7f2ea;
  --card: #fffdfa;
  --ink: #2c2016;
  --muted: #7a6c5c;
  --accent: #a8451e;
  --accent-dark: #7e3115;
  --border: #e6dbc9;
  --gray-bg: #e7e2d8;
  --gray-text: #8c8474;
  --radius: 10px;
  --ok: #3f9142;
  --ok-bg: #d9f0da;
  --ok-border: #a8d9b0;
  --no: #c23b2e;
  --no-bg: #f8d3ce;
  --no-border: #e3a99f;
  --maybe: #b8790f;
  --maybe-bg: #faedc3;
  --maybe-border: #e9cf8a;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior-y: contain;
}

input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

body { padding-bottom: 24px; }

header.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fdf7ee;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-icon svg { width: 16px; height: 16px; }

.brand-title {
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-weight: 800;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px 60px;
}

h1, h2, h3 { font-family: "Playfair Display", Georgia, serif; margin: 0 0 6px; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }

p.lead { color: var(--muted); font-size: 0.92rem; margin: 0 0 16px; line-height: 1.45; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(44, 32, 22, 0.04);
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 6px;
}
label:first-child { margin-top: 0; }

input[type="text"], input[type="datetime-local"], textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}

textarea { resize: vertical; min-height: 70px; }

.hint { font-size: 0.78rem; color: var(--gray-text); margin-top: 4px; }

.field-error {
  color: #b3301a;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 10px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
}

.btn-primary { background: var(--accent); color: #fdf7ee; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--gray-bg); color: var(--ink); }
.btn-secondary:active { background: #dcd6c8; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; }

.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

.icon-btn-round {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--gray-bg);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn-round svg { width: 17px; height: 17px; }

/* Share row */
.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-bg);
  border-radius: 8px;
  padding: 8px 8px 8px 12px;
}
.share-link {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--muted);
  font-family: ui-monospace, Consolas, monospace;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fdf7ee;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* Tabs */
.tabs {
  display: flex;
  position: sticky;
  top: 53px;
  z-index: 9;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  padding: 12px 4px;
  background: none;
  border: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  font-family: inherit;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Instruction box */
.instructions {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #fbede6;
  border: 1px solid #edd6ca;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--accent-dark);
}
.instructions svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* Name badge */
.name-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  margin-bottom: 14px;
}
.name-badge-label { font-size: 0.78rem; color: var(--muted); }
.name-badge select {
  border: none;
  background: var(--gray-bg);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  font-family: inherit;
}

/* Tool selector (participant status picker) */
.tool-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.tool-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--ink);
}
.tool-btn .dot { width: 14px; height: 14px; border-radius: 50%; }
.tool-btn[data-tool="yes"] .dot { background: var(--ok); }
.tool-btn[data-tool="no"] .dot { background: var(--no); }
.tool-btn[data-tool="maybe"] .dot { background: var(--maybe); }
.tool-btn.selected[data-tool="yes"] { border-color: var(--ok); background: var(--ok-bg); }
.tool-btn.selected[data-tool="no"] { border-color: var(--no); background: var(--no-bg); }
.tool-btn.selected[data-tool="maybe"] { border-color: var(--maybe); background: var(--maybe-bg); }

/* Calendar grid */
.calendar-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--card);
  max-height: 66vh;
  touch-action: pan-x pan-y;
}

.calendar-grid {
  display: grid;
  width: max-content;
}

.grid-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.hour-label {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--gray-bg);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 8px 2px;
  min-width: 40px;
}

.date-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--gray-bg);
  padding: 6px 10px;
  min-width: 84px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.date-label .dow { font-size: 0.7rem; font-weight: 600; color: var(--muted); }
.date-label.weekend .dow { color: var(--accent); }
.date-label .dnum { font-size: 0.92rem; font-weight: 800; }

.slot-cell {
  border-right: 1px solid var(--gray-bg);
  border-bottom: 1px solid var(--gray-bg);
  min-width: 40px;
  min-height: 38px;
  touch-action: none;
  background: transparent;
}

.slot-cell.empty { background: repeating-linear-gradient(135deg, transparent, transparent 5px, var(--bg) 5px, var(--bg) 6px); }

.slot-cell.candidate {
  background: #fff;
  cursor: pointer;
}

.slot-cell.editable.candidate {
  background: rgba(168, 69, 30, 0.16);
}
.slot-cell.editable.candidate:active { background: rgba(168, 69, 30, 0.3); }

.slot-cell.inactive { background: var(--gray-bg); opacity: 0.55; }

.slot-cell.status-yes { background: var(--ok-bg); }
.slot-cell.status-no { background: var(--no-bg); }
.slot-cell.status-maybe { background: var(--maybe-bg); }

.slot-cell.agg-red { background: var(--no-bg); }
.slot-cell.agg-yellow { background: var(--maybe-bg); }
.slot-cell.agg-green { background: var(--ok-bg); }
.slot-cell.agg-none { background: #fff; }

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 10px 2px 16px;
  font-size: 0.78rem;
  color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 12px; height: 12px; border-radius: 4px; }
.legend-dot.ok { background: var(--ok-bg); border: 1px solid var(--ok-border); }
.legend-dot.no { background: var(--no-bg); border: 1px solid var(--no-border); }
.legend-dot.maybe { background: var(--maybe-bg); border: 1px solid var(--maybe-border); }
.legend-dot.plain { background: #fff; border: 1px solid var(--border); }
.legend-dot.cand { background: rgba(168, 69, 30, 0.16); border: 1px solid var(--accent); }

/* Participant chips */
.participant-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.participant-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #fff;
  border: 1.5px solid var(--border);
}
.participant-chip.checked { border-color: var(--accent); background: #fbede6; }
.participant-chip input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0;
}
.participant-name { font-weight: 600; flex: 1; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot.seen { background: #e0b429; }
.status-dot.responded { background: var(--ok); }
.status-dot.none { background: var(--gray-bg); border: 1px solid var(--border); }
.status-text { font-size: 0.74rem; color: var(--muted); }

/* Sheet (bottom modal) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 10px 18px 24px;
  transform: translateY(110%);
  transition: transform 0.25s ease;
  z-index: 21;
  max-width: 720px;
  margin: 0 auto;
  max-height: 80vh;
  overflow-y: auto;
}
.sheet.show { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 6px auto 14px; }
.sheet h3 { margin-bottom: 12px; }

.cell-detail-list { display: flex; flex-direction: column; gap: 6px; }
.cell-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.9rem;
}
.cell-detail-row .status-word { margin-left: auto; font-weight: 700; font-size: 0.82rem; }
.cell-detail-row.st-yes .status-word { color: var(--ok); }
.cell-detail-row.st-no .status-word { color: var(--no); }
.cell-detail-row.st-maybe .status-word { color: var(--maybe); }
.cell-detail-row.st-none .status-word { color: var(--gray-text); }

.center-screen {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

@media (min-width: 480px) {
  .hour-label, .slot-cell { min-width: 46px; }
}
