/* ============================================================
   Local English Vocabulary — components.css
   Button / Input / Card / Stat / Badge / Segmented /
   List / Empty / Modal / Toast / Chip / Switch
   ============================================================ */

/* ---------------------------------------------- button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

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

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

.btn__icon,
.btn__label {
  display: inline-flex;
}

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

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

.btn--subtle {
  background: var(--surface-2);
  border-color: transparent;
}

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

.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

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

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

.btn--sm {
  height: 30px;
  padding: 0 10px;
  font-size: var(--text-sm);
}

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

.btn--icon {
  width: 36px;
  padding: 0;
}

.btn--icon.btn--sm {
  width: 30px;
}

.btn--icon.btn--lg {
  width: 42px;
}

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

/* ---------------------------------------------- input */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-2);
}

.field__control {
  position: relative;
  display: flex;
  align-items: center;
}

.field__icon {
  position: absolute;
  left: 11px;
  display: inline-flex;
  color: var(--text-3);
  pointer-events: none;
}

.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

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

.input::placeholder {
  color: var(--text-3);
}

.input:hover {
  border-color: var(--border-strong);
}

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

.field__hint {
  font-size: var(--text-sm);
  color: var(--text-3);
}

.textarea {
  height: auto;
  min-height: 76px;
  padding: 10px 12px;
  line-height: 1.6;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b8b95' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* ---------------------------------------------- checkbox */

.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
}

.checkbox__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.checkbox__box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.checkbox__input:checked + .checkbox__box {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.checkbox__input:focus-visible + .checkbox__box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.checkbox__label {
  font-size: var(--text-base);
}

.checkbox__desc {
  font-size: var(--text-sm);
  color: var(--text-3);
}

.field__error {
  font-size: var(--text-sm);
  color: var(--danger);
}

.field--invalid .input {
  border-color: var(--danger);
}

.field--invalid .input:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ---------------------------------------------- loading state */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  color: var(--text-2);
}

.state__text {
  font-size: var(--text-base);
}

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

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

/* ---------------------------------------------- card */

.card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.card__title {
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card__subtitle {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--text-2);
}

.card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.card__body {
  flex: 1;
  padding: var(--space-5);
}

.card__body--flush {
  padding: 0;
}

/* ---------------------------------------------- stat */

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-2);
}

.stat__label-icon {
  display: inline-flex;
  color: var(--text-3);
}

.stat__value {
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat__unit {
  margin-left: 2px;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-3);
}

.stat__meta {
  font-size: var(--text-sm);
  color: var(--text-3);
}

.stat--accent .stat__value {
  color: var(--accent);
}

.stat--success .stat__value {
  color: var(--success);
}

.stat--danger .stat__value {
  color: var(--danger);
}

/* ---------------------------------------------- badge / chip */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
}

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

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

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

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

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

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------------------------------------------- segmented control */

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

.segmented__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.segmented__btn:hover {
  color: var(--text);
}

.segmented__btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented--full {
  display: flex;
  width: 100%;
}

.segmented--full .segmented__btn {
  flex: 1;
}

.segmented--compact .segmented__btn {
  padding: 0 8px;
}

/* ---------------------------------------------- list */

.list {
  display: flex;
  flex-direction: column;
}

.list__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px var(--space-5);
  border-bottom: 1px solid var(--border);
}

.list__item:last-child {
  border-bottom: none;
}

.list__item--interactive {
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.list__item--interactive:hover {
  background: var(--surface-2);
}

.list__main {
  flex: 1;
  min-width: 0;
}

.list__title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list__meta {
  margin-top: 1px;
  font-size: var(--text-sm);
  color: var(--text-3);
}

.list__side {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-3);
  font-size: var(--text-sm);
}

/* ---------------------------------------------- empty state */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--space-10) var(--space-5);
  text-align: center;
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text-3);
}

.empty__title {
  font-weight: 600;
}

.empty__desc {
  max-width: 360px;
  font-size: var(--text-sm);
  color: var(--text-2);
}

.empty__actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--scrim);
  animation: fade-in var(--dur) var(--ease);
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur-slow) var(--ease);
}

.modal--sm {
  max-width: 420px;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal__desc {
  margin-top: 3px;
  font-size: var(--text-sm);
  color: var(--text-3);
}

.modal__body {
  padding: 0 var(--space-5) var(--space-5);
  overflow-y: auto;
  color: var(--text-2);
}

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}

@media (max-width: 767px) {
  /* 触摸目标不小于 40px */
  .btn {
    min-height: 40px;
  }

  .btn--sm {
    min-height: 36px;
  }

  .btn--icon {
    min-width: 40px;
  }

  .chip {
    min-height: 34px;
  }

  .input {
    min-height: 42px;
  }
}

@media (max-width: 560px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: none;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: sheet-in var(--dur-slow) var(--ease);
  }

  .modal__foot .btn {
    flex: 1;
  }
}

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

.toast-root {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

@media (max-width: 767px) {
  .toast-root {
    bottom: calc(var(--bottomnav-h) + var(--space-4) + env(safe-area-inset-bottom));
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: var(--text-base);
  pointer-events: auto;
  cursor: pointer;
  animation: toast-in var(--dur-slow) var(--ease);
}

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

.toast__icon {
  display: inline-flex;
  color: var(--text-3);
}

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

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

.toast--warning .toast__icon {
  color: var(--warning);
}

.toast--info .toast__icon {
  color: var(--accent);
}

.toast__message {
  flex: 1;
  min-width: 0;
}

/* ---------------------------------------------- animations */

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes sheet-in {
  from { transform: translateY(24px); }
  to { transform: none; }
}

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

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

@keyframes bar-grow {
  from { height: 0; }
}

/* ============================================================
   顶栏用户菜单
   ============================================================ */

.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-full);
  cursor: pointer;
  list-style: none;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.user-menu__trigger::-webkit-details-marker {
  display: none;
}

.user-menu__trigger:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.user-menu__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-sm);
  font-weight: 700;
}

.user-menu__name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  font-weight: 600;
}

.user-menu__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 200px;
  padding: var(--space-2);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.user-menu__email {
  padding: 6px 10px;
  color: var(--text-3);
  font-size: var(--text-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__action {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.user-menu__action:hover {
  background: var(--surface-2);
  color: var(--danger);
}

@media (max-width: 480px) {
  .user-menu__name {
    display: none;
  }
}
