:root {
  color-scheme: light;
  --bg: #fff7ea;
  --ink: #282d27;
  --muted: #667165;
  --line: #d9ddd5;
  --panel: #fff0d3;
  --panel-green: #dcefe3;
  --panel-blue: #dcebf5;
  --panel-earth: #eadcc1;
  --panel-rose: #f6d9cb;
  --row-a: #f3ead8;
  --row-b: #e7eee6;
  --field: #fffaf0;
  --field-strong: #f5e4c6;
  --accent: #246f55;
  --accent-ink: #ffffff;
  --blue: #2e719f;
  --blue-ink: #173a52;
  --warn: #a44327;
  --focus: #0066d6;
  --radius: 14px;
  --radius-small: 10px;
}

@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-wght.ttf") format("truetype");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 650;
  transition: background-color .16s ease, transform .16s ease;
}

button.secondary {
  background: var(--panel-blue);
  color: var(--blue-ink);
}

button.danger {
  background: var(--panel-rose);
  color: var(--warn);
}

button:hover,
.button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 42px);
  background: #ffedcf;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.app-menu,
.space-switcher {
  position: relative;
}

.space-switcher > summary,
.current-space-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--field);
  padding: 0 14px;
  color: var(--ink);
  cursor: pointer;
  font-size: .95rem;
  font-weight: 700;
  line-height: 1;
}

.app-menu > summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}

.app-menu > summary::-webkit-details-marker,
.space-switcher > summary::-webkit-details-marker,
.menu-create-space > summary::-webkit-details-marker {
  display: none;
}

.app-menu > summary::after,
.space-switcher > summary::after,
.menu-create-space > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.brand-menu {
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.app-menu[open] > summary::after,
.space-switcher[open] > summary::after,
.menu-create-space[open] > summary::after {
  transform: translateY(2px) rotate(225deg);
}

.menu-panel,
.space-switcher-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  display: grid;
  gap: 4px;
  min-width: min(280px, calc(100vw - 28px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--field);
  box-shadow: 0 16px 42px rgb(40 45 39 / 14%);
}

.menu-panel {
  left: 0;
}

.space-switcher-panel {
  right: 0;
}

.menu-panel > a,
.menu-panel > button,
.menu-create-space > summary,
.space-switcher-panel a {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  font-weight: 650;
}

.menu-panel > a:hover,
.menu-panel > button:hover,
.menu-create-space > summary:hover,
.space-switcher-panel a:hover,
.space-switcher-panel a[aria-current="page"] {
  background: var(--panel-green);
  transform: none;
}

.menu-create-space form {
  display: grid;
  gap: 10px;
  padding: 8px 10px 10px;
}

.menu-create-space input {
  border: 1px solid var(--line);
  background: #ffffff;
}

.current-space {
  min-width: 0;
  max-width: min(360px, 45vw);
}

.space-switcher > summary,
.current-space-link {
  max-width: 100%;
  overflow: hidden;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.space-switcher-panel small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 650;
}

.space-switcher-panel span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.page {
  width: min(1040px, 100%);
  flex: 1;
  margin: 0 auto;
  padding: 24px clamp(14px, 4vw, 36px) 60px;
}

.site-footer {
  width: min(1040px, 100%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 auto;
  padding: 0 clamp(14px, 4vw, 36px) 28px;
}

.site-footer button {
  min-height: 36px;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
  font-size: .9rem;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.site-footer button:hover {
  color: var(--ink);
  transform: none;
}

.footer-modal .modal-card {
  background: var(--field);
}

.footer-modal p {
  margin: 0;
}

.footer-help {
  gap: 16px;
}

.footer-help section {
  display: grid;
  gap: 4px;
}

.footer-help h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.intro {
  padding: 42px 0 20px;
}

.intro h1,
.topline h1,
.space-head h1 {
  margin: 0;
  font-size: clamp(2rem, 9vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.intro p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1.2rem;
}

.form-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 650;
  font-size: .78rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--field);
  color: var(--ink);
  padding: 9px 12px;
  font-size: 1rem;
}

textarea {
  display: block;
  overflow: hidden;
  resize: none;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.topline,
.space-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.space-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.modal {
  width: min(520px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  padding: 0;
}

.modal::backdrop {
  background: rgb(40 45 39 / 42%);
}

.modal-card {
  display: grid;
  gap: 16px;
  overflow: auto;
  max-height: calc(100dvh - 28px);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.modal-content {
  display: grid;
  gap: 10px;
}

.eyebrow,
.panel-title {
  margin: 0 0 4px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: .75rem;
}

.muted,
.empty {
  color: var(--muted);
}

.space-list,
.device-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.space-list a,
.device-list li {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel-green);
  text-decoration: none;
}

.space-list li:nth-child(2n) a,
.device-list li:nth-child(2n) {
  background: var(--panel-blue);
}

.space-list li:nth-child(3n) a,
.device-list li:nth-child(3n) {
  background: var(--panel-earth);
}

.space-list span,
.device-list span {
  color: var(--muted);
}

.admin-panel {
  margin: 0 0 18px;
  border-radius: var(--radius);
  background: var(--panel-green);
  padding: 14px;
}

.admin-panel {
  position: relative;
}

details.admin-panel:not([open]) {
  display: none;
}

.admin-panel summary {
  cursor: pointer;
  font-weight: 750;
}

.admin-panel > [data-delete-space] {
  position: absolute;
  top: 10px;
  right: 14px;
  min-height: 0;
  padding: 4px 9px;
  font-size: .82rem;
  line-height: 1.25;
}

.admin-content {
  display: grid;
  gap: 18px;
  padding-top: 16px;
}

.settings-panel .admin-content {
  padding-top: 42px;
}

.member-section h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.25;
}

.member-section .member-name {
  margin: 0;
  padding-left: 14px;
}

.member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
}

.member-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-left: 14px;
}

.remove-member-button {
  min-height: 0;
  border: 0;
  background: transparent;
  color: var(--warn);
  padding: 0 2px;
  font-size: .9em;
  line-height: 1;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-create {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel-earth);
}

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

.form-message {
  margin: 0;
  border-radius: var(--radius-small);
  padding: 10px 12px;
  background: var(--field);
  color: var(--muted);
  font-weight: 650;
}

.form-message.is-error {
  background: var(--panel-rose);
  color: var(--warn);
}

.form-message.is-success {
  background: var(--panel-green);
  color: var(--accent);
}

.when-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.when-field legend {
  padding: 0;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}

.quick-when button.is-active {
  background: #c5e4d3;
  color: var(--accent);
}

.commit-create [aria-invalid="true"],
.when-field.is-invalid .quick-when {
  outline: 2px solid var(--warn);
  outline-offset: 2px;
}

.quick-when,
.actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.toggle-switch {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
}

.toggle-switch a {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  padding: 0 16px;
  color: #9aa19a;
  text-decoration: none;
  font-weight: 700;
}

.toggle-switch a + a {
  border-left: 1px solid rgb(40 45 39 / 10%);
}

.toggle-switch a.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.commitments-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--row-a);
}

