:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #16202a;
  --muted: #5e6b78;
  --accent: #0f6d8c;
  --accent-strong: #0b566f;
  --line: #d8e0e7;
  --warning-bg: #fff5ea;
  --warning-line: #ffd4a8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Nunito Sans", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(1000px 520px at -12% -8%, #e8f1f6 0%, transparent 60%),
    radial-gradient(820px 450px at 112% 8%, #eaf6f7 0%, transparent 58%),
    linear-gradient(180deg, #f7f9fb 0%, #eef2f5 100%);
  color: var(--ink);
  line-height: 1.45;
}

.container {
  max-width: 1120px;
  margin: 1.5rem auto 2rem;
  padding: 1.4rem;
  background: var(--surface);
  border: 1px solid #e3e9ee;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 39, 56, 0.08);
}

.page-header {
  margin-bottom: 1.1rem;
}

.page-header h1 {
  margin: 0;
  font-family: "Avenir Next Condensed", "Franklin Gothic Medium", "Trebuchet MS", sans-serif;
  font-size: clamp(1.65rem, 2.1vw, 2.45rem);
  letter-spacing: 0.01em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #d9e4ec;
  background: #f5f8fb;
  flex: 0 0 auto;
}

.community-strip {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--muted);
}

.community-link {
  color: #5b7183;
  text-decoration: none;
  border-bottom: 1px dotted #b6c6d2;
}

.community-link:hover {
  color: #3d5568;
  border-bottom-color: #8ea5b6;
  text-decoration: none;
}

.email-signup {
  display: inline-block;
  position: relative;
}

.email-signup summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  cursor: pointer;
  color: #5b7183;
  border-bottom: 1px dotted #b6c6d2;
}

.email-signup summary::-webkit-details-marker {
  display: none;
}

.email-signup summary::after {
  content: " ▾";
  color: #8ba0b0;
  font-size: 0.85em;
}

.email-signup[open] summary::after {
  content: " ▴";
}

.email-signup-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 0.45rem);
  z-index: 12;
  width: min(430px, calc(100vw - 3.8rem));
  padding: 0.52rem;
  border: 1px solid #d7e2ea;
  border-radius: 10px;
  background: #fbfdff;
  box-shadow: 0 10px 24px rgba(13, 35, 52, 0.12);
}

.email-signup-panel form {
  margin: 0;
}

.email-signup-panel input,
.email-signup-panel button {
  min-height: 34px;
  font-size: 0.92rem;
}

/* Kit embed compaction overrides */
.email-signup-panel .formkit-form {
  margin: 0 !important;
  padding: 0 !important;
  max-width: 100% !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

.email-signup-panel .formkit-fields {
  display: flex !important;
  align-items: center !important;
  gap: 0.45rem !important;
  margin: 0 !important;
}

.email-signup-panel .formkit-field {
  margin: 0 !important;
  flex: 1 1 auto;
}

.email-signup-panel .formkit-input {
  min-height: 34px !important;
  padding: 0.38rem 0.62rem !important;
  font-size: 0.9rem !important;
}

.email-signup-panel .formkit-submit {
  min-height: 34px !important;
  padding: 0.4rem 0.72rem !important;
  font-size: 0.86rem !important;
  width: auto !important;
  white-space: nowrap;
  color: #ffffff !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  text-indent: 0 !important;
}

.email-signup-panel .formkit-submit * {
  color: inherit !important;
}

.email-signup-panel .formkit-powered-by-convertkit-container,
.email-signup-panel .formkit-powered-by-convertkit {
  margin-top: 0.22rem !important;
  font-size: 0.68rem !important;
  opacity: 0.62;
}

.view-switch {
  margin-top: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6fafd;
}

.view-btn {
  min-height: 34px;
  width: auto;
  padding: 0.35rem 0.82rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: #4d6274;
  font-weight: 600;
}

.view-btn.is-active {
  background: #ffffff;
  border-color: #cad8e3;
  color: #213245;
  box-shadow: 0 1px 4px rgba(20, 42, 60, 0.08);
}

.calendar-view {
  padding: 0.25rem;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.52rem;
}

.calendar-header h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.calendar-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.calendar-nav {
  min-height: 34px;
  width: auto;
  min-width: 34px;
  padding: 0.25rem 0.55rem;
  border-radius: 8px;
  border: 1px solid #cfdae4;
  background: #ffffff;
  font-weight: 600;
}

.calendar-today {
  min-width: 58px;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.3rem;
  margin-bottom: 0.35rem;
}

.calendar-weekdays span {
  text-align: center;
  color: #6a7a88;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.3rem;
}

.calendar-day {
  min-height: 92px;
  padding: 0.45rem 0.35rem;
  border-radius: 9px;
  border: 1px solid #d9e3eb;
  background: #f9fbfd;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  text-align: left;
}

.calendar-day .day-number {
  font-weight: 700;
  font-size: 0.95rem;
  color: #203244;
}

.calendar-day .day-count {
  font-size: 0.7rem;
  color: #597084;
  line-height: 1.2;
}

.calendar-day.outside-month {
  opacity: 0.48;
}

.calendar-day.has-events {
  background: #f2f8fc;
  border-color: #bfd6e6;
}

.calendar-day.is-today {
  border-color: #86b8d0;
  box-shadow: inset 0 0 0 1px #a7cfdf;
}

.day-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.day-modal[hidden] {
  display: none;
}

.day-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 29, 43, 0.42);
}

