:root {
  --bg: #f8f5f0;
  --panel: #ffffff;
  --panel-soft: #fff8ee;
  --text: #2c2930;
  --muted: #706b77;
  --line: #e8e0d8;
  --brand: #d93445;
  --brand-dark: #a51f31;
  --green: #2e9450;
  --yellow: #f6d46b;
  --purple: #463151;
  --shadow: 0 8px 28px rgba(32, 20, 12, 0.10);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #fff 0, var(--bg) 180px);
  color: var(--text);
}
button, input, select, textarea {
  font: inherit;
}
button, select, input[type="checkbox"] { cursor: pointer; }
a { color: inherit; }

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px;
  padding-bottom: 90px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -14px -14px 12px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar.compact-nav { box-shadow: 0 4px 18px rgba(32, 20, 12, 0.06); }
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.logo h1 { font-size: 1.24rem; line-height: 1.1; margin: 0; color: var(--brand); }
.logo p { margin: 3px 0 0; color: var(--muted); font-size: .9rem; }
.date-picker { display: flex; gap: 8px; align-items: center; }
.date-picker label { font-size: .78rem; color: var(--muted); }
.date-picker select { min-width: 128px; }

.nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 0;
}
.nav button,
.pill,
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 11px;
  min-height: 40px;
  box-shadow: none;
}
.nav button { font-size: .82rem; padding: 7px 4px; min-height: 34px; }
.nav button.active,
.pill.active,
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.danger { border-color: #f0b5bb; color: #9b1022; background: #fff4f5; }
.btn.soft { background: var(--panel-soft); }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: .87rem; }
.btn.full { width: 100%; }