.commitments-header,
.commitment-row {
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(180px, 1fr) minmax(140px, 180px) minmax(190px, auto);
  gap: 0;
  align-items: stretch;
}

.commitments-header {
  min-height: 38px;
  border-bottom: 1px solid rgb(40 45 39 / 12%);
  background: rgb(255 250 240 / 48%);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.commitments-header span {
  padding: 10px 12px;
}

.commitments {
  display: grid;
}

.commitment {
  background: var(--row-a);
}

.commitment:nth-child(even) {
  background: var(--row-b);
}

.commitment + .commitment {
  border-top: 1px solid rgb(40 45 39 / 8%);
}

.commitment.is-done {
  opacity: .72;
}

.commitment-row {
  min-height: 58px;
}

.commitment-row label {
  min-width: 0;
  height: 100%;
  align-content: start;
  padding: 8px;
}

.commitment-row label > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.commitment-row input,
.commitment-row select,
.commitment-row textarea {
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  padding: 8px 10px;
}

.commitment-row input:disabled,
.commitment-row select:disabled,
.commitment-row textarea:disabled {
  color: var(--muted);
  opacity: 1;
}

.commitment-what textarea {
  font-weight: 650;
}

.commitment-row .row-actions {
  align-items: start;
  justify-content: flex-end;
  padding: 8px 10px 8px 4px;
}

.commitment-row .row-actions button {
  min-height: 36px;
  padding: 0 11px;
  font-size: .9rem;
}

.commitments .empty {
  margin: 0;
  padding: 18px;
  background: var(--row-a);
}

.copy-field {
  margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.share-help {
  margin: 0;
}

.qr-box {
  width: min(360px, 100%);
  margin: 14px auto 0;
  padding: 16px;
  background: var(--field);
  border-radius: var(--radius);
  overflow: visible;
}

.qr-box:empty {
  display: none;
}

.qr-box svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: 0 auto;
  background: var(--field);
  shape-rendering: crispEdges;
}

.prose {
  max-width: 680px;
}

@media (min-width: 760px) {
  .inline-create {
    grid-template-columns: 1fr auto;
    align-items: end;
  }
}

@media (max-width: 760px) {
  .commitments-header {
    grid-template-columns: .9fr 1.35fr 1fr;
  }

  .commitments-header span {
    padding: 9px 10px;
  }

  .commitments-header span:last-child {
    display: none;
  }

  .commitment-row {
    grid-template-columns: .9fr 1.35fr 1fr;
    min-height: 0;
  }

  .commitment-who {
    grid-column: 1;
    grid-row: 1;
  }

  .commitment-what {
    grid-column: 2;
    grid-row: 1;
  }

  .commitment-when {
    grid-column: 3;
    grid-row: 1;
  }

  .commitment-row .row-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 2px 8px 10px;
  }

  .commitment-row .row-actions button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topline,
  .space-head,
  .space-list a,
  .device-list li {
    align-items: stretch;
    flex-direction: column;
  }

  .space-actions {
    justify-content: stretch;
  }

  .space-actions button {
    width: 100%;
  }

  .site-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .header-left {
    width: 100%;
    justify-content: space-between;
  }

  .current-space {
    width: 100%;
    max-width: none;
  }

  .space-switcher,
  .space-switcher > summary,
  .current-space-link {
    width: 100%;
  }

  .space-switcher-panel {
    right: auto;
    left: 0;
  }
}
