/* ---------- Design tokens ---------- */
:root {
  --brand: #059669;
  --brand-strong: #047857;
  --brand-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;

  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.06);

  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #10b981;
    --brand-strong: #34d399;
    --brand-soft: #064e3b;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --warn: #fbbf24;
    --warn-soft: #451a03;

    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1b2740;
    --border: #26334d;
    --text: #e2e8f0;
    --text-muted: #8ea0bd;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
}

h1, h2, h3 {
  margin: 0;
}

.muted {
  color: var(--text-muted);
}

.flex-spacer {
  flex: 1;
}

/* ---------- Layout ---------- */
.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: inherit;
  text-decoration: none;
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.user-chip a {
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s, transform 0.05s;
  touch-action: manipulation;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  flex: none;
}

/* ---------- PWA install ---------- */
.install-btn {
  flex: none;
}

.install-btn-topbar {
  padding: 7px 12px;
  font-size: 13px;
}

.install-btn-login {
  margin-top: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
}

.install-steps {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 10px;
  font-size: 14px;
  line-height: 1.5;
}

/* display:grid above would otherwise defeat the hidden attribute */
.install-steps[hidden],
.install-btn[hidden] {
  display: none;
}

.install-icon {
  vertical-align: -2px;
  color: var(--brand);
}

/* ---------- Login ---------- */
.login-hero {
  max-width: 420px;
  margin: 8vh auto 0;
  padding: 32px 24px;
  text-align: center;
}

.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  margin: 0 auto 20px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 44px;
  box-shadow: var(--shadow);
}

.login-hero h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.login-hero p {
  color: var(--text-muted);
  margin: 0 0 28px;
  line-height: 1.5;
}

.login-note {
  margin-top: 20px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  font-size: 14px;
}

.login-buttons {
  display: grid;
  gap: 10px;
}

.login-buttons .btn {
  padding: 13px 16px;
  font-size: 15px;
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

/* ---------- Cards & lists ---------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}

.section-head h1 {
  font-size: 22px;
}

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

.space-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.space-card {
  display: block;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.1s;
}

.space-card:active {
  transform: scale(0.99);
}

.space-card h3 {
  font-size: 17px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.space-card .meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge-due {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-owner {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.empty-state {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-muted);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state .big {
  font-size: 40px;
  margin-bottom: 10px;
}

/* ---------- Chores ---------- */
.chore-list {
  display: grid;
  gap: 10px;
}

.chore-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chore-card.is-overdue {
  border-left: 4px solid var(--danger);
}

.chore-card.is-due {
  border-left: 4px solid var(--warn);
}

.chore-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.chore-main h3 {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chore-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.chore-meta .due-overdue {
  color: var(--danger);
  font-weight: 700;
}

.chore-meta .due-today {
  color: var(--warn);
  font-weight: 700;
}

.complete-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  color: transparent;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
}

.complete-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.complete-btn.done,
.complete-btn:active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Members ---------- */
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.member-row:last-child {
  border-bottom: none;
}

.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.member-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.activity-row {
  display: flex;
  gap: 8px;
  padding: 7px 0;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.activity-row:last-child {
  border-bottom: none;
}

.activity-row b {
  color: var(--text);
}

/* ---------- Dialogs ---------- */
.dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  width: min(440px, calc(100vw - 32px));
  padding: 0;
}

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

.dialog-form {
  padding: 22px;
  display: grid;
  gap: 14px;
}

.dialog-form h2 {
  font-size: 19px;
}

.dialog-form .muted {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field em {
  font-weight: 400;
  color: var(--text-muted);
  font-style: normal;
}

.field input,
.field textarea,
.field select {
  font: inherit;
  font-weight: 400;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}

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

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.invite-code {
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.18em;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
  user-select: all;
}

/* ---------- Feedback ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: toast-in 0.2s ease-out;
  max-width: calc(100vw - 40px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--warn);
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
}

.page-loading {
  display: grid;
  place-items: center;
  min-height: 50vh;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  margin-top: 18px;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .section-head h1 {
    font-size: 19px;
  }

  .user-chip .user-name {
    display: none;
  }

  .install-btn-topbar .install-btn-label {
    display: none;
  }
}
