/* Summary, bill list, agenda, dialog. */

/* --- summary -------------------------------------------------------------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--stat-min), 1fr));
  gap: var(--space-4) var(--space-5);
  padding: var(--space-4);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat__label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.stat__value {
  font-size: var(--text-xl);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat__value--danger {
  color: var(--danger);
}

.stat__value--ok {
  color: var(--ok);
}

.stat__note {
  font-size: var(--text-xs);
  color: var(--text-dim);
}

/* --- segmented control ---------------------------------------------------- */

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.segmented__option {
  border: 0;
  background: transparent;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: var(--text-xs);
  cursor: pointer;
  color: var(--text-dim);
}

.segmented__option.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* --- bill list ------------------------------------------------------------ */

.bill-list,
.agenda {
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 26rem;
  overflow-y: auto;
}

.bill {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}

.bill:hover {
  background: var(--surface-2);
}

.bill__bar {
  align-self: stretch;
  border-radius: 999px;
  background: var(--muted);
  min-height: 2rem;
}

.bill__body {
  min-width: 0;
}

/*
 * display:block matters here. These are <span>s, and text-overflow:ellipsis is
 * ignored on inline boxes - a long payee name then pushed straight through the
 * amount column instead of truncating.
 */
.bill__name {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bill__meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bill__meta--overdue {
  color: var(--danger);
  font-weight: 650;
}

.bill__amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.bill__amount--unknown {
  color: var(--text-faint);
  font-weight: 400;
  font-style: italic;
}

.bill--paid .bill__name {
  text-decoration: line-through;
  color: var(--text-dim);
}

.bill--paid {
  opacity: 0.65;
}

.badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 0 0.4em;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 650;
  background: var(--warn-soft);
  color: var(--warn);
  vertical-align: 1px;
}

.badge--autopay {
  background: var(--accent-soft);
  color: var(--accent);
}

/* --- agenda --------------------------------------------------------------- */

.agenda__item {
  display: grid;
  grid-template-columns: 3.75rem 1fr auto;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}

.agenda__item:hover {
  background: var(--surface-2);
}

.agenda__when {
  font-size: var(--text-xs);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

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

.agenda__sub {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.agenda__amount {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--text-dim);
}

.agenda__day-heading {
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.empty {
  padding: var(--space-5);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
}

/* --- dialog --------------------------------------------------------------- */

.sheet {
  width: min(30rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.sheet::backdrop {
  background: rgba(8, 12, 20, 0.55);
  backdrop-filter: blur(2px);
}

.sheet__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  margin: 0;
}

.sheet__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.sheet__swatch {
  flex: none;
  width: 10px;
  height: 2.5rem;
  border-radius: 999px;
  background: var(--muted);
}

.sheet__subtitle {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  color: var(--text-dim);
}

.sheet__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: var(--text-sm);
}

.sheet__facts dt {
  color: var(--text-dim);
}

.sheet__facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sheet__error {
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
}

.sheet__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-size: var(--text-sm);
  color: var(--text-dim);
}

.field__label em {
  font-style: normal;
  color: var(--text-faint);
}

.field__input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.button {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
}

.button:hover {
  background: var(--surface-3);
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button--primary:hover {
  filter: brightness(1.08);
}

.button--secondary {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: var(--accent);
}

.button--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.button--ghost:hover {
  background: var(--surface-2);
}

.button[hidden] {
  display: none;
}

@media (max-width: 720px) {
  .bill-list,
  .agenda {
    max-height: none;
  }

  .sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

/* ===========================================================================
   Widget frame
   =========================================================================== */

.widget {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 120ms ease, opacity 120ms ease;
}

.widget--dragging {
  opacity: 0.4;
}

.widget--drop-target {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.widget__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.widget__title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}

.widget__extras {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  overflow: hidden;
}

.widget__controls {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.widget:hover .widget__controls,
.widget:focus-within .widget__controls {
  opacity: 1;
}

/* Touch has no hover, so the controls are always there - but the drag handle
   is not, because HTML5 drag does not fire from a finger. Long-press gives the
   same operations through the context menu. */
:root[data-pointer="coarse"] .widget__controls {
  opacity: 1;
}

:root[data-pointer="coarse"] .widget__drag {
  display: none;
}

.widget__control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: var(--text-base);
  line-height: 1;
}

.widget__control:hover {
  background: var(--surface-3);
  color: var(--text);
}

.widget__drag {
  cursor: grab;
}

.widget__drag:active {
  cursor: grabbing;
}

.widget__body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--space-2);
}

/* Inside a sized widget, inner lists scroll with the body rather than
   imposing their own height. */
.widget__body .bill-list,
.widget__body .agenda {
  max-height: none;
  padding: 0;
}

.widget__body .summary {
  padding: var(--space-2);
}

.widget__body .week-strip {
  padding: 0;
}

.widget__body .calendar {
  height: 100%;
}

.inline-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.inline-nav__label {
  font-size: var(--text-sm);
  font-weight: 650;
  min-width: 9ch;
  text-align: center;
}

/* ===========================================================================
   Context menu
   =========================================================================== */

.menu {
  position: fixed;
  z-index: 100;
  min-width: 12rem;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.menu[hidden] {
  display: none;
}

.menu__item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: var(--text-sm);
}

.menu__item:hover:not(:disabled) {
  background: var(--surface-2);
}

.menu__item:disabled {
  opacity: 0.35;
  cursor: default;
}

.menu__item--danger {
  color: var(--danger);
}

.menu__separator {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--border);
}

