/* ── MD3 Dark Theme Tokens ── */
:root {
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;
  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;
  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8c1d18;
  --md-sys-color-surface: #1c1b1f;
  --md-sys-color-surface-variant: #49454f;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;
  --md-sys-color-on-surface: #e6e1e5;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;
  --md-sys-color-positive: #6fcf97;
  --md-sys-color-negative: #f2b8b5;

  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;

  --font: 'Space Mono', 'Courier New', monospace;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
  grid-template-columns: 80px 1fr;
  grid-template-areas:
    "header header"
    "nav    main";
}

.hidden { display: none !important; }

/* ── Top App Bar ── */
.top-app-bar {
  grid-area: header;
  background: var(--md-sys-color-surface-container);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: .75rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-app-bar__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--md-sys-color-on-surface);
  flex: 1;
}

.top-app-bar__actions {
  display: flex;
  gap: .5rem;
  align-items: center;
}

/* ── Navigation Rail ── */
.nav-rail {
  grid-area: nav;
  background: var(--md-sys-color-surface-container);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
  gap: .5rem;
  border-right: 1px solid var(--md-sys-color-outline-variant);
}

.nav-rail__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: .5rem;
  width: 72px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-large);
  transition: background .15s, color .15s;
  font-family: var(--font);
  font-size: .625rem;
  letter-spacing: .04em;
}

.nav-rail__item:hover { background: rgba(208,188,255,.08); }
.nav-rail__item.active { color: var(--md-sys-color-on-secondary-container); }

.nav-rail__item.active .nav-rail__icon {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.nav-rail__icon {
  width: 56px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  transition: background .15s;
}

.nav-rail__label { font-size: .625rem; text-transform: uppercase; letter-spacing: .06em; }

/* ── Main Content ── */
.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 1.5rem;
}

.view { display: flex; flex-direction: column; gap: 1.25rem; }
.view.active { display: flex; }
.view.hidden { display: none !important; }

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--md-sys-color-on-surface);
}

/* ── FAB ── */
.fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  padding: .875rem 1.25rem;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
  letter-spacing: .04em;
  position: relative;
}
.fab:hover { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }

/* Icon-only FAB — shows tooltip on hover via data-label */
.fab--icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}
.fab--icon::after {
  content: attr(data-label);
  position: absolute;
  right: calc(100% + .5rem);
  top: 50%;
  transform: translateY(-50%);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
  padding: .25rem .625rem;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline-variant);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.fab--icon:hover::after { opacity: 1; }

.fab--small {
  width: 40px;
  height: 40px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

/* spacing wrapper so FAB doesn't sit directly against list */
.tab-panel__actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

/* ── Card Grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ── Surface Card ── */
.surface-card {
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.card-title {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  margin-bottom: .75rem;
  letter-spacing: .02em;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header-row .card-title { margin-bottom: 0; }
.card-total {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
}

/* Event card (clickable) */
.event-card {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.event-card:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-highest);
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.event-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.event-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.event-card__name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  flex: 1;
}
.event-card__actions {
  display: flex;
  gap: .25rem;
  flex-shrink: 0;
}
.event-card__footer {
  display: flex;
  justify-content: center;
  gap: .5rem;
  padding-top: .75rem;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin-top: .5rem;
}
.event-card__meta {
  font-size: .75rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
}
.event-card__badge {
  display: inline-block;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-radius: 99px;
  padding: .125rem .6rem;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .05em;
}

/* Settled event card */
.event-card--settled {
  opacity: .5;
  position: relative;
}
.event-card--settled:hover { opacity: .7; }
.event-card__check {
  position: absolute;
  bottom: .625rem;
  right: .75rem;
  color: var(--md-sys-color-positive);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Event group headers & divider */
.events-groups {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.event-group {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.event-group__title {
  font-size: .8125rem;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--md-sys-color-on-surface-variant);
  padding: .75rem 1rem;
  margin: 0 -1rem;
  border-bottom: none;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium, 12px);
}
.event-group__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* small icon-only action button (edit/delete on cards and expense rows) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--md-sys-shape-corner-small);
  cursor: pointer;
  transition: background .15s, color .15s;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
  position: relative;
}
.btn-icon:hover { background: rgba(230,225,229,.1); color: var(--md-sys-color-on-surface); }
.btn-icon--danger:hover { background: rgba(242,184,181,.12); color: var(--md-sys-color-error); }
.btn-icon--edit:hover  { background: rgba(208,188,255,.12); color: var(--md-sys-color-primary); }

/* tooltip via data-label */
.btn-icon[data-label]::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + .375rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  font-size: .6875rem;
  font-family: var(--font);
  white-space: nowrap;
  padding: .2rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--md-sys-color-outline-variant);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 10;
}
.btn-icon[data-label]:hover::after { opacity: 1; }

