:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-strong: #fff9ee;
  --ink: #222420;
  --muted: #6f746b;
  --line: #ded7c9;
  --accent: #176b5b;
  --accent-dark: #0d4f43;
  --accent-soft: #dceee8;
  --coral: #d7674d;
  --sun: #e8b84a;
  --blue: #3867b7;
  --shadow: 0 18px 50px rgba(41, 38, 31, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(232, 184, 74, 0.22), transparent 28rem),
    linear-gradient(140deg, #f6f2ea 0%, #edf2ed 48%, #f8efe8 100%);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border-right: 1px solid rgba(34, 36, 32, 0.08);
  background: rgba(255, 253, 248, 0.74);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.2rem;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 50%;
  background: var(--ink);
  color: #fffdf8;
  font-weight: 900;
}

.nav-tabs {
  display: grid;
  gap: 0.45rem;
}

.nav-tab {
  min-height: 3rem;
  border: 0;
  border-radius: 0.5rem;
  color: var(--muted);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.8rem;
  text-align: left;
}

.nav-tab span:first-child {
  width: 1.5rem;
  font-size: 1.1rem;
}

.nav-tab.is-active,
.nav-tab:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.install-button,
.primary-action,
.ghost-action,
.text-action,
.icon-button,
.snooze-button,
.cadence-presets button {
  border: 0;
  border-radius: 0.5rem;
  min-height: 2.75rem;
}

.install-button {
  margin-top: auto;
  background: var(--ink);
  color: white;
}

.account-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 700;
}

.account-button.is-synced {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.auth-copy {
  color: var(--muted);
  margin: 0 0 0.6rem;
  line-height: 1.5;
}

.auth-error {
  color: #9e2f23;
  min-height: 1.2rem;
  margin: 0;
  font-size: 0.9rem;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at top left, rgba(232, 184, 74, 0.22), transparent 28rem),
    linear-gradient(140deg, #f6f2ea 0%, #edf2ed 48%, #f8efe8 100%);
}

.auth-card {
  width: min(100%, 24rem);
  display: grid;
  gap: 1rem;
  padding: clamp(1.4rem, 4vw, 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
}

.auth-brand {
  justify-content: center;
}

body:not(.is-authed) .app-shell {
  display: none;
}

body.is-authed .auth-gate {
  display: none;
}

.workspace {
  padding: clamp(1rem, 2.5vw, 2rem);
  width: min(100%, 86rem);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1.25rem;
}

.page-header h1 {
  margin: 0;
  max-width: 46rem;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.page-header.compact h1 {
  font-size: clamp(2rem, 3vw, 3rem);
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-action {
  background: var(--accent);
  color: white;
  font-weight: 800;
  padding: 0 1.05rem;
  box-shadow: 0 10px 24px rgba(23, 107, 91, 0.22);
}

.primary-action:hover {
  background: var(--accent-dark);
}

.ghost-action {
  background: #efe9dc;
  color: var(--ink);
  padding: 0 1rem;
  font-weight: 750;
}

.text-action,
.link-action {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 850;
  padding: 0;
}

.text-action {
  min-height: 1.5rem;
  margin-bottom: 0.55rem;
}

.link-action {
  text-align: left;
}

.link-action:hover,
.text-action:hover {
  color: var(--accent);
  text-decoration: underline;
}

.danger {
  color: #9e2f23;
  margin-right: auto;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 26rem);
  gap: 1rem;
  align-items: start;
}

.focus-panel,
.side-panel,
.detail-panel {
  border: 1px solid rgba(34, 36, 32, 0.1);
  border-radius: 0.5rem;
  background: rgba(255, 253, 248, 0.82);
  box-shadow: var(--shadow);
}

.focus-panel {
  padding: 1rem;
}

.side-panel {
  padding: 1rem;
}

.detail-panel {
  padding: 1rem;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.9rem;
}

.section-title h2 {
  margin: 0;
  font-size: 1.05rem;
}

.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
}

.queue-list,
.people-list,
.journal-list {
  display: grid;
  gap: 0.7rem;
}

.queue-card,
.person-card,
.journal-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
}

.queue-card {
  display: grid;
  gap: 0.85rem;
  padding: 0.85rem;
}

.queue-info {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.85rem;
  align-items: center;
}

.queue-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(222, 215, 201, 0.72);
}

.status-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--accent);
}

.status-dot.overdue {
  background: var(--coral);
}

.status-dot.soon {
  background: var(--sun);
}

.person-main {
  min-width: 0;
}

.person-main h3,
.journal-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.person-main h3 .link-action {
  font-size: inherit;
}

.meta-line,
.note-preview {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.note-preview {
  margin-top: 0.35rem;
}

.due-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0 0.55rem;
  border-radius: 999px;
  background: #f0eadf;
  color: #4d514b;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.due-pill.overdue {
  background: #ffe0d8;
  color: #8c321f;
}

.due-pill.today {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.card-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: end;
}

