/* Reusable UI components */

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 0.9375rem;
  border: none; border-radius: var(--radius-sm);
  padding: 12px 20px;
  cursor: pointer;
  background: var(--brand); color: #fff;
  transition: filter .12s ease, transform .06s ease;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--brand-dark); border: 1.5px solid var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.subtle { background: var(--brand-light); color: var(--brand-dark); }
.btn.sm { padding: 7px 12px; font-size: 0.8125rem; border-radius: 8px; }

/* ---- cards, rows ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card.flat { box-shadow: none; border: 1px solid var(--line); }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid var(--card-line); width: 100%; text-align: left; font: inherit; color: inherit;
}
.list-row:hover { background: color-mix(in srgb, var(--surface) 94%, var(--brand)); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 0.8125rem; color: var(--muted); }
.row-end { text-align: right; flex-shrink: 0; }

/* ---- badges & pills ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.75rem; font-weight: 700;
  background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 3px 10px;
}
.pill {
  display: inline-block;
  font-size: 0.75rem; font-weight: 700;
  border-radius: 999px; padding: 3px 10px;
}
.pill.ok { background: var(--ok-light); color: var(--ok-ink); }
.pill.warn { background: var(--accent-light); color: var(--accent-ink); }
.pill.danger { background: var(--danger-light); color: var(--danger-ink); }
.pill.muted { background: var(--surface-2); color: var(--muted); }

.member-dot {
  width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-size: 0.75rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ---- forms ---- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.8438rem; font-weight: 700; margin-bottom: 6px; }
.field .hint { font-size: 0.7812rem; color: var(--muted); margin-top: 5px; }
input[type="text"], input[type="password"], input[type="date"], input[type="email"],
input[type="number"], select, textarea {
  width: 100%;
  font: inherit; font-size: 1rem;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
textarea { min-height: 140px; resize: vertical; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px; gap: 4px;
}
.seg button {
  font: inherit; font-size: 0.8438rem; font-weight: 700;
  border: none; border-radius: 7px;
  padding: 8px 6px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.toggle-row + .toggle-row { border-top: 1px solid var(--line); }
.switch { position: relative; width: 46px; height: 27px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--knob-off); border-radius: 999px; transition: background .15s;
}
.switch .knob::before {
  content: ""; position: absolute; width: 21px; height: 21px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .knob { background: var(--brand); }
.switch input:checked + .knob::before { transform: translateX(19px); }

/* ---- banner ---- */
.banner {
  display: flex; align-items: center; gap: 10px;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.8438rem; font-weight: 600;
  margin-bottom: 14px;
}
.banner.info { background: var(--brand-light); color: var(--brand-dark); }
.banner.warn { background: var(--accent-light); color: var(--accent-ink); }
.banner.danger { background: var(--danger-light); color: var(--danger-ink); }
.banner .btn { margin-left: auto; flex-shrink: 0; }

/* ---- toast ---- */
#toast-root {
  position: fixed; bottom: calc(var(--tabbar-h) + 18px); left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: 92vw;
}
.toast {
  background: var(--toast-bg); color: var(--toast-text);
  font-size: 0.875rem; font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .15s ease;
}
.modal-panel {
  background: var(--surface);
  width: 100%; max-width: 540px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88dvh; overflow-y: auto;
  animation: sheet-up .22s cubic-bezier(.3,1.1,.4,1);
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal-panel { border-radius: 20px; max-width: 440px; }
}
.modal-title { font-size: 1.125rem; font-weight: 800; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }

/* ---- .ics export picker ---- */
.ics-pick-tools { display: flex; gap: 8px; margin-bottom: 10px; }
.ics-pick-list {
  max-height: 46dvh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.ics-pick-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  cursor: pointer;
}
.ics-pick-row + .ics-pick-row { border-top: 1px solid var(--line); }
.ics-pick-row input { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--brand); }
.ics-pick-row .row-main { display: block; }
.ics-pick-row .row-title { display: block; }
.ics-pick-row .row-sub { display: block; }

/* ---- empty state ---- */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
.empty-state .big { font-size: 2.75rem; margin-bottom: 10px; }
.empty-state h3 { color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 0.875rem; }

/* ---- obligation card ---- */
.ob-card {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--card-line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
}
.ob-card.urgent { border-left-color: var(--danger); }
.ob-card.soon { border-left-color: var(--accent); }
.ob-card .ob-main { flex: 1; min-width: 0; cursor: pointer; }
.ob-title { font-weight: 700; font-size: 0.9062rem; }
.ob-meta { font-size: 0.7812rem; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.ob-due { font-size: 0.8125rem; font-weight: 800; white-space: nowrap; }
.ob-due.overdue { color: var(--danger-ink); }
.ob-due.today { color: var(--accent-ink); }
.ob-actions { display: flex; gap: 6px; margin-top: 8px; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--brand); border-radius: 999px; transition: width .2s; }