/* ── Participant Card (legacy alias) / Person Card ── */
.participant-card,
.person-card {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  align-items: center;
  gap: .875rem;
}
.participant-card:hover,
.person-card:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-highest);
}
.participant-card--inactive,
.person-card--inactive {
  opacity: .55;
}
.participant-card__avatar,
.person-card__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  flex-shrink: 0;
}
.participant-card--inactive .participant-card__avatar,
.person-card--inactive .person-card__avatar {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}
.participant-card__body,
.person-card__body { flex: 1; min-width: 0; }
.participant-card__name,
.person-card__name { font-size: .9375rem; font-weight: 700; }
.participant-card__meta,
.person-card__meta { font-size: .75rem; color: var(--md-sys-color-on-surface-variant); margin-top: .125rem; }

/* Event links in person card */
.person-event-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.person-event-link:hover { text-decoration: underline; }
.person-event-link--settled {
  opacity: .45;
}
.participant-card__actions,
.person-card__actions { display: flex; gap: .25rem; flex-shrink: 0; }

.person-card__rep {
  font-size: .6875rem;
  color: var(--md-sys-color-outline);
  margin-top: .25rem;
  font-style: italic;
}

/* Group connector lines in summary table */
.group-connector {
  display: inline-block;
  width: 1rem;
  height: 100%;
  position: relative;
  vertical-align: middle;
}
/* Solo — just invisible spacer for indentation */
.group-connector--solo {
  /* empty space, same width as grouped connectors */
}
/* First in group: vertical line from middle down to bottom edge, horizontal to right */
.group-connector--first::before {
  content: '';
  position: absolute;
  left: .4rem;
  top: 0.1rem;
  bottom: -0.9rem;
  width: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
.group-connector--first::after {
  content: '';
  position: absolute;
  left: .4rem;
  top: 50%;
  width: .4rem;
  height: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
/* Middle in group: vertical line full height, horizontal to right */
.group-connector--mid::before {
  content: '';
  position: absolute;
  left: .4rem;
  top: -1.1rem;
  bottom: -0.9rem;
  width: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
.group-connector--mid::after {
  content: '';
  position: absolute;
  left: .5rem;
  top: 50%;
  width: .3rem;
  height: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
/* Last in group: vertical line from top edge to middle, horizontal to right */
.group-connector--last::before {
  content: '';
  position: absolute;
  left: .4rem;
  top: -1.1rem;
  bottom: 50%;
  width: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
.group-connector--last::after {
  content: '';
  position: absolute;
  left: .4rem;
  top: 50%;
  width: .4rem;
  height: 1.5px;
  background: var(--md-sys-color-outline);
  opacity: .5;
}
/* Group config dialog */
.group-config-item {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: .75rem;
  margin-bottom: .75rem;
}
.group-config-item__header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.group-config-item__icon { font-size: 1.25rem; }
.group-config-item__label {
  font-size: .8125rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  flex: 1;
}
.group-config-item__remove {
  width: 24px;
  height: 24px;
  font-size: 1rem;
}
.group-config-item__members {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}

/* status pill */
.status-pill {
  display: inline-block;
  font-size: .625rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .125rem .5rem;
  border-radius: 99px;
}
.status-pill--active {
  background: rgba(111,207,151,.15);
  color: var(--md-sys-color-positive);
  border: 1px solid rgba(111,207,151,.3);
}
.status-pill--inactive {
  background: rgba(255,255,255,.05);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
}

/* ── Toggle switch ── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
  cursor: pointer;
  user-select: none;
}
.toggle-row__label { font-size: .9375rem; color: var(--md-sys-color-on-surface); }
.toggle { position: relative; }
.toggle input[type=checkbox] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle__track {
  display: block;
  width: 52px;
  height: 28px;
  background: var(--md-sys-color-surface-variant);
  border-radius: 14px;
  border: 2px solid var(--md-sys-color-outline);
  transition: background .2s, border-color .2s;
  position: relative;
}
.toggle input:checked ~ .toggle__track {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}
.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: transform .2s, background .2s, width .2s, height .2s, top .2s, left .2s;
}
.toggle input:checked ~ .toggle__track .toggle__thumb {
  transform: translateX(24px);
  background: var(--md-sys-color-on-primary);
  width: 24px;
  height: 24px;
  top: 0;
  left: 0;
}

/* ── Tabs ── */
.tabs-bar {
  display: flex;
  gap: .25rem;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: .25rem;
  flex-wrap: wrap;
}

.tab {
  flex: 1;
  min-width: max-content;
  padding: .5rem 1rem;
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-small);
  font-family: var(--font);
  font-size: .8125rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background .15s, color .15s;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.tab:hover { background: rgba(208,188,255,.08); }
.tab.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tab-panel { padding-top: 1rem; }

.event-detail-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
}
.event-detail-toolbar .fab--icon::after {
  right: auto;
  left: 50%;
  top: auto;
  bottom: calc(100% + .5rem);
  transform: translateX(-50%);
}

/* ── Form Fields ── */
.field {
  display: flex;
  flex-direction: column;
  gap: .375rem;
  margin-bottom: 1rem;
}
.field--inline {
  flex-direction: row;
  align-items: center;
  gap: .75rem;
}
.field--inline .field__input { flex: 1; }

.field__label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.field__hint {
  font-size: .75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.field__row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
}
.field__col { flex: 1; }
.field__checkbox-inline {
  display: flex;
  align-items: center;
  gap: .375rem;
  cursor: pointer;
  font-size: .8125rem;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  padding-bottom: .625rem;
  user-select: none;
}
.field__checkbox-inline input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--md-sys-color-primary);
}

.field__input,
.field__select {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  padding: .625rem .875rem;
  font-family: var(--font);
  font-size: .9375rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  -moz-appearance: textfield;
}
.field__input:focus,
.field__select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(208,188,255,.25);
}
/* Hide number input spinners globally */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* error state */
.field__input.error { border-color: var(--md-sys-color-error); }
.field__error {
  font-size: .75rem;
  color: var(--md-sys-color-error);
  margin-top: .125rem;
}

/* ── Checkbox list ── */
.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  max-height: 180px;
  overflow-y: auto;
  padding: .5rem;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline);
}
.checkbox-chip {
  display: flex;
  align-items: center;
  gap: .375rem;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 99px;
  padding: .25rem .75rem;
  cursor: pointer;
  font-size: .8125rem;
  font-family: var(--font);
  color: var(--md-sys-color-on-surface);
  transition: background .15s, border-color .15s;
  user-select: none;
}
.checkbox-chip input[type=checkbox] { accent-color: var(--md-sys-color-primary); }
.checkbox-chip.selected {
  background: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary-container);
}
.checkbox-chip input:disabled { opacity: .5; cursor: not-allowed; }
.chip-lock-icon { font-size: .7rem; opacity: .7; }

