@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("/fonts/source-sans-3-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --paper: #f3f0e8;
  --surface: #faf8f2;
  --surface-soft: #f0ece2;
  --ink: #282721;
  --muted: #77736a;
  --line: #d9d3c7;
  --red: #a95142;
  --red-soft: #f2dfda;
  --amber: #b3872e;
  --amber-soft: #f4ead2;
  --green: #6f8f77;
  --gray: #95938b;
  --focus: #4c6c7c;
  font-family: "Source Sans 3", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 20% 0%, rgb(255 255 255 / 45%), transparent 40%),
    var(--paper);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 1rem;
  left: 1rem;
  padding: 0.7rem 1rem;
  color: var(--surface);
  background: var(--ink);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.ledger-shell {
  display: grid;
  grid-template-columns: minmax(31rem, 1.05fr) minmax(34rem, 0.95fr);
  gap: 1.2rem;
  height: 100vh;
  padding: 1.5rem;
}

.account-panel,
.detail-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgb(250 248 242 / 86%);
}

.account-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 2.5rem 3rem 1.35rem;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-weight: 430;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2.3rem, 4vw, 3.35rem);
}

h2 {
  font-size: 2rem;
}

.text-action,
.icon-close,
.danger-link {
  border: 0;
  background: transparent;
}

.text-action {
  padding: 0.4rem;
  color: var(--muted);
  text-decoration: none;
}

.text-action:hover {
  color: var(--ink);
}

.filters {
  display: grid;
  gap: 0.8rem;
  padding: 0 3rem 1rem;
  border-bottom: 1px solid var(--line);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.filter-chip,
.needs-task {
  min-height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 0.8rem;
}

.filter-chip {
  padding: 0.25rem 0.72rem;
  color: var(--muted);
}

.filter-chip::before {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: var(--gray);
  content: "";
}

.filter-chip[data-filter="all"]::before {
  display: none;
}

.filter-chip.status-red::before {
  background: var(--red);
}

.filter-chip.status-week::before {
  background: var(--amber);
}

.filter-chip.status-scheduled::before {
  background: var(--green);
}

.filter-chip.active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface-soft);
}

.needs-task {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  padding: 0.25rem 0.7rem;
  border-color: #aaa397;
  color: #635f57;
  background: #ebe7de;
}

.needs-task > span {
  display: grid;
  width: 1.15rem;
  height: 1.15rem;
  place-items: center;
  border-radius: 50%;
  color: var(--surface);
  background: #6d6960;
  font-weight: 700;
}

.needs-task:disabled {
  opacity: 0.35;
  cursor: default;
}

.search-field input {
  width: 100%;
  padding: 0.55rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.search-field input::placeholder {
  color: #a19c92;
}

.account-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 3rem;
}

.account-row {
  display: grid;
  grid-template-columns: 0.7rem minmax(8rem, 1.2fr) minmax(8rem, 1fr) auto;
  gap: 0.85rem;
  align-items: center;
  width: 100%;
  min-height: 5.2rem;
  padding: 0 0.55rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  background: transparent;
}

.account-row:hover,
.account-row.selected {
  background: var(--surface-soft);
}

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

.status-dot.overdue,
.status-dot.today {
  background: var(--red);
}

.status-dot.week {
  background: var(--amber);
}

.status-dot.scheduled {
  background: var(--green);
}

.status-dot.none {
  border: 1px solid var(--gray);
  background: transparent;
}

.account-row.pulse .status-dot.overdue {
  animation: attention 900ms ease-out 1;
}

@keyframes attention {
  0% {
    box-shadow: 0 0 0 0 rgb(169 81 66 / 45%);
  }
  100% {
    box-shadow: 0 0 0 0.65rem rgb(169 81 66 / 0%);
  }
}

