/* Buttons */
.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-line: var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.55rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--btn-line);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: var(--fs-sm);
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn--primary {
  --btn-bg: var(--accent);
  --btn-ink: #fff;
  --btn-line: var(--accent);
  box-shadow: 0 1px 2px rgba(163, 25, 25, 0.24);
}

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

.btn--dark {
  --btn-bg: var(--surface-inverse);
  --btn-ink: #fff;
  --btn-line: var(--surface-inverse);
}

.btn--dark:hover:not(:disabled) {
  background: var(--surface-inverse-2);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
  color: var(--ink-2);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn--danger {
  --btn-bg: var(--danger-soft);
  --btn-ink: var(--danger);
  --btn-line: transparent;
}

.btn--danger:hover:not(:disabled) {
  background: #fbdada;
}

.btn--sm {
  min-height: 2.1rem;
  padding: 0.35rem 0.75rem;
  font-size: var(--fs-xs);
}

.btn--lg {
  min-height: 3rem;
  padding: 0.75rem 1.3rem;
  font-size: var(--fs-md);
}

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

.btn--icon {
  width: 2.4rem;
  min-width: 2.4rem;
  min-height: 2.4rem;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn--icon.btn--sm {
  width: 2rem;
  min-width: 2rem;
  min-height: 2rem;
}

.btn .icon {
  width: 1.1rem;
  height: 1.1rem;
  flex: none;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}

/* Fields */
.field {
  display: grid;
  gap: 0.38rem;
  min-width: 0;
}

.field-label {
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 650;
  line-height: 1.3;
}

.field-label .req {
  color: var(--accent);
}

.field-hint {
  color: var(--ink-3);
  font-size: var(--fs-xs);
  line-height: 1.45;
}

.field-error {
  color: var(--danger);
  font-size: var(--fs-xs);
  font-weight: 600;
}

.input {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease), background var(--speed) var(--ease);
}

.input::placeholder {
  color: #9aa0aa;
}

.input:hover:not(:disabled):not([readonly]) {
  border-color: #aeb4bf;
}

.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: var(--focus-ring);
}

.input[readonly] {
  background: var(--surface-2);
  color: var(--ink-2);
}

.input:disabled {
  background: var(--surface-3);
  color: var(--ink-3);
  cursor: not-allowed;
}

.input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 35, 0.12);
}

textarea.input {
  min-height: 5.5rem;
  resize: vertical;
}

select.input {
  appearance: none;
  padding-right: 2.3rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234d515a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1.05rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.form-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid .span-full {
  grid-column: 1 / -1;
}

.form-grid .span-2 {
  grid-column: span 2;
}

.form-stack {
  display: grid;
  gap: 1rem;
}

/* Cards */
.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.card--danger {
  border-color: #f2c9c9;
  overflow: hidden;
}

.card--danger .card__head {
  background: var(--danger-soft);
  border-bottom-color: #f2c9c9;
}

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.card__head h3,
.card__head h2 {
  font-size: var(--fs-lg);
}

.card__head p {
  margin-top: 0.25rem;
  color: var(--ink-3);
  font-size: var(--fs-sm);
}

.card__body {
  padding: 1.25rem;
}

.card__body--tight {
  padding: 0.85rem 1rem;
}

.card__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.55rem;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

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

.badge--complete {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge--accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

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

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

.badge--neutral {
  background: var(--surface-3);
  color: var(--ink-2);
}

.badge--dot::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
}

/* Progress */
.progress {
  position: relative;
  width: 100%;
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}

.progress__bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 400ms var(--ease);
}

.progress__bar--ok {
  background: var(--ok);
}