/* ── Buttons ── */
.btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: .625rem 1.5rem;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .04em;
}
.btn-filled:hover { background: #b69fef; }

.btn-tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: .625rem 1.5rem;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .04em;
}
.btn-tonal:hover { background: var(--md-sys-color-outline-variant); }

.btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: .625rem 1rem;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .04em;
}
.btn-text:hover { background: rgba(208,188,255,.1); }

.btn-danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: .375rem .875rem;
  font-family: var(--font);
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger:hover { background: #601410; }

/* btn-edit kept for potential future use; icon buttons replace it in expense list */
.btn-edit {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: .375rem .875rem;
  font-family: var(--font);
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-edit:hover { background: var(--md-sys-color-outline-variant); }

.btn-sm { padding: .375rem .875rem; font-size: .8125rem; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(230,225,229,.12); }

/* ── Item List ── */
.item-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.state-empty {
  color: var(--md-sys-color-on-surface-variant);
  font-size: .875rem;
  text-align: center;
  padding: 2rem 0;
}

/* Expense item */
.expense-item {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: .875rem 1.125rem;
  display: flex;
  flex-direction: column;
  gap: .625rem;
  transition: border-color .15s;
}
.expense-item:hover { border-color: var(--md-sys-color-outline); }

/* top row: description + amount + action buttons */
.expense-item__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .75rem;
}
.expense-item__desc {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  flex: 1;
}
.expense-item__right {
  display: flex;
  align-items: center;
  gap: .375rem;
  flex-shrink: 0;
}
.expense-item__amount {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}
.expense-item__actions { display: flex; gap: .25rem; }

/* meta row: payer · date · split type */
.expense-item__meta {
  font-size: .75rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
}

/* splits: full-width wrap */
.expense-item__splits {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}
.split-chip {
  font-size: .6875rem;
  background: var(--md-sys-color-surface-container-highest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 99px;
  padding: .2rem .625rem;
  color: var(--md-sys-color-on-surface-variant);
  flex: 0 0 auto;
  max-width: 100%;
}
.split-chip--zero {
  opacity: .4;
}



/* Color utilities */
.positive { color: var(--md-sys-color-positive); }
.negative { color: var(--md-sys-color-negative); }
.neutral  { color: var(--md-sys-color-on-surface-variant); }

/* Member item */
.member-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .625rem .5rem;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: .9375rem;
}
.member-item:nth-child(odd) { background: rgba(255,255,255,.03); }

/* Participant event row */
.participant-event-row {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: .875rem 1.125rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .25rem .75rem;
}
.participant-event-row__name { font-size: .9375rem; font-weight: 700; }
.participant-event-row__detail { font-size: .75rem; color: var(--md-sys-color-on-surface-variant); }
.participant-event-row__balance { font-size: .9375rem; font-weight: 700; text-align: right; }
.participant-event-row__costs  { font-size: .75rem; color: var(--md-sys-color-on-surface-variant); text-align: right; }

/* Total row */
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.total-label { font-size: .875rem; color: var(--md-sys-color-on-surface-variant); }
.total-value { font-size: 1.125rem; font-weight: 700; }

/* ── Dialog page ── */
.dialog-page {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

/* The card — flex column so header/footer are sticky, body scrolls */
.dialog-surface {
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-extra-large);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  overflow: hidden;           /* clip child corners */
}

/* Wide dialog for the expense form */
.dialog-surface--wide { max-width: 680px; }

/* Full-width dialog for summary */
.dialog-surface--full { max-width: 95vw; width: fit-content; max-height: 90vh; margin: auto; }
.dialog-surface--full .dialog-body { display: flex; flex-direction: column; align-items: center; }
.dialog-surface--full .dialog-header { justify-content: center; }
.dialog-surface--full .dialog-header .btn-icon { position: absolute; right: 1rem; }

/* Static header */
.dialog-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.75rem 1rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-high);
  position: relative;
}
.dialog-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  flex: 1;
  margin: 0;
}