.icon-button {
  width: 2.5rem;
  min-width: 2.5rem;
  background: #efe9dc;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
}

.snooze-button {
  min-height: 2.2rem;
  padding: 0 0.6rem;
  background: #efe9dc;
  color: #4d514b;
  font-size: 0.78rem;
  font-weight: 850;
}

.snooze-button:hover,
.cadence-presets button:hover {
  background: #e4ddcf;
}

.people-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 13rem;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.search-field span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.people-tools input,
.people-tools select,
.stacked-form input,
.stacked-form select,
.stacked-form textarea,
.dialog-form input,
.dialog-form select,
.dialog-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 253, 248, 0.92);
  color: var(--ink);
  min-height: 2.85rem;
  padding: 0.65rem 0.75rem;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.16);
}

.stacked-form,
.dialog-form {
  display: grid;
  gap: 0.8rem;
}

.type-fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.type-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.type-options label {
  min-width: 0;
}

.type-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.type-options span {
  display: grid;
  place-items: center;
  min-height: 2.45rem;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 253, 248, 0.92);
  color: #4d514b;
  font-size: 0.86rem;
  font-weight: 850;
}

.type-options input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.type-options input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.16);
}

label span,
legend {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.person-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  padding: 0.9rem;
}

.person-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.journal-card {
  padding: 0.9rem;
}

.detail-header {
  align-items: start;
}

.detail-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: end;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem);
  gap: 1rem;
  align-items: start;
}

.detail-history {
  grid-column: 1 / -1;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.summary-item {
  min-height: 5rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
}

.summary-item span {
  display: block;
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.summary-item strong {
  display: block;
  color: var(--ink);
  line-height: 1.25;
}

.detail-notes {
  min-height: 11rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.55;
  white-space: pre-wrap;
}

.detail-notes p {
  margin: 0;
}

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

.empty-state {
  padding: 1.5rem;
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(94vw, 38rem);
  border: 0;
  border-radius: 0.5rem;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 90px rgba(34, 36, 32, 0.28);
}

dialog::backdrop {
  background: rgba(34, 36, 32, 0.34);
  backdrop-filter: blur(3px);
}

.dialog-form {
  padding: 1rem;
}

.dialog-header,
.dialog-actions,
.form-row {
  display: flex;
  gap: 0.75rem;
}

.dialog-header {
  align-items: center;
  justify-content: space-between;
}

.dialog-header h2 {
  margin: 0;
}

.dialog-actions {
  justify-content: end;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.backup-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: end;
}

.import-action {
  display: inline-grid;
  place-items: center;
  min-height: 2.75rem;
}

.import-action span {
  margin: 0;
  color: inherit;
  font-size: inherit;
}

.import-action input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.form-row > * {
  flex: 1;
  min-width: 0;
}

.cadence-fieldset {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.85rem;
}

.cadence-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.cadence-presets button {
  min-height: 2.15rem;
  padding: 0 0.7rem;
  background: #efe9dc;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translate(-50%, 1rem);
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  border-radius: 0.5rem;
  background: var(--ink);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    padding-bottom: 4.35rem;
  }

  .rail {
    position: fixed;
    inset: auto 0 0;
    z-index: 8;
    height: auto;
    padding: 0.55rem calc(0.55rem + env(safe-area-inset-right)) calc(0.55rem + env(safe-area-inset-bottom)) calc(0.55rem + env(safe-area-inset-left));
    border: 1px solid rgba(34, 36, 32, 0.1);
    border-width: 1px 0 0;
    background: rgba(255, 253, 248, 0.92);
  }

  .brand,
  .install-button {
    display: none;
  }

  .account-button {
    position: fixed;
    top: calc(0.6rem + env(safe-area-inset-top));
    right: calc(0.7rem + env(safe-area-inset-right));
    z-index: 9;
    min-height: 2.4rem;
    padding: 0 0.9rem;
    box-shadow: var(--shadow);
  }

  .nav-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-tab {
    justify-content: center;
    min-height: 3.1rem;
    padding: 0;
    gap: 0.25rem;
    flex-direction: column;
    font-size: 0.78rem;
  }

  .workspace {
    padding: 1rem;
  }

  .page-header {
    align-items: start;
    flex-direction: column;
  }

  .page-header .primary-action {
    width: 100%;
  }

  .dashboard-grid,
  .people-tools,
  .detail-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .queue-info {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .queue-info .due-pill {
    grid-column: 2;
    justify-self: start;
    margin-top: 0.25rem;
  }

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

  .queue-actions > * {
    flex: 1;
  }

  .person-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .person-card .card-actions {
    grid-column: 1 / -1;
    justify-content: end;
  }

  .backup-actions {
    width: 100%;
  }

  .backup-actions > *,
  .detail-actions > * {
    flex: 1;
  }

  .detail-actions {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .form-row,
  .dialog-actions {
    flex-direction: column;
  }

  .danger {
    margin-right: 0;
  }
}