.progress--lg {
  height: 0.68rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.stat {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.stat__label {
  color: var(--ink-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat__value {
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
}

.stat__hint {
  color: var(--ink-3);
  font-size: var(--fs-xs);
}

.stat--accent {
  border-color: #f3caca;
  background: linear-gradient(180deg, #fff, var(--accent-soft));
}

/* Empty states */
.empty {
  display: grid;
  justify-items: center;
  gap: 0.65rem;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  text-align: center;
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-3);
  box-shadow: var(--shadow-xs);
}

.empty h3 {
  font-size: var(--fs-lg);
}

.empty p {
  max-width: 34rem;
  color: var(--ink-3);
  font-size: var(--fs-sm);
}

/* Dialogs */
.dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: min(88dvh, 52rem);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dialog--wide {
  width: min(52rem, calc(100vw - 2rem));
}

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

.dialog[open] {
  display: flex;
  flex-direction: column;
}

.dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.dialog__head h2 {
  font-size: var(--fs-xl);
}

.dialog__head p {
  margin-top: 0.25rem;
  color: var(--ink-3);
  font-size: var(--fs-sm);
}

.dialog__body {
  padding: 1.25rem;
  overflow-y: auto;
}

.dialog__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.dialog__foot--split {
  justify-content: space-between;
}

/* Toasts */
.toast-root {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 100;
  display: grid;
  gap: 0.55rem;
  width: min(23rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in 260ms var(--ease);
}

.toast.is-leaving {
  animation: toast-out 180ms var(--ease) forwards;
}

.toast__icon {
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: var(--info-soft);
  color: var(--info);
}

.toast--success .toast__icon {
  background: var(--ok-soft);
  color: var(--ok);
}

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

.toast--warn .toast__icon {
  background: var(--warn-soft);
  color: var(--warn);
}

.toast__message {
  padding-top: 0.1rem;
  font-size: var(--fs-sm);
  line-height: 1.45;
}

.toast__close {
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
}

.toast__close:hover {
  background: var(--surface-3);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px); }
}

/* Callouts */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.callout .icon {
  margin-top: 0.1rem;
  color: var(--ink-3);
}

.callout--info {
  border-color: #cadef4;
  background: var(--info-soft);
  color: #174c80;
}

.callout--warn {
  border-color: #f1dca2;
  background: var(--warn-soft);
  color: #724a00;
}

.callout--danger {
  border-color: #f2c9c9;
  background: var(--danger-soft);
  color: #8a1b1b;
}

.callout--success {
  border-color: #bfe5d2;
  background: var(--ok-soft);
  color: #145f3b;
}

/* Details list */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1.5rem;
}

.detail {
  display: grid;
  gap: 0.12rem;
}

.detail__label {
  color: var(--ink-3);
  font-size: var(--fs-xs);
  font-weight: 650;
}

.detail__value {
  color: var(--ink);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

/* Photo picker */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.photo {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-3);
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo__remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border: 0;
  border-radius: 50%;
  background: rgba(23, 24, 28, 0.75);
  color: #fff;
  backdrop-filter: blur(4px);
}

.photo-add {
  display: grid;
  place-items: center;
  gap: 0.3rem;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-align: center;
}

.photo-add:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

/* Copy field */
.copy-field {
  display: flex;
  gap: 0.5rem;
}

.copy-field .input {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

/* Table-like member rows */
.member-list {
  display: grid;
  gap: 0.6rem;
}

.member {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.member__main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.member__name {
  font-weight: 650;
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member__meta {
  color: var(--ink-3);
  font-size: var(--fs-xs);
}

.member__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
}

/* Avatar */
.avatar {
  display: grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  flex: none;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.avatar--dark {
  background: var(--surface-inverse);
  color: #fff;
}

/* Skeleton / loading */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

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

/* Divider */
.divider {
  height: 1px;
  border: 0;
  background: var(--line);
}

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .form-grid,
  .form-grid--3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .form-grid .span-full { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dialog {
    width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .dialog__foot { padding-bottom: calc(0.9rem + env(safe-area-inset-bottom)); }
  .toast-root { bottom: calc(var(--bottomnav-height) + 0.9rem + env(safe-area-inset-bottom)); }
  .member { grid-template-columns: 1fr; }
  .member__actions { justify-content: flex-start; }
}