/* Scrollable body */
.dialog-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.25rem 1.75rem;
  /* custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--md-sys-color-outline-variant) transparent;
}
.dialog-body::-webkit-scrollbar { width: 6px; }
.dialog-body::-webkit-scrollbar-track { background: transparent; }
.dialog-body::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline-variant);
  border-radius: 3px;
}

/* Static footer */
.dialog-actions {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1rem 1.75rem;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-high);
}

/* ── Custom Amounts split table ── */
.custom-split-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-bottom: 16px;
}
.custom-split-table th {
  text-align: left;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  padding: .25rem .5rem .5rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.custom-split-table th.col-cb  { width: 36px; text-align: center; }
.custom-split-table th.col-name { width: 1%; white-space: nowrap; }
.custom-split-table th.col-amt { width: 145px; }
.custom-split-table th.col-det { width: auto; }
.custom-split-table td.col-name { width: 1%; white-space: nowrap; }
.custom-split-table td.col-amt .field__input { text-align: right; }
.custom-split-table td.col-det .field__input { width: 100%; }

.custom-split-table td {
  padding: .2rem .5rem;
  vertical-align: middle;
}
.custom-split-table tr:not(:last-child) td {
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.custom-split-table tr.row--excluded td {
  opacity: .4;
}
.custom-split-table td.col-cb {
  text-align: center;
}
/* accent-color checkbox */
.custom-split-table input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
}
.custom-split-table .field__input {
  padding: .375rem .625rem;
  font-size: .875rem;
}
.person-name-cell {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

/* ── Split detail rows (split_even / custom_person hints) ── */
.split-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.split-row--custom {
  grid-template-columns: 1fr 110px;
}
.split-row__label {
  font-size: .875rem;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.split-row .field__input { width: 100%; }

/* live sum feedback in table footer */
.split-footer-row td {
  border-top: 1.5px solid var(--md-sys-color-outline-variant);
  padding-top: .5rem;
  vertical-align: middle;
}
.split-sum-value {
  font-weight: 700;
  font-size: .875rem;
  color: var(--md-sys-color-on-surface);
  display: block;
  text-align: right;
}
.split-sum-value--error {
  color: var(--md-sys-color-error, #f44) !important;
}
.split-sum-feedback {
  font-size: .65rem;
  color: var(--md-sys-color-on-surface-variant);
  display: block;
  text-align: right;
}
.split-sum-feedback--ok { color: var(--md-sys-color-positive); }
.split-sum-feedback--error { color: var(--md-sys-color-error, #f44); }

.hint-text {
  font-size: .8125rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: .75rem;
}

/* ── Summary Table ── */
.summary-table-wrap {
  overflow-x: auto;
  display: inline-block;
  max-width: 100%;
}
.summary-table {
  width: auto;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .8125rem;
  white-space: nowrap;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden;
}
/* Inner cell borders */
.summary-table th,
.summary-table td {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  border-right: 1px solid var(--md-sys-color-outline-variant);
}
.summary-table thead th {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.summary-table tfoot td {
  border-top: 1px solid var(--md-sys-color-outline-variant);
  border-bottom: none;
}
.summary-table thead {
  background: rgba(255,255,255,.04);
  position: sticky;
  top: 0;
}
.summary-th {
  padding: .5rem .9rem;
  text-align: center;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}
.summary-th__payer {
  display: block;
  font-size: .5625rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--md-sys-color-outline);
  margin-top: .125rem;
}
.summary-th--expense {
  cursor: pointer;
  transition: background .12s;
}
.summary-th--expense:hover {
  background: rgba(208,188,255,.08);
}
.summary-th--person {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 1;
}
.summary-th--total {
  background: rgba(255,255,255,.04);
}
.summary-td {
  padding: .5rem .9rem;
  text-align: right;
  color: var(--md-sys-color-on-surface);
}
.summary-td--person {
  text-align: left;
  font-weight: 700;
  position: relative;
  overflow: visible;
  background: rgba(255,255,255,.04);
}
.summary-td--zero { color: rgba(255,255,255,.35); }
/* Zero text only (keep background) */
.summary-td--zero-text { color: var(--md-sys-color-outline); }
/* Negative amounts (paid upfront / net negative) — green */
.summary-td--negative { color: var(--md-sys-color-positive); font-weight: 700; }
.summary-td--total {
  font-weight: 700;
  background: rgba(255,255,255,.04);
}
.summary-td--grand {
  font-weight: 700;
  color: var(--md-sys-color-primary);
  background: rgba(255,255,255,.04);
}
.summary-td--group-net {
  vertical-align: middle;
  text-align: center;
  border-left: 1px solid rgba(255,255,255,.04);
}
.summary-td--clickable {
  cursor: pointer;
  transition: background .12s;
}
.summary-td--clickable:hover {
  background: rgba(208,188,255,.08) !important;
}
.summary-td--onthehouse {
  text-align: center;
  vertical-align: middle;
  background: var(--md-sys-color-surface-container);
  border-left: 1px solid var(--md-sys-color-outline-variant);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  padding: .5rem .25rem;
  width: 2.5rem;
}
.onthehouse-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-style: italic;
  font-size: .75rem;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}
.summary-table tfoot {
  background: rgba(255,255,255,.04);
}
#summary-tbody tr.profile-highlight td {
  background: var(--profile-highlight-bg);
}
#summary-tbody tr.profile-highlight .summary-td--person {
  color: var(--md-sys-color-on-surface);
}
#summary-tbody tr.summary-row--owed.profile-highlight .summary-td--person,
#summary-tbody tr.summary-row--owed.profile-highlight .summary-td--total {
  color: var(--md-sys-color-positive);
}
/* Owed rows — only name text is italic+green, not the icon */
.summary-row--owed .summary-td--person {
  color: var(--md-sys-color-positive);
}
.summary-row--owed .summary-person-name {
  font-style: italic;
}
/* Zero-total rows — settled style */
.summary-row--zero-total .summary-td--person,
.summary-row--zero-total .summary-td--total {
  color: var(--md-sys-color-positive);
}
/* Settled via checkbox */
.summary-row--settled .summary-td:not(.summary-td--person) {
  text-decoration: line-through;
  opacity: .5;
}

/* Round settle circle (inside Total cell) */
.settle-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--md-sys-color-outline);
  cursor: pointer;
  transition: none;
  opacity: .4;
  vertical-align: middle;
}