.menu__heading {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

/* ===========================================================================
   Day panel
   =========================================================================== */

.day-panel__heading {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 650;
}

.day-panel__section {
  margin: var(--space-3) 0 var(--space-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.day-panel__section:first-child {
  margin-top: 0;
}

.day-panel__section--alert {
  color: var(--danger);
}

.day-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.day-nav__label {
  flex: 1;
  font-weight: 650;
  font-size: var(--text-sm);
}

.day-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  min-width: 0;
}

.day-row:hover {
  background: var(--surface-2);
}

.day-row__check {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.day-row__swatch {
  flex: none;
  width: 4px;
  align-self: stretch;
  min-height: 1.75rem;
  border-radius: 999px;
  background: var(--muted);
}

.day-row__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: var(--space-1) 0;
}

.day-row__title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
}

.day-row__meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-row__trailing {
  flex: none;
  font-size: var(--text-xs);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.day-row--done .day-row__title {
  text-decoration: line-through;
  color: var(--text-faint);
}

.day-row--alert .day-row__title {
  color: var(--danger);
}

/* ===========================================================================
   Manage lists
   =========================================================================== */

.list-heading {
  margin: var(--space-3) 0 var(--space-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.list-heading:first-child {
  margin-top: 0;
}

.manage-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.manage-row:hover {
  background: var(--surface-2);
}

.manage-row--muted {
  opacity: 0.55;
}

.manage-row__swatch {
  flex: none;
  width: 4px;
  align-self: stretch;
  min-height: 1.75rem;
  border-radius: 999px;
}

.manage-row__body {
  flex: 1;
  min-width: 0;
}

.manage-row__title {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-row__meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-row__action {
  flex: none;
  font-size: var(--text-xs);
  color: var(--accent);
}

/* ===========================================================================
   Table
   =========================================================================== */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-2);
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table__row {
  cursor: pointer;
}

.table__row:hover {
  background: var(--surface-2);
}

.table__row--muted {
  opacity: 0.6;
}

.table__number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table__number--unknown {
  color: var(--text-faint);
  font-style: italic;
}

.table__swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: 1px;
}

.table__sub {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.pill {
  display: inline-block;
  padding: 1px 0.5em;
  border-radius: 999px;
  font-size: var(--text-xs);
  background: var(--surface-3);
  color: var(--text-dim);
  white-space: nowrap;
}

.pill--overdue {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 650;
}

.pill--paid,
.pill--cleared {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill--partial {
  background: var(--warn-soft);
  color: var(--warn);
}

@media (max-width: 720px) {
  .table__hide-narrow {
    display: none;
  }
}

/* ===========================================================================
   Category breakdown + placeholders
   =========================================================================== */

.breakdown {
  padding: var(--space-2);
}

.breakdown__head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.breakdown__value {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.breakdown__track {
  height: 6px;
  margin: 4px 0 2px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.breakdown__bar {
  height: 100%;
  border-radius: 999px;
}

.breakdown__count {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.placeholder {
  padding: var(--space-4);
  color: var(--text-dim);
}

.placeholder__title {
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
  color: var(--text);
}

.placeholder__body {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  max-width: 60ch;
}

.placeholder__steps {
  margin: 0;
  padding-left: 1.2em;
  font-size: var(--text-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* ===========================================================================
   Forms + settings
   =========================================================================== */

.sheet--wide {
  width: min(46rem, calc(100vw - 2rem));
}

.sheet__spacer {
  flex: 1;
}

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

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

.field--inline {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.field__checkbox {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.field[hidden] {
  display: none;
}

.button--danger {
  color: var(--danger);
}

.button--armed {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.settings {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-height: min(60vh, 34rem);
  overflow-y: auto;
}

.settings__section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.settings__heading {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.settings__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.settings__warning {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--text-xs);
}

.chip-toggle {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: var(--text-sm);
}

.chip-toggle.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 650;
}

.settings__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.settings__label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-dim);
}

.settings__value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 650;
}

.settings__slider {
  width: 100%;
  accent-color: var(--accent);
}

.settings__widgets {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.settings__widget {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.settings__widget.is-hidden {
  opacity: 0.5;
}

.settings__widget-name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: var(--text-sm);
  cursor: pointer;
}

.settings__widget-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

.settings__more summary {
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--accent);
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stepper__button {
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  background: var(--surface);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1;
}

.stepper__button:hover:not(:disabled) {
  background: var(--surface-3);
}

.stepper__button:disabled {
  opacity: 0.35;
  cursor: default;
}

.stepper__value {
  min-width: 2.4rem;
  text-align: center;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings__widget {
    flex-wrap: wrap;
  }
}

/*
 * The calendar is a fixed 6x7 shape, so inside a sized widget it divides the
 * space it is given rather than overflowing it. Without this the last week of
 * the month sat below the fold of its own widget and had to be scrolled to.
 */
.widget[data-widget="calendar"] .widget__body {
  overflow: hidden;
}

.widget[data-widget="calendar"] .calendar__grid {
  flex: 1;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
}

.widget[data-widget="weekStrip"] .widget__body {
  overflow: hidden;
}

/* Narrow widgets: let the header wrap rather than clipping the month label. */
@media (max-width: 900px) {
  .widget__header {
    flex-wrap: wrap;
  }

  .widget__extras {
    justify-content: flex-start;
  }

  .inline-nav__label {
    min-width: 0;
  }
}
