:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --ink: #23282B;
  --ink-soft: #6B7278;
  --accent: #2F6F62;
  --accent-ink: #F3F8F6;
  --accent-soft: #DCE9E5;
  --line: #DDD7C8;
  --line-strong: #C7BFA9;
  --danger: #A8462E;
  --danger-soft: #F3E1DB;
  --radius-s: 6px;
  --radius-m: 12px;
  --shadow-modal: 0 20px 48px rgba(35, 40, 43, 0.22);
  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-body: "Archivo", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

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

/* ---------------------------------------------------------------- Topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.topbar__brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.topbar__mark {
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.topbar__brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  margin: 0;
  letter-spacing: 0.2px;
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-label {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
  margin-left: 6px;
  min-width: 150px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--bg); }

.pill-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pill-btn:hover { border-color: var(--line-strong); }

.pill-btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.pill-btn--accent:hover { background: #285F53; }

.text-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 14px;
  padding: 8px 4px;
}
.text-btn:hover { color: var(--ink); }
.text-btn--danger { color: var(--danger); }

.view-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.view-toggle__btn {
  border: none;
  background: var(--surface);
  padding: 8px 16px;
  font-size: 14px;
  color: var(--ink-soft);
}
.view-toggle__btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------ Member strip */

.members-strip {
  display: flex;
  gap: 8px;
  padding: 10px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid var(--line);
}
.member-chip__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.member-chip.is-external { border-style: dashed; color: var(--ink-soft); }

/* ------------------------------------------------------------- Calendar */

.calendar-root {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.calendar-scroll {
  height: 100%;
  overflow: auto;
}

.calendar-grid {
  position: relative;
  display: grid;
  grid-template-columns: 56px 1fr;
}

.grid-header {
  position: sticky;
  top: 0;
  z-index: 5;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 56px 1fr;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.grid-header__gutter { border-right: 1px solid var(--line); }

.grid-header__columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
}

.col-header {
  padding: 10px 8px;
  text-align: center;
  border-right: 1px solid var(--line);
}
.col-header:last-child { border-right: none; }

.col-header__day {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: capitalize;
}
.col-header__date {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
}
.col-header.is-today .col-header__date { color: var(--accent); }
.col-header.is-weekend { background: #EFE8D6; }
.col-header.is-weekend .col-header__day,
.col-header.is-weekend .col-header__date { color: #8A7F63; }

.col-header__member {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
}
.col-header__member-dot {
  width: 9px; height: 9px; border-radius: 50%;
}

.time-gutter {
  grid-column: 1;
  border-right: 1px solid var(--line);
  position: relative;
}
.time-gutter__label {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--ink-soft);
}

.day-columns {
  grid-column: 2;
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
}

.day-column {
  position: relative;
  border-right: 1px solid var(--line);
}
.day-column:last-child { border-right: none; }
.day-column.is-today { background: rgba(47, 111, 98, 0.045); }
.day-column.is-weekend { background: #EFE8D6; }
.day-column.is-weekend.is-today { background: rgba(47, 111, 98, 0.06); }

.hour-line {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px solid var(--line);
}
.hour-line.is-half { border-top: 1px dashed #EAE5D6; }

.now-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 4;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -5px; top: -4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

.event-block {
  position: absolute;
  border-radius: var(--radius-s);
  padding: 4px 7px;
  font-size: 12px;
  line-height: 1.25;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.event-block__title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-block__meta {
  opacity: 0.85;
  font-size: 11px;
}
.event-block.is-allday {
  position: static;
  margin: 3px 4px 0;
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 16px;
  grid-column: 1 / -1;
}

/* --------------------------------------------------------------- Modals */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(35, 40, 43, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.is-open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-m);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}
.modal--wide { max-width: 640px; }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
}
.modal__header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}

.modal__body { padding: 4px 20px 20px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-soft);
}
.field > span:first-child { font-weight: 500; }
.field input, .field select, .field textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--bg);
}
.field input[type="checkbox"] {
  width: 18px; height: 18px;
  align-self: flex-start;
}

.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field { flex: 1; }

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.modal__footer-right { display: flex; gap: 8px; }

.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.settings-section:last-child { border-bottom: none; }
.settings-section h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 10px;
}
.hint {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.5;
}
.hint code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}

.members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-s);
}
.member-row__dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.member-row__name { flex: 1; font-size: 14px; }
.member-row__tag {
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 999px;
}

.member-form, .source-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.member-form input[type="text"], .source-form input {
  flex: 1;
  min-width: 160px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--bg);
  font-size: 14px;
}
.member-form input[type="color"] {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 2px;
  background: var(--surface);
}
.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}

.weekday-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.weekday-picker label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
  cursor: pointer;
}
.weekday-picker input[type="checkbox"] {
  width: 14px; height: 14px;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-s);
  font-size: 13px;
}
.source-row__name { font-weight: 600; flex: 1; }
.source-row__status { color: var(--ink-soft); font-size: 12px; }
.source-row__status.is-error { color: var(--danger); }

/* -------------------------------------------------------- Responsiveness */

@media (max-width: 860px) {
  .topbar { padding: 10px 14px; gap: 12px; }
  .topbar__brand h1 { font-size: 17px; }
  .period-label { font-size: 15px; min-width: 0; }
  .members-strip { padding: 8px 14px; }
  .col-header__date { font-size: 15px; }
}
