dialog {
  width: min(94vw, 620px);
  max-height: 90vh;
  overflow: auto;
  padding: 0;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 30px 90px rgb(17 39 33 / 28%);
}

dialog::backdrop {
  background: rgb(15 36 30 / 56%);
  backdrop-filter: blur(3px);
}

dialog form {
  padding: 1.4rem;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.dialog-description {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.entry-dialog-heading {
  margin: 0;
  padding: 1.4rem 1.4rem 1rem;
}

.entry-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0 1.4rem;
  border-bottom: 1px solid var(--line);
}

.entry-tab {
  position: relative;
  min-height: 2.7rem;
  padding: 0.6rem 0.85rem;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.entry-tab::after {
  position: absolute;
  right: 0.5rem;
  bottom: -1px;
  left: 0.5rem;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
  content: "";
}

.entry-tab[aria-selected="true"] {
  color: var(--green);
}

.entry-tab[aria-selected="true"]::after {
  background: var(--green);
}

.entry-tab:hover {
  color: var(--ink);
}

.panel-title {
  margin: 0 0 1rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 500;
}

.form-note {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

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

.field {
  display: grid;
  align-content: start;
  gap: 0.4rem;
  min-width: 0;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 750;
}

.field--wide {
  grid-column: 1 / -1;
}

.field small {
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select,
.money-input {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid #bdc8c2;
  border-radius: 0.55rem;
  background: white;
}

.field input,
.field select {
  padding: 0.65rem 0.7rem;
}

.money-input {
  display: flex;
  align-items: center;
  padding-left: 0.7rem;
  color: var(--muted);
}

.money-input input {
  min-width: 0;
  border: 0;
  background: transparent;
  outline: 0;
}

.check-field {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.9rem;
  border-radius: 0.7rem;
  background: var(--green-soft);
}

label.check-field,
.check-field label {
  cursor: pointer;
}

.check-field input {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.15rem;
  accent-color: var(--green);
}

.check-field > span,
.check-field > div,
.check-field small {
  display: block;
}

.check-field small {
  margin-top: 0.15rem;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.5rem;
}

.dialog-actions--split {
  flex-wrap: wrap;
}

.action-spacer {
  flex: 1;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  color: white;
  border-radius: 0.65rem;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.75rem);
  transition: 160ms ease;
}

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

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

[hidden] {
  display: none !important;
}

.app-tools {
  margin-block: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--muted);
  border-radius: 0.75rem;
  overflow-wrap: anywhere;
}

.app-tools .button {
  min-height: 44px;
  margin: 0.25rem;
}

.app-tools summary {
  cursor: pointer;
  padding-block: 0.75rem;
}

.app-tools label {
  display: block;
  margin-block: 0.75rem 0.35rem;
}

.app-tools dialog {
  padding: 1.4rem;
}

#storage-error {
  margin: 1rem;
  padding: 1rem;
  border: 2px solid #a33;
  background: #fff4f4;
  color: #5d1717;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

dialog {
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.day-count {
  display: none;
}

.calendar td.is-selected {
  background: var(--green-soft);
}

.day-number[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px var(--green);
}

.selected-day {
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.selected-day h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.selected-day-items {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.selected-day .occurrence {
  min-height: 44px;
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  padding: 0.65rem;
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    padding-top: 1.4rem;
  }

  .calendar th {
    padding: 0.4rem 0;
    letter-spacing: 0;
    font-size: 0.65rem;
  }

  .calendar td {
    height: auto;
    padding: 1px;
  }

  .calendar .day-items {
    display: none;
  }

  .day-number {
    width: 100%;
    min-width: 0;
    min-height: 64px;
    margin: 0;
    align-content: center;
    gap: 0.2rem;
  }

  .day-count {
    display: block;
    font-size: 0.6rem;
    font-weight: 500;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .summary-card--due {
    grid-column: 1 / -1;
  }

  .schedule-panel {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .wide-day {
    display: none;
  }

  .short-day {
    display: inline;
  }
}

@media (max-width: 520px) {
  .app-header,
  main {
    width: min(100% - 1rem, 1460px);
  }

  .calendar-toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem;
  }

  .month-navigation {
    flex: 1 1 auto;
    justify-content: space-between;
  }

  .month-navigation {
    gap: 0.4rem;
  }

  .month-navigation h2 {
    min-width: 8.5rem;
    font-size: 1.3rem;
  }

  .calendar-hint {
    padding: 0 0.75rem 0.75rem;
    font-size: 0.75rem;
  }

  .summary-card {
    padding: 1rem;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-card--due {
    grid-column: auto;
  }

  .app-header {
    display: grid;
  }

  .header-actions {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field--wide {
    grid-column: auto;
  }

  .dialog-actions .button {
    flex: 1 1 auto;
  }

  .dialog-actions--split .button--danger {
    flex-basis: 100%;
  }
}

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