.hero {
  background: linear-gradient(135deg, #fff 0%, #fff3f3 55%, #fff 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.hero h2 { margin: 0 0 8px; font-size: 1.35rem; }
.hero p { margin: 0; color: var(--muted); }

.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr; }

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.panel h2, .panel h3, .card h3 { margin-top: 0; }
.muted { color: var(--muted); }
.warning {
  background: #fff9e8;
  border: 1px solid #f0dc93;
  color: #5c4410;
  border-radius: 14px;
  padding: 10px 12px;
}
.empty { padding: 18px; color: var(--muted); text-align: center; }

.toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar input[type="search"], select, input[type="time"], input[type="number"], input[type="text"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 78px; resize: vertical; }
.check-row { display: flex; align-items: center; gap: 9px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f2f0f3;
  color: #4d4852;
  font-size: .82rem;
}
.chip.green { background: #e8f5ec; color: #1f6f39; }
.chip.red { background: #ffe9ec; color: #9b1022; }
.chip.gold { background: #fff3c2; color: #665011; }
.chip.purple { background: #efe7f3; color: var(--purple); }

.card {
  display: grid;
  gap: 10px;
}
.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.card h3 { margin: 0; font-size: 1.08rem; }
.card.clickable, .clickable-row { cursor: pointer; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.card.clickable:hover, .card.clickable:focus-visible, .clickable-row:hover, .clickable-row:focus-visible {
  border-color: #d7bfc8;
  transform: translateY(-1px);
}
.card.clickable:focus-visible, .clickable-row:focus-visible { outline: 3px solid rgba(217, 52, 69, .24); outline-offset: 2px; }
.address { color: var(--muted); font-size: .95rem; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tap-hint {
  color: var(--muted);
  font-size: .8rem;
  margin-top: -2px;
}
.visit-note-preview {
  background: #f7fbff;
  border-left: 5px solid #b9d4ef;
  padding: 8px 10px;
  border-radius: 10px;
  color: #334b63;
}
.note-highlight {
  background: #fff7d9;
  border-left: 5px solid var(--yellow);
  padding: 8px 10px;
  border-radius: 10px;
}
.score {
  min-width: 56px;
  text-align: center;
  border-radius: 14px;
  background: #f4edf7;
  color: var(--purple);
  padding: 6px 8px;
  font-weight: 700;
}
.card.visited { opacity: .72; }
.card.visited h3 { text-decoration: line-through; text-decoration-thickness: 2px; }
.card.unplanned, .manage-row.unplanned { opacity: .62; background: #fbfaf8; }
.muted-chip { background: #eee9e3; color: #665d54; }

.manage-list { display: grid; gap: 8px; }
.manage-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.manage-main { min-width: 0; }
.manage-main strong { display: block; overflow-wrap: anywhere; }
.compact-field {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}
.compact-field input[type="number"] {
  width: 58px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
}


.day-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 12px;
}
.day-strip button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 9px 4px;
  text-align: center;
}
.day-strip button.active { background: var(--purple); color: white; border-color: var(--purple); }
.day-strip button.today-date {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(217, 52, 69, .12);
}
.day-strip button.today-date:not(.active) {
  background: #fff7f8;
  color: var(--text);
}
.day-strip small { display: block; opacity: .75; }

.plan-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.plan-time { color: var(--brand-dark); font-weight: 800; }
.reason-list { margin: 6px 0 0; padding-left: 20px; color: var(--muted); }
.reason-list li { margin: 3px 0; }

.settings-grid { display: grid; gap: 12px; }
.setting-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.setting-row:first-child { border-top: 0; }
.availability-row, .session-row, .event-row, .note-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.session-row { grid-template-columns: 1fr 82px 82px; align-items: center; }
.note-row { grid-template-columns: 1fr auto auto; align-items: center; }
.event-row { grid-template-columns: 1fr 82px 82px auto; align-items: start; }

.village-page { gap: 12px; }
.detail-hero,
.detail-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
}
.detail-hero {
  display: grid;
  gap: 12px;
  background: linear-gradient(135deg, #fff 0%, #fff8ee 100%);
}
.detail-section h3 { margin: 0 0 10px; }
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.status-card,
.schedule-row,
.special-detail,
.plain-note {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: #fff;
}
.status-card {
  display: grid;
  gap: 3px;
  margin-bottom: 8px;
}
.status-card.open { border-color: #b9dfc5; background: #f3fbf5; }
.status-card.closed { background: #fbfaf8; }
.schedule-list { display: grid; gap: 8px; }
.schedule-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.special-detail { display: grid; gap: 4px; margin-bottom: 8px; }

.quick-ratings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.rating-block {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.72);
  padding: 10px;
}
.rating-title {
  font-weight: 800;
  margin-bottom: 2px;
}
.tiny { font-size: .8rem; }
.compact-stars { margin-bottom: 0; }
.field-label {
  display: block;
  color: var(--muted);
  font-size: .86rem;
  margin: 8px 0 5px;
}
.star-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
}
.star-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  min-width: 42px;
  min-height: 40px;
  font-size: 1.35rem;
  line-height: 1;
  color: #b5a46b;
}
.star-btn.active {
  background: #fff3c2;
  border-color: #e3c45e;
  color: #8a6e00;
}
.save-status { min-height: 1.2em; }
.visited-detail { opacity: .92; }

.editor-dialog {
  width: min(740px, calc(100vw - 20px));
  border: 0;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .34);
}
.editor-dialog::backdrop { background: rgba(30, 20, 36, .58); }
.dialog-shell { margin: 0; }
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 14px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-body { padding: 14px; display: grid; gap: 14px; max-height: min(78vh, 900px); overflow: auto; }
.dialog-actions {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin: 0 0 4px; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  margin: 0;
}
legend { padding: 0 6px; color: var(--purple); font-weight: 700; }

.footer-note { color: var(--muted); font-size: .85rem; text-align: center; margin-top: 18px; }

@media (min-width: 760px) {
  .app-shell { padding: 20px; padding-bottom: 40px; }
  .topbar { margin: -20px -20px 16px; padding: 8px 20px; }
  .nav { grid-template-columns: repeat(6, 1fr); }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .toolbar { grid-template-columns: 2fr 1fr 1fr auto auto; align-items: center; }
  .manage-row { grid-template-columns: minmax(220px, 1fr) auto auto auto 110px auto; }
  .day-strip { grid-template-columns: repeat(6, 1fr); }
  .setting-row { grid-template-columns: 220px 1fr; align-items: center; }
  .availability-row { grid-template-columns: 1fr 120px 120px; align-items: center; }
}

.summary-days {
  display: grid;
  gap: 8px;
}
.summary-day {
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 10px 12px;
  color: var(--text);
}
.summary-day.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(217, 52, 69, .12);
}
.summary-day.today-date:not(.active) {
  border-color: var(--brand);
  background: #fff7f8;
}
.summary-day span {
  color: var(--brand-dark);
  font-weight: 700;
}
.summary-day small {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.backup-row {
  background: #fffdf7;
  border-radius: 14px;
  padding-left: 10px;
  padding-right: 10px;
}

@media (min-width: 760px) {
  .summary-days { grid-template-columns: repeat(3, 1fr); }
}

/* v9 UI cleanup */
.app-shell > .day-strip,
.app-shell > .hero,
.app-shell > .panel,
.app-shell > .grid,
.app-shell > .toolbar,
.app-shell > .manage-list,
.app-shell > .warning {
  margin-bottom: 12px;
}
.app-shell > .day-strip:last-child,
.app-shell > .hero:last-child,
.app-shell > .panel:last-child,
.app-shell > .grid:last-child,
.app-shell > .toolbar:last-child,
.app-shell > .manage-list:last-child,
.app-shell > .warning:last-child {
  margin-bottom: 0;
}
.hero { margin-bottom: 0; }
.warning { margin-top: 0; }

.title-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  padding: 0;
  min-height: 0;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}
.title-link:hover,
.title-link:focus-visible {
  color: var(--brand);
  outline: none;
  text-decoration-thickness: 2px;
}
.title-link:focus-visible {
  box-shadow: 0 0 0 3px rgba(217, 52, 69, .20);
  border-radius: 6px;
}

.card {
  cursor: default;
}
.card-actions {
  margin-top: 2px;
}
.plan-row h3,
.card h3 {
  line-height: 1.2;
}

.manage-row {
  gap: 10px 12px;
}
.manage-row .btn {
  justify-self: start;
  white-space: nowrap;
}
.compact-field {
  white-space: nowrap;
}
.compact-field input[type="number"] {
  flex: 0 0 58px;
}

@media (min-width: 760px) {
  .manage-row {
    grid-template-columns: minmax(260px, 1fr) minmax(62px, auto) minmax(62px, auto) minmax(76px, auto) minmax(104px, auto) minmax(130px, auto);
    column-gap: 14px;
  }
}

/* v11 card cleanup */
.title-link {
  color: var(--text);
}
.title-link:hover,
.title-link:focus-visible {
  color: var(--text);
}
.event-summary {
  background: #f7fbff;
  border-left: 5px solid #b9d4ef;
  padding: 8px 10px;
  border-radius: 10px;
  color: #334b63;
  font-size: .92rem;
}
.card .chips {
  margin-top: 6px;
}
.card .card-actions {
  padding-top: 2px;
}

/* v12 mobile location bar */
.location-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
}
.location-bar > div:first-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.location-bar .muted {
  font-size: .9rem;
  overflow-wrap: anywhere;
}
.location-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 560px) {
  .location-bar {
    align-items: stretch;
    flex-direction: column;
  }
  .location-actions {
    justify-content: stretch;
  }
  .location-actions .btn {
    flex: 1 1 auto;
  }
}