.day-modal-card {
  position: relative;
  width: min(620px, calc(100vw - 1.4rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid #c9d8e4;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(7, 24, 36, 0.26);
  padding: 0.85rem 0.95rem;
}

.day-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.day-modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.day-modal-close {
  min-height: 32px;
  min-width: 32px;
  width: auto;
  padding: 0;
  border-radius: 8px;
  border: 1px solid #cfdae4;
  background: #f8fbfd;
  font-size: 1.2rem;
  line-height: 1;
}

.day-modal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.48rem;
}

.day-modal-item {
  border: 1px solid #dde6ed;
  border-radius: 10px;
  padding: 0.58rem 0.68rem;
  background: #fbfdff;
}

.day-modal-item-title {
  margin: 0;
  font-weight: 700;
}

.day-modal-item-meta {
  margin: 0.18rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.day-modal-item a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid #b8d2df;
  border-radius: 999px;
  background: #f3fbff;
  padding: 0.18rem 0.56rem;
  text-decoration: none;
}

.day-modal-empty {
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 640px) {
  .email-signup-panel {
    position: static;
    margin-top: 0.4rem;
    width: min(430px, calc(100vw - 3.8rem));
  }

  .email-signup-panel .formkit-fields {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .email-signup-panel .formkit-submit {
    width: 100% !important;
  }
}

.controls {
  display: grid;
  grid-template-columns: minmax(360px, 1.7fr) minmax(220px, 1fr);
  gap: 0.9rem;
  margin: 1rem 0 0.9rem;
  padding: 0.75rem;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.control-field {
  display: grid;
  gap: 0.3rem;
}

.control-field label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

button,
input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0.62rem 0.82rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

button {
  cursor: pointer;
}

input::placeholder {
  color: #7f8d99;
}

input:focus,
select:focus,
button:focus {
  outline: none;
  border-color: #9ac4d3;
  box-shadow: 0 0 0 3px rgba(15, 109, 140, 0.14);
}

.multi-select {
  position: relative;
}

.multi-select-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-align: left;
}

.multi-select-toggle::after {
  content: "▾";
  color: #6f7b87;
  font-size: 0.9rem;
}

.multi-select-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 22px rgba(11, 28, 42, 0.14);
  z-index: 10;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.multi-select-option:hover {
  background: #f2f7fa;
}

.multi-select-option input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.meta {
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.refresh-notice {
  margin: 0.35rem 0 0;
  color: #4f6a7d;
  font-size: 0.88rem;
}

.errors {
  margin-top: 0.9rem;
  padding: 0.86rem 1rem 0.9rem;
  border: 1px solid var(--warning-line);
  background: var(--warning-bg);
  border-radius: 12px;
}

.errors h2 {
  margin: 0 0 0.42rem;
  font-size: 1rem;
}

.errors ul {
  margin: 0;
  padding-left: 1.15rem;
}

.table-wrap {
  margin-top: 0.95rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid #e5ebf0;
  padding: 0.75rem 0.7rem;
  text-align: left;
  vertical-align: top;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  font-weight: 700;
  letter-spacing: 0.01em;
}

tbody tr:hover {
  background: #f6fbfd;
}

tbody tr:last-child td {
  border-bottom: 0;
}

#events-table th:first-child,
#events-table td:first-child {
  width: 11ch;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  font-variant-numeric: tabular-nums;
}

#events-table th:nth-child(3),
#events-table td:nth-child(3) {
  width: 18ch;
}

#events-table th:nth-child(4),
#events-table td:nth-child(4) {
  width: 14ch;
}