/* Settle column — same background as Total, no vertical border between them */
.summary-td--settle-col {
  border-left: none !important;
  padding-left: 0;
  text-align: center;
}
.settle-circle--checked {
  opacity: 1;
  border-color: var(--md-sys-color-positive);
  background: var(--md-sys-color-positive);
  color: var(--md-sys-color-surface);
}
.settle-circle--checked::after {
  content: '✓';
  font-size: .7rem;
  font-weight: 700;
}

/* ── Profile Switcher ── */
.profile-switcher {
  position: relative;
}

.profile-switcher__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .03em;
  border: 2px solid transparent;
  transition: border-color .15s, background .15s;
  user-select: none;
  flex-shrink: 0;
}
.profile-switcher__avatar:hover {
  border-color: var(--md-sys-color-primary);
}
/* When a profile is active — glow the avatar */
.profile-switcher__avatar.has-profile {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.profile-switcher__dropdown {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  background: var(--md-sys-color-surface-container-highest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
  min-width: 200px;
  z-index: 500;
  overflow: hidden;
}

.profile-dropdown__label {
  padding: .625rem 1rem .375rem;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.profile-dropdown__list {
  display: flex;
  flex-direction: column;
}

.profile-dropdown__item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .625rem 1rem;
  font-family: var(--font);
  font-size: .875rem;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  background: transparent;
  border: none;
  text-align: left;
  transition: background .12s;
}
.profile-dropdown__item:hover {
  background: rgba(208,188,255,.1);
}
.profile-dropdown__item.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 700;
}
.profile-dropdown__item-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .6875rem;
  font-weight: 700;
  flex-shrink: 0;
}
.profile-dropdown__item.active .profile-dropdown__item-avatar {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.profile-dropdown__divider {
  height: 1px;
  background: var(--md-sys-color-outline-variant);
  margin: .25rem 0;
}

.profile-dropdown__clear {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .625rem 1rem;
  font-family: var(--font);
  font-size: .875rem;
  color: var(--md-sys-color-error);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background .12s;
}
.profile-dropdown__clear:hover {
  background: rgba(242,184,181,.1);
}

/* ── Active Profile Highlight ── */
/* Highlight colour — vivid amber/gold that pops on the dark theme */
:root {
  --profile-highlight: #ffd166;
  --profile-highlight-bg: rgba(255,209,102,.12);
  --profile-highlight-border: rgba(255,209,102,.5);
}

/* Generic utility — any element with this class gets highlighted */
.profile-highlight {
  outline: none !important;
  outline-offset: -2px;
}

/* Person card in People grid */
.person-card.profile-highlight {
  background: var(--profile-highlight-bg) !important;
  border-color: var(--profile-highlight) !important;
  outline: none !important;
}
.person-card.profile-highlight .person-card__name,
.person-card.profile-highlight .person-card__avatar {
  color: var(--profile-highlight);
  font-weight: 700;
}
.person-card.profile-highlight .person-card__avatar {
  background: rgba(255,209,102,.2);
  border: 2px solid var(--profile-highlight);
}

/* Expense item — only highlight the payer name span, not the whole card */
.expense-item__payer.profile-highlight {
  color: var(--profile-highlight);
  font-weight: 700;
}

/* Split chip for the active person */
.split-chip.profile-highlight {
  background: rgba(255,209,102,.18) !important;
  border-color: var(--profile-highlight) !important;
  color: var(--profile-highlight) !important;
  font-weight: 700;
}

/* Balance item */
.balance-item.profile-highlight {
  border-color: var(--profile-highlight) !important;
  background: var(--profile-highlight-bg) !important;
}
.balance-item.profile-highlight .balance-item__name {
  color: var(--profile-highlight);
}

/* Custom split table row */
.custom-split-table tr.profile-highlight td {
  background: var(--profile-highlight-bg);
}
.custom-split-table tr.profile-highlight .person-name-cell {
  color: var(--profile-highlight);
  font-weight: 700;
}

/* ── Snackbar ── */
.snackbar {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  padding: .875rem 1.5rem;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: .9375rem;
  z-index: 999;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  max-width: 90vw;
  text-align: center;
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: opacity .3s;
  white-space: pre-wrap;
}
.snackbar.error { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); border-color: var(--md-sys-color-error); }
.snackbar.hidden { opacity: 0; pointer-events: none; }

