/* Base: reset, typography and the shared components every view uses. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure {
  margin: 0;
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: -0.01em;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-soft);
}

/* Author `display` rules (e.g. .form-error) must never override the hidden attribute. */
[hidden] {
  display: none !important;
}

.vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.phone-only {
  display: none !important;
}

@media (max-width: 640px) {
  .phone-only {
    display: revert !important;
  }

  .desktop-only {
    display: none !important;
  }
}

.num {
  font-variant-numeric: tabular-nums;
}

.caps {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-subtle);
}

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

/* ---- Icons (UI-10): <svg class="icon"><use href="/icons/sprite.svg#i-name"/></svg> ---- */

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--sm {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.icon--lg {
  width: 24px;
  height: 24px;
  stroke-width: 1.6;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease),
    color var(--fast) var(--ease),
    box-shadow var(--fast) var(--ease);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.12);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--surface);
  border-color: var(--line-strong);
}

.btn--secondary:hover {
  background: var(--paper-sunken);
}

.btn--ghost {
  color: var(--ink-muted);
}

.btn--ghost:hover {
  background: var(--paper-sunken);
  color: var(--ink);
}

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

.btn--danger:hover {
  background: var(--danger-hover);
}

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

.btn--danger-ghost:hover {
  background: var(--danger-soft);
}

.btn--icon {
  width: var(--control);
  padding: 0;
}

.btn--block {
  width: 100%;
}

.btn--lg {
  min-height: 44px;
  font-size: var(--text-md);
  padding: 0 18px;
}

.btn--glass {
  background: var(--glass);
  border-color: var(--glass-edge);
  color: var(--on-glass);
}

.btn--glass:hover {
  background: var(--glass-strong);
}

.btn .count {
  margin-left: 2px;
}

@media (pointer: coarse) {
  .btn {
    min-height: var(--touch);
  }

  .btn--icon {
    width: var(--touch);
  }
}

/* ---- Form controls ---- */

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--ink-subtle);
}

.input,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  /* 16px keeps iOS Safari from zooming into focused fields */
  font-size: 16px;
  transition:
    border-color var(--fast) var(--ease),
    box-shadow var(--fast) var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--ink-subtle);
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: var(--leading);
}

.textarea--mono {
  font-family: var(--font-mono);
  font-size: 14px;
}

.input-icon {
  position: relative;
  display: block;
}

.input-icon > .icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-subtle);
  pointer-events: none;
}

.input-icon > .input {
  padding-left: 36px;
}

.check {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface) center / 12px no-repeat;
  cursor: pointer;
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}

.check:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.3l2.3 2.3 4.7-5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.check:indeterminate {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 6h6' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  .check:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.3l2.3 2.3 4.7-5' fill='none' stroke='%230c1022' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }

  .check:indeterminate {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 6h6' fill='none' stroke='%230c1022' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  }
}

.form-error {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ---- Avatars: colored initials ---- */

.avatar {
  --size: 28px;
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  flex: none;
  border-radius: 50%;
  background: var(--avatar-5);
  color: #fff;
  font-size: calc(var(--size) * 0.4);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}

.avatar--sm {
  --size: 22px;
}

.avatar--lg {
  --size: 36px;
}

.avatar--1 { background: var(--avatar-1); }
.avatar--2 { background: var(--avatar-2); }
.avatar--3 { background: var(--avatar-3); }
.avatar--4 { background: var(--avatar-4); }
.avatar--5 { background: var(--avatar-5); }
.avatar--6 { background: var(--avatar-6); }
.avatar--7 { background: var(--avatar-7); }
.avatar--8 { background: var(--avatar-8); }

.avatar--ghost {
  background: var(--paper-sunken);
  color: var(--ink-muted);
}

.avatar-stack {
  display: inline-flex;
  align-items: center;
}

.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--ring, var(--surface));
}

.avatar-stack .avatar + .avatar {
  margin-left: -6px;
}

/* ---- Labels (LBL-1) ---- */

.label {
  --lb: var(--label-gray-bg);
  --lf: var(--label-gray-fg);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--lb);
  color: var(--lf);
  font-size: var(--text-xs);
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label--lg {
  height: 26px;
  padding: 0 10px;
  font-size: var(--text-sm);
}