#events-table th:nth-child(5),
#events-table td:nth-child(5) {
  width: 6ch;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
}

@media (max-width: 900px) {
  .container {
    margin: 1rem 0.75rem 1.35rem;
    padding: 1rem;
  }

  .brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 8px;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .calendar-day {
    min-height: 82px;
  }

  #events-table th:nth-child(3),
  #events-table td:nth-child(3),
  #events-table th:nth-child(4),
  #events-table td:nth-child(4) {
    width: auto;
  }
}

@media (max-width: 700px) {
  .container {
    margin: 0.7rem 0.5rem 1.1rem;
    padding: 0.92rem;
    border-radius: 12px;
  }

  .brand {
    align-items: flex-start;
    gap: 0.55rem;
  }

  .page-header h1 {
    font-size: clamp(1.35rem, 6vw, 1.82rem);
    line-height: 1.18;
  }

  .community-strip {
    margin-top: 0.44rem;
    gap: 0.78rem;
    font-size: 0.84rem;
  }

  .controls {
    margin-top: 0.92rem;
    padding: 0.82rem;
    gap: 0.72rem;
  }

  .control-field label {
    font-size: 0.78rem;
  }

  input,
  button,
  select {
    min-height: 42px;
    padding: 0.56rem 0.7rem;
  }

  .multi-select-menu {
    max-height: 220px;
  }

  .view-switch {
    margin-top: 0.72rem;
  }

  .view-btn {
    min-height: 33px;
    padding: 0.34rem 0.68rem;
    font-size: 0.9rem;
  }

  .meta,
  .refresh-notice {
    font-size: 0.84rem;
  }

  .table-wrap {
    margin-top: 0.88rem;
    border: 0;
    background: transparent;
    overflow: visible;
  }

  #events-table {
    width: 100%;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0 1rem;
  }

  #events-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    white-space: nowrap;
  }

  #events-table tbody,
  #events-table tr,
  #events-table td {
    display: block;
    width: 100%;
  }

  #events-table tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    padding: 0.65rem 0.72rem;
    box-shadow: 0 3px 10px rgba(13, 36, 52, 0.06);
  }

  #events-table tbody tr + tr {
    margin-top: 0.18rem;
  }

  #events-table td {
    border-bottom: 0;
    padding: 0.24rem 0;
    display: block;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
  }

  #events-table td:not(:last-child) {
    border-bottom: 1px solid #edf2f6;
    margin-bottom: 0.38rem;
    padding-bottom: 0.52rem;
  }

  #events-table td::before {
    display: block;
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin-bottom: 0.12rem;
  }

  #events-table td[data-label="Link"] a {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0.22rem 0.62rem;
    border-radius: 999px;
    border: 1px solid #b8d2df;
    background: #f3fbff;
    text-decoration: none;
  }

  #events-table th:first-child,
  #events-table td:first-child,
  #events-table th:nth-child(3),
  #events-table td:nth-child(3),
  #events-table th:nth-child(4),
  #events-table td:nth-child(4),
  #events-table th:nth-child(5),
  #events-table td:nth-child(5) {
    width: auto;
    white-space: normal;
  }

  .calendar-header {
    margin-bottom: 0.42rem;
  }

  .calendar-header h2 {
    font-size: 0.94rem;
  }

  .calendar-nav {
    min-height: 32px;
    min-width: 32px;
    padding: 0.2rem 0.45rem;
    font-size: 0.88rem;
  }

  .calendar-weekdays {
    gap: 0.2rem;
    margin-bottom: 0.26rem;
  }

  .calendar-weekdays span {
    font-size: 0.64rem;
  }

  .calendar-grid {
    gap: 0.2rem;
  }

  .calendar-day {
    min-height: 72px;
    padding: 0.36rem 0.3rem;
    border-radius: 8px;
  }

  .calendar-day .day-number {
    font-size: 0.86rem;
  }

  .calendar-day .day-count {
    font-size: 0.62rem;
  }

  .day-modal {
    padding: 0.65rem;
  }

  .day-modal-card {
    width: calc(100vw - 1rem);
    padding: 0.72rem;
  }
}

@media (max-width: 420px) {
  .container {
    margin: 0.55rem 0.35rem 0.9rem;
    padding: 0.74rem;
  }

  .controls {
    padding: 0.68rem;
  }

  .community-strip {
    gap: 0.62rem;
  }

  #events-table tr {
    padding: 0.56rem 0.62rem;
  }

  #events-table {
    border-spacing: 0 0.9rem;
  }
}
