/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.card.tight {
  padding: 0;
  overflow: hidden;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-strong);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

/* ---------- Hero (settlement) ---------- */
.hero {
  position: relative;
  border-radius: var(--radius-card);
  padding: 22px;
  background: var(--hero-grad);
  border: 1px solid var(--border);
  box-shadow: var(--hero-glow);
  overflow: hidden;
  color: #ecfeff;
}
.hero .blob {
  position: absolute;
  right: -30px;
  top: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(167, 139, 250, 0.35), transparent 70%);
  pointer-events: none;
}
.hero .hero-label {
  font-size: 0.78rem;
  opacity: 0.9;
}
.hero .hero-amount {
  font-size: 2.3rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #ffffff;
}
[data-theme="dark"] .hero .hero-amount {
  color: var(--accent-teal);
  text-shadow: 0 0 22px rgba(45, 212, 191, 0.45);
}
.hero .hero-sub {
  font-size: 0.82rem;
  opacity: 0.92;
  margin-top: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: transform 0.04s ease, filter 0.15s ease;
}
.btn:hover {
  filter: brightness(1.08);
}
.btn:active {
  transform: translateY(1px);
}
.btn.sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}
.btn.block {
  width: 100%;
}
.btn-accent {
  border: 0;
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-weight: 700;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover {
  background: var(--bg-elev);
  color: var(--text);
}
.btn-danger {
  border-color: transparent;
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger);
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1rem;
}
.icon-btn:hover {
  filter: brightness(1.1);
}

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 600;
}
.chip.accent {
  background: color-mix(in srgb, var(--accent-teal) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent-teal) 35%, transparent);
  color: var(--text-strong);
}
.chip .x {
  margin-left: 2px;
  opacity: 0.6;
  font-weight: 700;
}
.chip .x:hover {
  opacity: 1;
}
.chip-add {
  border-style: dashed;
  color: var(--text-dim);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge.shared {
  color: var(--accent-teal);
  border-color: color-mix(in srgb, var(--accent-teal) 35%, transparent);
  background: color-mix(in srgb, var(--accent-teal) 12%, transparent);
}
.badge.transfer {
  color: var(--accent-violet);
  border-color: color-mix(in srgb, var(--accent-violet) 35%, transparent);
  background: color-mix(in srgb, var(--accent-violet) 12%, transparent);
}
.badge.income {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 35%, transparent);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}

/* ---------- Avatars & dots ---------- */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #06121a;
  flex: 0 0 auto;
}
.avatar.sm {
  width: 22px;
  height: 22px;
  font-size: 0.62rem;
}
.avatar-stack {
  display: inline-flex;
}
.avatar-stack .avatar + .avatar {
  margin-left: -9px;
  border: 2px solid var(--bg-elev);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: inline-block;
}

/* ---------- Stat chips ---------- */
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat .label {
  margin-bottom: 4px;
}
.stat .val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-strong);
}

/* ---------- Progress (budgets) ---------- */
.progress {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent-gradient);
  transition: width 0.3s ease;
}
.progress-fill.warn {
  background: linear-gradient(90deg, var(--accent-teal), var(--warn));
}
.progress-fill.over {
  background: linear-gradient(90deg, var(--warn), var(--danger));
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
}
/* The expenses table scrolls inside a bounded box so the header can stay pinned
   and the horizontal scrollbar sits near the viewport. */
[data-table-scroll] {
  overflow: auto;
  max-height: calc(100dvh - 250px);
  min-height: 240px;
}
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  background: var(--bg-elev);
}
.table th,
.table td {
  text-align: left;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  user-select: none;
  box-shadow: 0 1px 0 var(--border);
}
.table thead th.sortable {
  cursor: pointer;
}
.table thead th.sortable:hover {
  color: var(--text);
}
.table thead th .arrow {
  margin-left: 4px;
  opacity: 0.8;
}
.table tbody tr:hover {
  background: var(--bg-soft);
}
.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table .row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.table-empty {
  padding: 34px;
  text-align: center;
  color: var(--text-dim);
  background: var(--bg-elev);
}

/* Fixed-layout table: honour per-column pixel widths, ellipsis overflow */
.table.fixed {
  /* Exact per-column widths: the table is as wide as the sum of its columns, so
     resizing one column changes only that column, never the others. */
  table-layout: fixed;
  width: max-content;
}
.table.fixed th,
.table.fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.table.fixed td.wrap {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Draggable / resizable headers */
.table th.draggable-col {
  /* No position:relative here — the sticky `.table thead th` already establishes
     the containing block for the absolutely-positioned .col-resize handle, and
     overriding it would break the sticky header. */
  cursor: grab;
}
.table th.draggable-col:active {
  cursor: grabbing;
}
.table th.draggable-col .th-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  pointer-events: none; /* let the <th> receive drag/click */
}
.table th.col-dragging {
  opacity: 0.45;
}
.table th.col-drop-target {
  box-shadow: inset 3px 0 0 0 var(--accent-teal);
}
.col-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 9px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}
.col-resize:hover {
  background: color-mix(in srgb, var(--accent-teal) 45%, transparent);
}
body.col-resizing {
  cursor: col-resize;
  user-select: none;
}