/* ── Responsive ── */
@media (max-width: 600px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 64px 56px 1fr;
    grid-template-areas: "header" "nav" "main";
  }
  .nav-rail {
    flex-direction: row;
    justify-content: center;
    border-right: none;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    padding: .5rem 1rem;
    gap: 1rem;
  }
  .nav-rail__item { width: auto; flex-direction: row; gap: .5rem; }
  .nav-rail__icon { width: 36px; height: 36px; }
}

/* Remove border between Total amount and Settle checkbox cells */
.summary-td--total:has(+ .summary-td--settle-col) {
  border-right: none !important;
}

/* Expense detail modal fields */
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.detail-row:last-of-type { border-bottom: none; }
.detail-row__label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--md-sys-color-on-surface-variant);
}
.detail-row__value {
  font-size: .9375rem;
  color: var(--md-sys-color-on-surface);
  text-align: right;
}

/* Split detail table in modal */
.detail-split-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: .75rem;
  font-size: .875rem;
}
.detail-split-table th {
  text-align: left;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--md-sys-color-on-surface-variant);
  padding: .375rem .5rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.detail-split-table th:last-child { text-align: right; }
.detail-split-table td {
  padding: .375rem .5rem;
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.detail-split-table td:last-child { text-align: right; font-weight: 600; }

/* ── Login Page ── */
.login-page {
  position: fixed;
  inset: 0;
  background: var(--md-sys-color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-card {
  text-align: center;
  padding: 3rem 2.5rem;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  max-width: 360px;
  width: 100%;
}
.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  margin-bottom: .5rem;
}
.login-subtitle {
  font-size: .875rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 1.5rem;
}
.login-error {
  font-size: .8125rem;
  color: var(--md-sys-color-error);
  margin-top: 1rem;
}
#google-signin-btn {
  display: flex;
  justify-content: center;
}

/* ── Loading spinner — full content-area overlay ────────────────────────────── */
/*
 * #page-loader is a fixed overlay anchored to the same grid cell as
 * .main-content. It always renders the spinner dead-center in the
 * visible content area regardless of which container is loading.
 * JS shows/hides it via showPageLoader() / hidePageLoader().
 * The old per-container .loading-state/.loading-spinner classes are kept
 * for any edge-case inline use but are no longer used by setLoading().
 */
#page-loader {
  display: none;               /* hidden by default */
  position: fixed;
  /* align to the main content grid cell, not the full viewport */
  top: 4rem;                   /* below top-app-bar (~64px) */
  left: 5rem;                  /* right of nav-rail (~80px) */
  right: 0;
  bottom: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: .875rem;
  background: transparent;
  z-index: 200;
  pointer-events: none;        /* don't block clicks while loading */
  color: var(--md-sys-color-on-surface-variant);
  font-size: .875rem;
}
#page-loader.active {
  display: flex;
}
#page-loader .page-loader__spinner {
  width: 40px;
  height: 40px;
  border: 3.5px solid var(--md-sys-color-outline-variant);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: page-spin .7s linear infinite;
}
@keyframes page-spin {
  to { transform: rotate(360deg); }
}
#page-loader .page-loader__label {
  opacity: .75;
}