.account-name,
.detail-title {
  overflow: hidden;
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-name {
  font-size: 1.25rem;
}

.task-summary,
.due-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.due-label {
  justify-self: end;
}

.due-label.overdue,
.due-label.today,
.due-label.week {
  padding: 0.35rem 0.55rem;
  border-radius: 0.3rem;
}

.due-label.overdue,
.due-label.today {
  color: var(--red);
  background: var(--red-soft);
}

.due-label.week {
  color: #87661e;
  background: var(--amber-soft);
}

.empty-list,
.loading-state {
  padding: 3rem 0;
  color: var(--muted);
  text-align: center;
}

.panel-footer {
  display: flex;
  justify-content: space-between;
  padding: 0.8rem 3rem;
  border-top: 1px solid var(--line);
  font-size: 0.83rem;
}

.detail-panel {
  overflow-y: auto;
}

.detail-empty {
  display: grid;
  min-height: 100%;
  place-content: center;
  color: var(--muted);
  text-align: center;
}

.detail-empty p {
  margin: 0 0 0.35rem;
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.6rem;
}

.detail-empty span {
  font-size: 0.85rem;
}

.detail-content {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  padding: 3rem 3.3rem 1.2rem;
}

.mobile-back {
  display: none;
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.detail-title {
  font-size: clamp(2.4rem, 4vw, 3.5rem);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.7rem 0 1.4rem;
  color: var(--muted);
}

.current-task {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  background: rgb(255 255 255 / 20%);
}

.current-task p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-actions,
.contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.quiet-button,
.primary,
.contact-chip {
  min-height: 2.4rem;
  padding: 0.48rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: transparent;
}

.primary {
  border-color: var(--ink);
  color: var(--surface);
  background: var(--ink);
}

.contact-row {
  margin: 1.1rem 0 1.5rem;
}

.contact-chip {
  background: rgb(255 255 255 / 25%);
}

.history {
  border-top: 1px solid var(--line);
}

.timeline-entry {
  position: relative;
  padding: 1.45rem 0;
  border-bottom: 1px solid var(--line);
}

.timeline-entry time {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.timeline-entry p {
  margin: 0.42rem 3rem 0 0;
  line-height: 1.55;
  white-space: pre-wrap;
}

.entry-kind {
  margin-left: 0.5rem;
  color: var(--green);
  font-size: 0.72rem;
}

.entry-edit {
  position: absolute;
  top: 1.25rem;
  right: 0;
}

.add-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.7rem;
  align-items: end;
  margin-top: auto;
  padding-top: 1.5rem;
}

.add-entry textarea {
  min-height: 2.5rem;
  resize: vertical;
  border: 0;
  border-bottom: 1px solid var(--muted);
  background: transparent;
}

.add-entry input[type="date"] {
  width: 8.5rem;
  padding: 0.5rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.detail-danger {
  margin-top: 1.5rem;
  color: var(--muted);
  text-align: right;
}

.danger-link {
  padding: 0.35rem;
  color: var(--red);
}

.soft-dialog {
  width: min(32rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1.2rem 4rem rgb(40 39 33 / 18%);
}

.soft-dialog::backdrop {
  background: rgb(40 39 33 / 28%);
  backdrop-filter: blur(2px);
}

.dialog-form {
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
}

.dialog-form header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.icon-close {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--muted);
  font-size: 1.5rem;
}

.dialog-form label,
.form-stack label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.dialog-form input,
.dialog-form textarea,
.form-stack input {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.2rem;
  background: #fffdf8;
}

.dialog-form textarea {
  min-height: 6rem;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.action-spacer {
  flex: 1;
}

.form-error {
  min-height: 1.2rem;
  margin: 0;
  color: var(--red);
  font-size: 0.84rem;
}

.quiet {
  color: var(--muted);
}

.toast {
  position: fixed;
  z-index: 110;
  right: 1.5rem;
  bottom: 1.5rem;
  max-width: 24rem;
  padding: 0.7rem 1rem;
  color: var(--surface);
  background: var(--ink);
  opacity: 0;
  transform: translateY(1rem);
  transition: 160ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(27rem, 100%);
  padding: 3rem;
  border: 1px solid var(--line);
  background: var(--surface);
}

.login-card h1 {
  font-size: 2.7rem;
}

.form-stack {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

@media (max-width: 900px) {
  .ledger-shell {
    display: block;
    height: 100dvh;
    padding: 0;
  }

  .account-panel,
  .detail-panel {
    height: 100dvh;
    border: 0;
  }

  .detail-panel {
    display: none;
  }

  body.detail-open .account-panel {
    display: none;
  }

  body.detail-open .detail-panel {
    display: block;
  }

  .mobile-back {
    display: inline-flex;
    margin: 0 0 1rem -0.4rem;
  }

  .panel-header,
  .filters,
  .account-list,
  .panel-footer {
    padding-right: 1.2rem;
    padding-left: 1.2rem;
  }

  .panel-header {
    padding-top: 1.5rem;
  }

  .detail-content {
    padding: 1.2rem;
  }

  .detail-title {
    white-space: normal;
  }

  .account-row {
    grid-template-columns: 0.7rem minmax(7rem, 1fr) auto;
    min-height: 4.8rem;
  }

  .task-summary {
    display: none;
  }
}

@media (max-width: 560px) {
  .filter-row {
    flex-wrap: wrap;
  }

  .needs-task {
    order: -1;
    width: 100%;
    margin-left: 0;
    justify-content: center;
  }

  .current-task {
    align-items: flex-start;
    flex-direction: column;
  }

  .current-task p {
    white-space: normal;
  }

  .add-entry {
    grid-template-columns: 1fr auto;
  }

  .add-entry textarea {
    grid-column: 1 / -1;
  }

  .dialog-actions.split {
    align-items: stretch;
    flex-direction: column-reverse;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
