/* ------------------------------------------------------------------ tokens */

:root {
  --bg: #0b0f17;
  --bg-raised: #121926;
  --bg-sunken: #080b12;
  --surface: #151d2c;
  --surface-hover: #1b2537;
  --border: #24304a;
  --border-strong: #33415f;

  --text: #eaf0fa;
  --text-muted: #93a3bd;
  --text-faint: #64748b;

  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --accent-ink: #08122b;

  --good: #34d399;
  --good-dim: #10603f;
  --warn: #fbbf24;
  --warn-dim: #6b4a06;
  --bad: #f87171;
  --bad-dim: #6d2222;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

/* -------------------------------------------------------------------- boot */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------- login */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background: radial-gradient(1000px 500px at 50% -10%, #1a2540 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}

.login-mark,
.brand-mark {
  display: block;
  background: linear-gradient(140deg, var(--accent), #9d7bff);
  border-radius: 12px;
}

.login-mark {
  width: 48px;
  height: 48px;
  margin-bottom: 18px;
}

.login-card h1 {
  font-size: 26px;
  margin-bottom: 6px;
}

.login-sub {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 6px;
}

input,
textarea,
select {
  width: 100%;
  padding: 12px 13px;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--text);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  appearance: none;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.form-error {
  margin: -6px 0 14px;
  color: var(--bad);
  font-size: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-hint {
  margin: -12px 0 16px;
  font-size: 12px;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------ layout */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex: none;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.period-chip {
  margin-left: auto;
  background: var(--bg-raised);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.period-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: 999px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.topbar-user:hover {
  background: var(--bg-raised);
}

.period-chip + .topbar-user {
  margin-left: 0;
}

.user-name {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.view {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px 16px calc(96px + var(--safe-bottom));
  outline: none;
}

/* ------------------------------------------------------------------ tabbar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  padding-bottom: var(--safe-bottom);
  background: rgba(11, 15, 23, 0.94);
  backdrop-filter: saturate(140%) blur(12px);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 8px;
  background: none;
  border: 0;
  color: var(--text-faint);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.tab svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  color: var(--accent);
}

.tab-badge {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: 6px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  line-height: 17px;
  text-align: center;
}

@media (min-width: 760px) {
  .tabbar {
    position: sticky;
    top: 0;
    order: -1;
    justify-content: center;
    gap: 4px;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    padding: 6px 12px;
  }

  .tab {
    flex: none;
    flex-direction: row;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 14px;
  }

  .tab.is-active {
    background: var(--bg-raised);
  }

  .tab-badge {
    position: static;
    margin: 0;
  }

  .view {
    padding-bottom: 60px;
  }
}

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-tight {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 10px;
}

.section-head:first-child {
  margin-top: 4px;
}

.section-head h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.section-count {
  font-size: 13px;
  color: var(--text-faint);
}

/* --------------------------------------------------------------- stake hero */

.hero {
  background: linear-gradient(155deg, #1c2942 0%, var(--surface) 55%);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 14px;
}

.hero-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.hero-amount {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hero-amount.is-clear {
  color: var(--good);
}

.hero-sub {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
  margin: 16px 0 10px;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #9d7bff);
  border-radius: 999px;
  transition: width 0.45s ease;
}

.progress-fill.is-clear {
  background: linear-gradient(90deg, var(--good), #6ee7b7);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.stat-value {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.stat-value.is-good {
  color: var(--good);
}
.stat-value.is-warn {
  color: var(--warn);
}
.stat-value.is-bad {
  color: var(--bad);
}

.callout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  border: 1px solid;
}

.callout-warn {
  background: rgba(251, 191, 36, 0.08);
  border-color: var(--warn-dim);
  color: #fcd34d;
}

.callout-good {
  background: rgba(52, 211, 153, 0.08);
  border-color: var(--good-dim);
  color: #6ee7b7;
}

.callout-info {
  background: rgba(91, 140, 255, 0.08);
  border-color: #2c3f6b;
  color: #a9c1ff;
}

/* -------------------------------------------------------------------- task */

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.task-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.task-title {
  font-size: 16px;
  font-weight: 640;
  letter-spacing: -0.01em;
  margin: 0;
}

.task-value {
  flex: none;
  font-size: 19px;
  font-weight: 700;
  color: var(--good);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.task-desc {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--text-muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* --------------------------------------------------------------- checklist */

.checklist {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-sunken);
}

.checklist-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

.checklist-done {
  color: var(--good);
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  font-size: 14.5px;
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
}

.checklist-item:last-child {
  border-bottom: 0;
}

label.checklist-item {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

label.checklist-item:hover {
  background: var(--surface-hover);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  white-space: nowrap;
}

.pill-muted {
  color: var(--text-faint);
}
.pill-good {
  color: #6ee7b7;
  border-color: var(--good-dim);
  background: rgba(52, 211, 153, 0.1);
}
.pill-warn {
  color: #fcd34d;
  border-color: var(--warn-dim);
  background: rgba(251, 191, 36, 0.1);
}
.pill-bad {
  color: #fca5a5;
  border-color: var(--bad-dim);
  background: rgba(248, 113, 113, 0.1);
}
.pill-accent {
  color: #a9c1ff;
  border-color: #2c3f6b;
  background: rgba(91, 140, 255, 0.12);
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-good {
  background: var(--good);
  border-color: var(--good);
  color: #05271a;
}

.btn-good:hover:not(:disabled) {
  background: #6ee7b7;
  border-color: #6ee7b7;
}

.btn-danger {
  color: #fca5a5;
  border-color: var(--bad-dim);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.12);
  border-color: var(--bad);
}

.btn-ghost {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-raised);
  border-color: var(--border);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 11px;
  min-height: 34px;
  font-size: 13px;
}

/* -------------------------------------------------------------------- misc */

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty strong {
  display: block;
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 4px;
}

.rows {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.row:last-child {
  border-bottom: 0;
}

.row-main {
  min-width: 0;
  flex: 1;
}

.row-title {
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row-sub {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.row-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  white-space: nowrap;
}

.amount-credit {
  color: var(--good);
}
.amount-debit {
  color: var(--bad);
}

.member-row {
  display: block;
  padding: 14px;
}

.member-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.member-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
  margin-top: 10px;
  border: 1px solid var(--border);
}

.member-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.total-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.total-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

@media (max-width: 420px) {
  .totals {
    grid-template-columns: 1fr;
  }
  .hero-amount {
    font-size: 38px;
  }
}

/* ------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 7, 12, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fade 0.15s ease;
}

@media (min-width: 620px) {
  .modal-backdrop {
    align-items: center;
    padding: 24px;
  }
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}

@media (min-width: 620px) {
  .modal {
    border-radius: 18px;
    padding-bottom: 20px;
  }
}

.modal h2 {
  font-size: 19px;
  margin-bottom: 4px;
}

.modal-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions .btn {
  flex: 1;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(78px + var(--safe-bottom));
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}

.toast.is-error {
  border-color: var(--bad);
  color: #fca5a5;
}

.toast.is-success {
  border-color: var(--good-dim);
  color: #6ee7b7;
}

@media (min-width: 760px) {
  .toast {
    bottom: 24px;
  }
}

/* --------------------------------------------------------------- a11y misc */

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

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