/* Legacy inline spinner — kept for backward compat but not used by setLoading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: .875rem;
  color: var(--md-sys-color-on-surface-variant);
  font-size: .875rem;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--md-sys-color-outline-variant);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: page-spin .7s linear infinite;
  flex-shrink: 0;
}
.loading-spinner--sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

/* ── Dev login form ─────────────────────────────────────────────────────────── */
#dev-login-form {
  width: 100%;
  text-align: left;
}
#dev-login-form .field__label {
  display: block;
  margin-bottom: .35rem;
}
#dev-login-form .field__input {
  width: 100%;
  box-sizing: border-box;
}
.dev-login-badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-tertiary-container);
  background: var(--md-sys-color-tertiary-container);
  border-radius: 999px;
  padding: .2rem .65rem;
  margin-bottom: 1rem;
}

/* ── Settings / Users Module ─────────────────────────────────────────────────── */

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.user-item:last-child { border-bottom: none; }
.user-item__info { flex: 1; min-width: 0; }
.user-item__name {
  font-weight: 700;
  font-size: .9rem;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.user-item__email {
  font-size: .8rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: .15rem;
}
.user-item__linked {
  margin-left: .5rem;
  font-style: italic;
  color: var(--md-sys-color-primary);
}
.user-item__meta {
  font-size: .75rem;
  color: var(--md-sys-color-outline);
  margin-top: .2rem;
}
.user-item__actions {
  display: flex;
  gap: .25rem;
  margin-left: .75rem;
}

/* Role pills */
.role-pill {
  display: inline-block;
  font-size: .65rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.role-pill--admin {
  background: rgba(208,188,255,.18);
  color: var(--md-sys-color-primary);
}
.role-pill--editor {
  background: rgba(204,194,220,.15);
  color: var(--md-sys-color-secondary);
}
.role-pill--viewer {
  background: rgba(255,255,255,.08);
  color: var(--md-sys-color-outline);
}

/* Verified badges */
.verified-badge {
  color: var(--md-sys-color-positive, #66bb6a);
  font-size: .8rem;
  font-weight: 700;
}
.unverified-badge {
  color: var(--md-sys-color-outline);
  font-size: .8rem;
}

/* ── File Upload & Attachments ─────────────────────────────────────────────── */

.file-upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: .75rem 1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-top: .5rem;
}
.file-upload-area:hover,
.file-upload-area--drag {
  border-color: var(--md-sys-color-primary);
  background: rgba(208,188,255,.06);
}
.file-upload-area__text {
  font-size: .8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .4rem;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--md-sys-color-surface-container-high);
  border-radius: 999px;
  padding: .25rem .6rem;
  font-size: .75rem;
  color: var(--md-sys-color-on-surface);
}
.attachment-chip--pending {
  background: rgba(208,188,255,.12);
  border: 1px solid var(--md-sys-color-outline-variant);
}
.attachment-chip__link {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}
.attachment-chip__link:hover {
  text-decoration: underline;
}
.attachment-chip__remove {
  background: none;
  border: none;
  color: var(--md-sys-color-error);
  font-size: .9rem;
  cursor: pointer;
  padding: 0 .2rem;
  line-height: 1;
}

.attachment-link {
  display: inline-block;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-size: .8rem;
  margin-right: .5rem;
}
.attachment-link:hover {
  text-decoration: underline;
}

/* ── Additional amounts table ──────────────────────────────────────────────── */

.additional-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-bottom: 16px;
}
.additional-table th {
  text-align: left;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  padding: .3rem .5rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.additional-table td {
  padding: .2rem .5rem;
  vertical-align: middle;
}
.additional-table tr:not(:last-child) td {
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.additional-table .field__input,
.additional-table .field__select {
  padding: .375rem .625rem;
  font-size: .875rem;
  width: 100%;
}
.additional-table th.add-col-name { width: 33%; }
.additional-table th.add-col-type { width: 33%; }
.additional-table th.add-col-amt { width: 33%; }
.additional-table th.add-col-action { width: 40px; }
.additional-table td.add-col-amt .field__input { text-align: right; }
.additional-table tfoot td {
  border-top: 1.5px solid var(--md-sys-color-outline-variant);
  padding-top: .5rem;
}
.add-footer-total {
  font-weight: 700;
  text-align: right;
  font-size: .875rem;
}

/* Total amount display */
#exp-total-amount {
  font-weight: 700;
  background: var(--md-sys-color-surface-container-high);
  text-align: right;
  color: var(--md-sys-color-on-surface-variant);
  cursor: default;
}

/* "With Additional" column in custom split table */
.custom-split-table th.col-amt-total { width: 145px; }
.custom-split-table td.col-amt-total .field__input { text-align: right; }
.field__input--readonly {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  cursor: default;
  font-weight: 700;
}

/* Universal right-alignment for all amount textboxes */
input[inputmode="decimal"],
#exp-amount,
#exp-total-amount {
  text-align: right;
}

/* Active profile highlight in event card member list */
.event-card__member--active {
  color: var(--profile-highlight);
  font-weight: 700;
}

/* Detail split table — column alignment */
.detail-split-table .detail-col-amt { text-align: right; font-weight: 600; }
.detail-split-table .detail-col-det { text-align: left; }
.detail-split-table td.detail-col-amt { text-align: right; font-weight: 600; }
.detail-split-table td.detail-col-det { text-align: left; }
.detail-name--highlight { color: var(--profile-highlight) !important; font-weight: 700; }
.detail-row--highlight td { color: var(--profile-highlight) !important; font-weight: 700; }

/* Clickable icon on expense column headers */
.summary-th--expense {
  position: relative;
  cursor: pointer;
}
.summary-th__detail-icon {
  position: absolute;
  right: 4px;
  bottom: 4px;
  opacity: .4;
  display: flex;
  align-items: center;
}
.summary-th--expense:hover .summary-th__detail-icon {
  opacity: 1;
}
