/* ============================================================
   components.css — 卡片、按鈕、表單、膠囊、面板、Toast
   ============================================================ */

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 18px;
}

.card.tight {
  padding: 14px;
}
.card.flat {
  box-shadow: none;
}
.card.press:active {
  transform: scale(0.985);
  transition: transform 0.12s var(--ease);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 650;
  font-size: 15.5px;
  border: 1px solid var(--line);
  transition: transform 0.12s var(--ease), opacity 0.15s, background 0.15s;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px -8px rgba(10, 132, 255, 0.7);
}

.btn.success {
  background: var(--green);
  color: #fff;
  border-color: transparent;
}

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

.btn.ghost {
  background: transparent;
  border-color: var(--line-strong);
}

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

.btn.block {
  width: 100%;
}

.btn.sm {
  height: 36px;
  padding: 0 14px;
  font-size: 13.5px;
}

.btn.lg {
  height: 54px;
  font-size: 17px;
}

.btn.icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface-2);
}

.btn svg {
  width: 18px;
  height: 18px;
}

/* 底部固定主按鈕 */
.action-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
  width: min(calc(100% - 28px), 520px);
  z-index: 60;
  pointer-events: none;
}

.action-bar > * {
  pointer-events: auto;
}

.action-bar .btn {
  width: 100%;
  box-shadow: var(--shadow-float);
}

/* ---------- 表單 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > label {
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  padding-left: 4px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 50px;
  padding: 13px 15px;
  border-radius: var(--radius-field);
  background: var(--surface-2);
  border: 1px solid var(--line);
  outline: none;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  appearance: none;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}

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

.textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.55;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center;
  padding-right: 40px;
}

.input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-suffix {
  font-size: 14px;
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
  padding-right: 6px;
}

.hint {
  font-size: 12.5px;
  color: var(--text-3);
  padding-left: 4px;
  line-height: 1.45;
}

.error-text {
  font-size: 12.5px;
  color: var(--red);
  padding-left: 4px;
}

/* 大輸入（兵籍號） */
.input.big {
  height: 60px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  font-family: var(--mono);
}

.input.code {
  text-transform: uppercase;
  letter-spacing: 0.28em;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
}

/* ---------- 分段控制 ---------- */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  overflow-x: auto;
  scrollbar-width: none;
}

.segmented::-webkit-scrollbar {
  display: none;
}

.segmented button {
  flex: 1 0 auto;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 650;
  color: var(--text-2);
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}

.segmented button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.14);
}

/* ---------- 選項網格（交通方式） ---------- */
.option-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 12px 4px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--text-2);
  transition: all 0.18s var(--ease);
  line-height: 1.2;
  text-align: center;
}

.option svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.7;
}

.option.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.option:active {
  transform: scale(0.95);
}

/* ---------- 膠囊 / 標籤 ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill.missing {
  background: var(--gray-soft);
  color: var(--gray);
}
.pill.reported {
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.departed {
  background: var(--orange-soft);
  color: var(--orange);
}
.pill.boarded {
  background: var(--purple-soft);
  color: var(--purple);
}
.pill.arrived {
  background: var(--green-soft);
  color: var(--green);
}
.pill.late,
.pill.absent {
  background: var(--red-soft);
  color: var(--red);
}
.pill.excused {
  background: var(--gray-soft);
  color: var(--gray);
}

/* 通知綁定指示：綠 = 已綁定（至少一個通道），灰 = 尚未綁定 */
.nbadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  vertical-align: -3px;
  margin-left: 5px;
  flex-shrink: 0;
}
.nbadge.on {
  color: var(--green);
  background: var(--green-soft);
}
.nbadge.off {
  color: var(--text-3);
  background: var(--surface-3);
}
.nbadge.md {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  margin-left: 0;
}

.pill.lg {
  height: 30px;
  padding: 0 13px;
  font-size: 13px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 7px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 650;
}

/* ---------- 清單列 ---------- */
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s;
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row:active {
  background: var(--surface-2);
}

.list-row .lead {
  flex-shrink: 0;
}

.list-row .main {
  flex: 1;
  min-width: 0;
}