.label--red { --lb: var(--label-red-bg); --lf: var(--label-red-fg); }
.label--orange { --lb: var(--label-orange-bg); --lf: var(--label-orange-fg); }
.label--yellow { --lb: var(--label-yellow-bg); --lf: var(--label-yellow-fg); }
.label--green { --lb: var(--label-green-bg); --lf: var(--label-green-fg); }
.label--teal { --lb: var(--label-teal-bg); --lf: var(--label-teal-fg); }
.label--blue { --lb: var(--label-blue-bg); --lf: var(--label-blue-fg); }
.label--indigo { --lb: var(--label-indigo-bg); --lf: var(--label-indigo-fg); }
.label--purple { --lb: var(--label-purple-bg); --lf: var(--label-purple-fg); }
.label--pink { --lb: var(--label-pink-bg); --lf: var(--label-pink-fg); }
.label--gray { --lb: var(--label-gray-bg); --lf: var(--label-gray-fg); }

.label__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ---- Chips: due date (CARD-5), small facts ---- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-sm);
  background: var(--paper-sunken);
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip--soon {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip--overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip--done {
  background: var(--ok-soft);
  color: var(--ok);
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--paper-sunken);
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.badge-readonly {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  color: var(--on-glass);
  font-size: var(--text-xs);
  font-weight: 650;
  white-space: nowrap;
}

/* ---- Segmented control ---- */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--paper-sunken);
}

.segmented__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.segmented__item[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

@media (pointer: coarse) {
  .segmented__item {
    min-height: 38px;
  }
}

/* ---- Menus (popover panels) ---- */

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  animation: pop var(--fast) var(--ease);
}

.menu--left {
  right: auto;
  left: 0;
}

.menu__title {
  padding: 6px 10px 4px;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
}

.menu__item:hover,
.menu__item:focus-visible {
  background: var(--paper-sunken);
}

.menu__item > .icon {
  color: var(--ink-subtle);
}

.menu__item--danger,
.menu__item--danger > .icon {
  color: var(--danger);
}

.menu__item .count {
  margin-left: auto;
}

.menu__sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

@media (pointer: coarse) {
  .menu__item {
    min-height: var(--touch);
  }
}

/* ---- Dialogs (UI-13: in-app confirmation, never window.confirm) ---- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--scrim);
  animation: fade var(--medium) var(--ease);
}

.dialog {
  width: min(440px, 100%);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface);
  /* Explicit: dialogs live in <body>, which carries the board's light-on-glass color. */
  color: var(--ink);
  box-shadow: var(--shadow-modal);
  animation: rise var(--medium) var(--ease);
}

.dialog__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-3);
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
}

.dialog__title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.dialog__body {
  margin-top: var(--space-2);
  color: var(--ink-muted);
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* ---- Toasts (UI-5, BIN-9) ---- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-4) + var(--safe-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(30rem, calc(100% - 2 * var(--space-4)));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 4px 4px 4px var(--space-4);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: rise var(--medium) var(--ease);
}

.toast-error {
  background: var(--danger);
  color: var(--on-danger);
}

.toast-message {
  flex: 1;
}

.toast-action,
.toast-close {
  min-height: 40px;
  min-width: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}

.toast-action {
  padding: 0 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: var(--text-xs);
}

.toast-action:hover,
.toast-close:hover {
  background: rgb(255 255 255 / 0.14);
}

.toast-close {
  font-size: 1.25rem;
  line-height: 1;
}

/* ---- Empty / loading / error states (UI-13) ---- */

.state {
  color: var(--ink-muted);
}

.state-ok {
  color: var(--ok);
}

.state-error {
  color: var(--danger);
}

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  max-width: 360px;
  margin: var(--space-7) auto;
  padding: 0 var(--space-4);
  text-align: center;
}

.empty__art {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-2);
  border-radius: 20px;
  background: var(--paper-sunken);
  color: var(--ink-subtle);
  transform: rotate(-4deg);
}

.empty__art--error {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty__title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.empty__body {
  color: var(--ink-muted);
}

.empty .btn {
  margin-top: var(--space-3);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--paper-sunken) 0%, var(--line) 50%, var(--paper-sunken) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ---- Motion ---- */

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

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

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

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* Menus opened from inside scrolling areas are placed against the viewport (menu.js). */
.menu--fixed {
  position: fixed;
  top: auto;
  right: auto;
  z-index: 60;
}

@media (max-width: 640px) {
  .menu__item.phone-only {
    display: flex !important;
  }
}

/* Radio buttons styled as a segmented control (the Move dialog). */
.segmented__item:has(input:checked) {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

.segmented__item:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.input--select {
  appearance: auto;
}

/* SEC-2 / AUTH-4: a page that is leaving an account shows nothing (app.ts leaveAccount). */
.leaving body {
  visibility: hidden !important;
}

