/*
  Apple Liquid UI — components.css
  Reusable components. Extend with modifier classes rather than writing
  parallel one-off styles — see AI_INSTRUCTIONS.md section 6.
*/

/* ================= Buttons ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.41px;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-spring-snappy),
              opacity var(--duration-fast) var(--ease-out-quick),
              background var(--duration-fast) var(--ease-out-quick);
  -webkit-tap-highlight-color: transparent;
}
.btn i { font-size: var(--icon-size-md); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { background: var(--accent-pressed); }

.btn-secondary {
  background: var(--fill-secondary);
  color: var(--accent);
}
.btn-secondary:active { background: var(--fill-primary); }

.btn-plain {
  background: transparent;
  color: var(--accent);
  padding: var(--space-2) var(--space-3);
}

.btn-destructive {
  background: var(--system-red);
  color: #fff;
}

.btn-sm { padding: var(--space-2) var(--space-4); font-size: 15px; }
.btn-lg { padding: var(--space-4) var(--space-8); font-size: 19px; }

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
  background: var(--fill-secondary);
  color: var(--label-primary);
}

/* ================= Cards ================= */
.card {
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  background: var(--system-background-tertiary);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-2);
}
.card-glass {
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

/* ================= Nav bar ================= */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--space-3) + env(safe-area-inset-top, 0px)) var(--space-5) var(--space-3);
  border-radius: 0;
}
.nav-bar-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
}

/* ================= Tab bar ================= */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-nav);
  display: flex;
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2);
  color: var(--label-tertiary);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out-quick);
}
.tab-item i { font-size: var(--icon-size-lg); }
.tab-item.active { color: var(--accent); }
.tab-item span { font-size: 10px; font-weight: 500; }

/* ================= Sheet / Modal ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  background: rgba(0, 0, 0, 0.4);
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  max-height: 88vh;
  overflow-y: auto;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-3) var(--space-6) calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
}
.sheet-grabber {
  width: 36px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--fill-primary);
  margin: var(--space-2) auto var(--space-4);
}
.sheet-centered {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-sheet);
  width: min(420px, 90vw);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
}

/* ================= Inputs ================= */
.input,
.search-field {
  width: 100%;
  font-family: var(--font-text);
  font-size: 17px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
  background: var(--fill-quaternary);
  color: var(--label-primary);
  transition: border-color var(--duration-fast) var(--ease-out-quick),
              box-shadow var(--duration-fast) var(--ease-out-quick);
}
.input::placeholder { color: var(--label-tertiary); }
.input:focus,
.search-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}
.search-field {
  border-radius: var(--radius-full);
  padding-left: var(--space-9);
  position: relative;
}
.search-field-wrap { position: relative; }
.search-field-wrap i {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--label-tertiary);
  font-size: var(--icon-size-sm);
}

/* ================= Toggle (switch) ================= */
.toggle {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  background: var(--fill-primary);
  transition: background var(--duration-base) var(--ease-spring-standard);
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-2);
  transition: transform var(--duration-base) var(--ease-spring-snappy);
}
.toggle input:checked + .toggle-track { background: var(--system-green); }
.toggle input:checked + .toggle-track .toggle-thumb,
.toggle input:checked ~ .toggle-thumb {
  transform: translateX(20px);
}

/* ================= Segmented control ================= */
.segmented-control {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--fill-tertiary);
  gap: 2px;
}
.segmented-control button {
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-5);
  border-radius: calc(var(--radius-md) - 2px);
  font-size: 14px;
  font-weight: 600;
  color: var(--label-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-spring-standard);
}
.segmented-control button.active {
  background: var(--system-background-tertiary);
  color: var(--label-primary);
  box-shadow: var(--shadow-1);
}

/* ================= Lists ================= */
.list {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--system-background-tertiary);
  border: 1px solid var(--separator);
}
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out-quick);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--fill-quaternary); }
.list-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}
.list-item-icon i { font-size: var(--icon-size-sm); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-chevron { color: var(--label-tertiary); font-size: 13px; }

/* ================= Badge ================= */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--system-red);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--system-red);
  display: inline-block;
}

/* ================= Toast ================= */
.toast {
  position: fixed;
  top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-size: 15px;
  font-weight: 500;
}

/* ================= App shell (PWA) ================= */
.app-shell {
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--system-background-secondary);
}