/* Floating horizontal scrollbar for wide tables */
#floating-hscroll {
  position: fixed;
  bottom: 0;
  z-index: 60;
  height: 15px;
  overflow-x: auto;
  overflow-y: hidden;
  background: color-mix(in srgb, var(--bg-soft) 92%, transparent);
  border-top: 1px solid var(--border-strong);
  backdrop-filter: blur(6px);
  display: none;
}
#floating-hscroll .fh-inner {
  height: 1px;
}
#floating-hscroll::-webkit-scrollbar {
  height: 13px;
}
#floating-hscroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
@media (max-width: 768px) {
  #floating-hscroll {
    bottom: calc(70px + env(safe-area-inset-bottom));
  }
}

/* ---------- Forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field > .label {
  margin-bottom: 1px;
}
.input,
.select,
textarea.input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text);
  outline: none;
}
.input:focus,
.select:focus,
textarea.input:focus {
  border-color: var(--accent-teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-teal) 20%, transparent);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.form-grid .full {
  grid-column: 1 / -1;
}
@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}
.checkbox input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent-teal);
}

/* segmented control */
.segmented {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  padding: 6px 13px;
  font-size: 0.82rem;
  font-weight: 600;
}
.segmented button.active {
  background: var(--bg-elev);
  color: var(--text-strong);
  box-shadow: var(--shadow-card);
}

/* ---------- Popover / dropdown ---------- */
.popover-wrap {
  position: relative;
}
.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.5);
  padding: 10px;
  min-width: 220px;
  max-height: 320px;
  overflow: auto;
}
.popover .pop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 0.86rem;
}
.popover .pop-item:hover {
  background: var(--bg-soft);
}

/* ---------- Quick add ---------- */
.quick-add {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.quick-add .input,
.quick-add .select {
  width: auto;
  flex: 1 1 120px;
}
.template-chips {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ---------- Banner ---------- */
.banner {
  border: 1px solid color-mix(in srgb, var(--accent-violet) 40%, transparent);
  background: color-mix(in srgb, var(--accent-violet) 12%, transparent);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.banner .grow {
  min-width: 160px;
}

/* ---------- Expense list (dashboard recents) ---------- */
.exp-list {
  display: flex;
  flex-direction: column;
}
.exp-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.exp-row:last-child {
  border-bottom: 0;
}
.exp-row .meta {
  min-width: 0;
  flex: 1 1 auto;
}
.exp-row .meta .t {
  font-weight: 600;
  color: var(--text-strong);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.exp-row .meta .s {
  font-size: 0.76rem;
  color: var(--text-dim);
}
.exp-row .amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: radial-gradient(120% 80% at 100% 0%, #1b1240 0%, var(--bg) 55%, var(--bg) 100%);
}
[data-theme="light"] .auth-wrap {
  background: radial-gradient(120% 80% at 0% 0%, #eef2ff 0%, var(--bg) 55%, var(--bg) 100%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card .brand {
  justify-content: center;
  padding: 0 0 6px;
}

/* ---------- Bars (reports) ---------- */
.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
}
.bar-track {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-pill);
}
.bar-row .lab {
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-row .val {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.bar-row.clickable {
  cursor: pointer;
  border-radius: 8px;
  padding-left: 6px;
  padding-right: 6px;
  margin-left: -6px;
  margin-right: -6px;
}
.bar-row.clickable:hover {
  background: var(--bg-soft);
}
.bar-row.clickable:hover .lab {
  color: var(--accent-teal);
}
@media (max-width: 560px) {
  .bar-row {
    grid-template-columns: 96px 1fr auto;
  }
}

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
@media (max-width: 768px) {
  .toast-host {
    bottom: calc(86px + env(safe-area-inset-bottom));
  }
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.5);
}
.toast.error {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
  color: var(--danger);
}
.toast.success {
  border-color: color-mix(in srgb, var(--good) 50%, transparent);
}

/* ---------- Modal ---------- */
.modal-host {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 16px;
  overflow: auto;
}
.modal {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Settings accordion ---------- */
.settings-section {
  padding: 0;
  overflow: hidden;
}
.section-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: none;
  border: 0;
  color: var(--text);
  padding: 15px 16px;
  text-align: left;
  font: inherit;
}
.section-head:hover {
  background: var(--bg-soft);
}
.section-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.section-sub {
  font-weight: 400;
}
.settings-section.open .section-head {
  border-bottom: 1px solid var(--border);
}
.section-head .chev {
  color: var(--text-dim);
  font-size: 0.9rem;
  flex: 0 0 auto;
}
.section-body {
  padding: 16px;
}

/* ---------- Misc ---------- */
.empty {
  padding: 30px;
  text-align: center;
  color: var(--text-dim);
}
.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 2px 0;
}
.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent-teal);
  animation: spin 0.8s linear infinite;
}
.loading-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