.list-row .t {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.list-row .s {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 2px;
}

.list-row .trail {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
}

.list-row .chev {
  width: 16px;
  height: 16px;
  opacity: 0.4;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-2);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.avatar.sq {
  border-radius: 50%;
}

.avatar.blue {
  background: var(--accent-soft);
  color: var(--accent);
}
.avatar.green {
  background: var(--green-soft);
  color: var(--green);
}
.avatar.orange {
  background: var(--orange-soft);
  color: var(--orange);
}

/* ---------- 統計條 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 14px 8px;
  box-shadow: var(--shadow-soft);
}

.stat {
  text-align: center;
  padding: 2px 4px;
}

.stat .n {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat .l {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
  font-weight: 600;
}

.stat.ok .n {
  color: var(--green);
}
.stat.warn .n {
  color: var(--orange);
}
.stat.bad .n {
  color: var(--red);
}
.stat.mute .n {
  color: var(--gray);
}

/* 進度條 */
.progress {
  height: 7px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  transition: width 0.5s var(--ease);
}

.progress.blue > i {
  background: var(--accent);
}

/* ---------- 底部面板 ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.24s var(--ease);
}

.sheet-backdrop.show {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 100%);
  width: min(100%, 560px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 48px -12px rgba(0, 0, 0, 0.4);
  z-index: 101;
  transition: transform 0.34s var(--ease);
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet.show {
  transform: translate(-50%, 0);
}

.sheet-grip {
  width: 38px;
  height: 5px;
  border-radius: 3px;
  background: var(--line-strong);
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 12px;
  flex-shrink: 0;
}

.sheet-head .t {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.sheet-body {
  padding: 0 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-foot {
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  background: var(--surface);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s;
}

.modal-backdrop.show {
  opacity: 1;
}

.modal {
  width: min(100%, 340px);
  background: var(--surface);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow-float);
  transform: scale(0.94);
  transition: transform 0.24s var(--ease);
}

.modal-backdrop.show .modal {
  transform: scale(1);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal p {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.55;
}

.modal .modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal .modal-actions .btn {
  flex: 1;
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + 90px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(100% - 40px, 420px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: rgba(28, 30, 36, 0.94);
  backdrop-filter: blur(16px);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-float);
  animation: toastIn 0.3s var(--ease) both;
  max-width: 100%;
}

html.dark .toast {
  background: rgba(245, 246, 250, 0.95);
  color: #111;
}

.toast.out {
  animation: toastOut 0.26s var(--ease) both;
}

.toast svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.toast.ok svg {
  color: #4ade80;
}
.toast.err svg {
  color: #ff7b72;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}

/* ---------- 空狀態 ---------- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-2);
}

.empty .ico {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-3);
}

.empty .ico svg {
  width: 30px;
  height: 30px;
  stroke-width: 1.6;
}

.empty .t {
  font-weight: 700;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 5px;
}

.empty .d {
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- 載入 ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 10px;
}

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

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ---------- 碼框（接龍預覽） ---------- */
.codebox {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- 開關 ---------- */
.switch {
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: var(--surface-3);
  transition: background 0.22s var(--ease);
  flex-shrink: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s var(--ease);
}

.switch.on {
  background: var(--green);
}

.switch.on::after {
  transform: translateX(20px);
}

/* ---------- 分段資訊列 ---------- */
.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.kv:last-child {
  border-bottom: 0;
}

.kv .k {
  color: var(--text-2);
  flex-shrink: 0;
}

.kv .v {
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}

/* ---------- 提示條 ---------- */
.banner {
  display: flex;
  gap: 10px;
  padding: 13px 15px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  align-items: flex-start;
}

.banner svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.banner.info {
  background: var(--accent-soft);
  color: var(--accent);
}
.banner.warn {
  background: var(--orange-soft);
  color: #b26b00;
}
html.dark .banner.warn {
  color: var(--orange);
}
.banner.danger {
  background: var(--red-soft);
  color: var(--red);
}
.banner.ok {
  background: var(--green-soft);
  color: #1f8b45;
}
html.dark .banner.ok {
  color: var(--green);
}

/* ---------- 時間 chips ---------- */
.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 4px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13.5px;
  font-weight: 650;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.16s;
}

.chip.on {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.chip:active {
  transform: scale(0.95);
}
