/* ================================================
   SportHub — Base Styles
   Variables, Reset, Shared Components
   ================================================ */

/* ─── CSS Variables / Theme ─── */
:root {
  --font-display: 'Outfit', 'Noto Sans TC', sans-serif;
  --font-body: 'Noto Sans TC', 'Outfit', sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-full: 999px;
  --shadow: 0 2px 12px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.18);
  --transition: .25s cubic-bezier(.4,0,.2,1);
  --topbar-h: 56px;
  --bottombar-h: 64px;
  --role-bar-h: 52px;
}

[data-theme="dark"] {
  --bg-root: #0d1017;
  --bg-card: #181d27;
  --bg-elevated: #222838;
  --bg-input: #222838;
  --border: #323a4e;
  --text-primary: #f5f7fa;
  --text-secondary: #e8ecf2;
  --text-muted: #cdd3de;
  --primary: #3b82f6;
  --accent: #34d399;
  --accent-hover: #6ee7b7;
  --accent-bg: rgba(52,211,153,.16);
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #60a5fa;
  --success: #34d399;
  --overlay: rgba(0,0,0,.65);
  --banner-shadow: 0 4px 24px rgba(0,0,0,.5);
  --skeleton-base: var(--bg-elevated);
  --skeleton-glow: var(--bg-card);
}

[data-theme="light"] {
  --bg-root: #f4f6f9;
  --bg-card: #ffffff;
  --bg-elevated: #f0f2f5;
  --bg-input: #f0f2f5;
  --border: #dfe3ea;
  --text-primary: #1a1d24;
  --text-secondary: #5a6478;
  --text-muted: #8892a4;
  --primary: #2563eb;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-bg: rgba(13,148,136,.1);
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --success: #059669;
  --overlay: rgba(0,0,0,.35);
  --banner-shadow: 0 4px 24px rgba(0,0,0,.12);
  --skeleton-base: var(--bg-elevated);
  --skeleton-glow: var(--bg-card);
}

/* ─── Reset ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, [contenteditable] {
  -webkit-user-select: auto;
  user-select: auto;
}
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-root);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--topbar-h);
  padding-bottom: var(--bottombar-h);
  transition: background var(--transition), color var(--transition);
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: .93rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .75rem;
  outline: none;
  transition: border var(--transition);
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; padding-right: 2rem; }
img { max-width: 100%; display: block; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Main Content / Pages ─── */
#main-content { max-width: 560px; margin: 0 auto; padding: .5rem; min-height: calc(100dvh - var(--topbar-h) - var(--bottombar-h)); }
.page { display: none; animation: fadeIn .3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Section Title ─── */
.section-title { font-weight: 700; font-size: .9rem; margin: 1rem 0 .5rem .2rem; color: var(--text-primary); }

/* ─── My Section (Role Gated) ─── */
.my-section { padding: .2rem; margin-bottom: .5rem; }

/* ─── Card List ─── */
.card-list { display: flex; flex-direction: column; gap: .65rem; padding-bottom: 1rem; }

/* ─── Tab Bar ─── */
.tab-bar { display: flex; gap: .25rem; padding: .3rem; background: var(--bg-elevated); border-radius: var(--radius); margin-bottom: .8rem; overflow-x: auto; }
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar.compact { padding: .2rem; }
.tab { padding: .45rem .7rem; border-radius: var(--radius-sm); font-size: .78rem; font-weight: 600; color: var(--text-muted); transition: all var(--transition); white-space: nowrap; flex-shrink: 0; }
.tab.active { background: var(--bg-card); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ─── Info Card ─── */
.info-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: .85rem; margin-bottom: .65rem; }
.info-title { font-weight: 700; font-size: .85rem; margin-bottom: .6rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
.info-row { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; font-size: .82rem; }
.info-row > span:first-child { color: var(--text-muted); font-size: .78rem; }

/* ─── Buttons ─── */
.primary-btn { background: var(--accent); color: #fff; padding: .55rem 1.2rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .85rem; transition: all var(--transition); }
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.primary-btn.small { padding: .35rem .75rem; font-size: .78rem; }
.primary-btn.full-width { width: 100%; text-align: center; margin-top: .5rem; }
.outline-btn { border: 1.5px solid var(--border); padding: .5rem 1rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .82rem; color: var(--text-secondary); transition: all var(--transition); }
.outline-btn:hover { border-color: var(--accent); color: var(--accent); }
.outline-btn.disabled, .outline-btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.outline-btn.full-width { width: 100%; text-align: center; }
.text-btn { color: var(--accent); font-weight: 600; font-size: .82rem; padding: .3rem .5rem; }
.text-btn:hover { background: var(--accent-bg); border-radius: var(--radius-sm); }
.action-btn { display: flex; align-items: center; gap: .4rem; background: var(--accent-bg); color: var(--accent); padding: .55rem .85rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .82rem; border: 1px solid transparent; transition: all var(--transition); }
.action-btn:hover { border-color: var(--accent); }
.edit-btn { font-size: .72rem; color: var(--accent); font-weight: 600; margin-left: .3rem; }
.danger-btn { background: var(--danger); color: #fff; padding: .5rem 1rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .82rem; }
.remove-btn { width: 26px; height: 26px; border-radius: 50%; background: rgba(248,113,113,.15); color: var(--danger); font-size: .8rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ─── Form Elements ─── */
.form-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.form-row { margin-bottom: .75rem; }
.form-row label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .3rem; }
.required { color: var(--danger); font-size: .7rem; }
.radio-group { display: flex; gap: 1rem; font-size: .85rem; }
.radio-group label { display: flex; align-items: center; gap: .3rem; cursor: pointer; color: var(--text-primary); font-weight: 400; }

/* ─── Input History Chips ─── */
.input-history-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-top: .25rem;
}
.input-history-chip {
  font-size: .68rem;
  padding: .15rem .45rem;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s;
}
.input-history-chip:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* App confirm modal */
.app-confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1300; align-items: center; justify-content: center; }
.app-confirm-overlay.open { display: flex; }
.app-confirm-box { background: var(--bg-card); border-radius: 14px; padding: 1.5rem 1.3rem 1.2rem; width: 280px; text-align: center; animation: scanPopIn .2s ease; }
.app-confirm-msg { font-size: .92rem; font-weight: 600; line-height: 1.5; margin-bottom: 1.2rem; color: var(--text-primary); }
.app-confirm-btns { display: flex; gap: .5rem; }
.app-confirm-btns button { flex: 1; padding: .55rem; border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: .88rem; cursor: pointer; }
.app-confirm-cancel { background: var(--bg-elevated); color: var(--text-secondary); }
.app-confirm-ok { background: var(--primary); color: #fff; }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: var(--overlay);
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; z-index: 1110;
  bottom: 0; left: 0; right: 0;
  max-height: 80vh;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}
.modal.open { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-card); z-index: 1; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.modal-close:hover { background: var(--bg-elevated); }
.modal-body { padding: 1rem 1.2rem; font-size: .88rem; line-height: 1.7; color: var(--text-secondary); }
.modal-body h4 { color: var(--text-primary); font-size: .9rem; margin: .8rem 0 .3rem; }
.modal-body h4:first-child { margin-top: 0; }
.modal-actions { display: flex; gap: .5rem; padding: .75rem 1.2rem; border-top: 1px solid var(--border); justify-content: flex-end; }

/* ─── Create Event / Tournament Form ─── */
.ce-form { display: flex; flex-direction: column; gap: .75rem; }
.ce-row { display: flex; flex-direction: column; gap: .3rem; }
.ce-row label { font-size: .78rem; font-weight: 600; color: var(--text-secondary); }
.ce-row-half { flex-direction: row; gap: .4rem; }
.ce-row-half > div { flex: 1; display: flex; flex-direction: column; gap: .3rem; min-width: 0; overflow: hidden; }
.ce-row-half > div:first-child { flex: 0 0 40%; }
.ce-row-half input[type="date"] { width: 100%; min-width: 0; box-sizing: border-box; padding: .45rem .35rem; font-size: .82rem; }
.ce-row-half select { padding: .45rem .35rem; font-size: .82rem; padding-right: 1.4rem; background-position: right .3rem center; }

/* Delegate Search */
.ce-delegate-wrap { position: relative; line-height: 1.2; }
.ce-delegate-wrap input { margin: 0; padding: .4rem .5rem; font-size: .82rem; }
.ce-delegate-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .3rem; }
.ce-delegate-tags:empty { margin-bottom: 0; }
.ce-delegate-tag {
  display: inline-flex; align-items: center; gap: .2rem;
  background: transparent; font-size: .75rem;
  padding: 0; border-radius: 999px;
}
.ce-delegate-tag .user-capsule { margin: 0; }
.ce-delegate-tag .ce-delegate-remove {
  cursor: pointer; font-size: .82rem; line-height: 1; color: var(--text-muted); padding: .1rem .15rem;
}
.ce-delegate-tag .ce-delegate-remove:hover { color: var(--danger); }
.ce-delegate-dropdown {
  display: none; position: absolute; left: 0; right: 0; top: 100%;
  background: #1a1a2e; border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 100; max-height: 180px; overflow-y: auto;
}
.ce-delegate-dropdown.open { display: block; }
.ce-delegate-item {
  padding: .45rem .6rem; cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; gap: .4rem;
  border-bottom: 1px solid var(--border);
}
.ce-delegate-item:last-child { border-bottom: none; }
.ce-delegate-item:hover { background: rgba(99,102,241,.2); }
.ce-delegate-item-name { font-weight: 600; color: #e0e0e0; }
.ce-delegate-item-meta { font-size: .7rem; color: #999; }

/* Image Upload */
.ce-upload { width: 100%; }
.ce-upload-placeholder {
  width: 100%;
  aspect-ratio: 2.5/1;
  border: 2px dashed var(--border) !important;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-elevated);
  overflow: hidden;
}
.ce-upload-placeholder:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.ce-upload-placeholder.has-image {
  border-style: solid;
  padding: 0;
}
.ce-upload-icon { font-size: 1.5rem; color: var(--text-muted); font-weight: 300; }
.ce-upload-text { font-size: .82rem; font-weight: 600; color: var(--text-primary); }
.ce-upload-hint { font-size: .7rem; color: var(--text-muted); text-align: center; line-height: 1.4; }

/* ─── Status Classes ─── */
.status-active { background: rgba(52,211,153,.15); color: var(--success); }
.status-scheduled { background: rgba(96,165,250,.15); color: var(--info); }
.status-expired { background: rgba(248,113,113,.15); color: var(--danger); }
.status-open { background: rgba(52,211,153,.15); color: var(--success); }
.status-full { background: rgba(245,158,11,.15); color: #f59e0b; }
.status-ended { background: rgba(160,160,160,.15); color: var(--text-muted); }
.status-cancelled { background: rgba(248,113,113,.15); color: var(--danger); }
.status-upcoming { background: rgba(96,165,250,.15); color: var(--info); }

/* Dark theme status overrides */
[data-theme="dark"] .status-active { background: rgba(52,211,153,.20); }
[data-theme="dark"] .status-scheduled { background: rgba(96,165,250,.20); }
[data-theme="dark"] .status-expired { background: rgba(248,113,113,.20); }
[data-theme="dark"] .status-open { background: rgba(52,211,153,.20); }
[data-theme="dark"] .status-full { background: rgba(245,158,11,.20); }
[data-theme="dark"] .status-ended { background: rgba(160,160,160,.20); }
[data-theme="dark"] .status-cancelled { background: rgba(248,113,113,.20); }
[data-theme="dark"] .status-upcoming { background: rgba(96,165,250,.20); }

/* 正式版：初始隱藏 DEMO badge + 顯示載入中（JS 載入後接手控制） */
.prod-early .mode-badge { display: none; }

/* ─── Mode Badge ─── */
.mode-badge {
  position: fixed;
  bottom: calc(var(--bottombar-h) + 8px);
  right: 12px;
  background: rgba(220,38,38,.85);
  color: #fff;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .12em;
  padding: .15rem .5rem;
  border-radius: var(--radius-full);
  z-index: 1500;
  pointer-events: none;
  font-family: var(--font-display);
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(220,38,38,.3);
}

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: calc(var(--bottombar-h) + 16px); left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--bg-elevated); color: var(--text-primary);
  padding: .65rem 1.2rem; border-radius: var(--radius-full);
  font-size: .82rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  z-index: 10001;
  opacity: 0; pointer-events: none;
  transition: all .4s cubic-bezier(.4,0,.2,1);
  white-space: nowrap; max-width: 92vw; text-align: center; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

/* ─── Loading Overlay ─── */
.loading-overlay { position: fixed; inset: 0; z-index: 9999; background: var(--bg-root); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.loading-spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Utility ─── */
.hidden { display: none !important; }
.contact-row { display: none; }
[data-min-role] { display: none; }

/* ─── Responsive ─── */
@media (max-width: 480px) {
  .role-current-label { display: none; }
  .role-avatar-btn { padding: .3rem; }
  .role-arrow { display: none; }
}
@media (min-width: 600px) {
  #main-content { padding: .75rem 1rem; }
  .shop-grid { grid-template-columns: repeat(3, 1fr); }
  .ach-card-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 800px) {
  .shop-grid { grid-template-columns: repeat(4, 1fr); }
  #main-content { max-width: 640px; }
}

/* ─── Skeleton Screen ─── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--skeleton-base);
  border-radius: var(--radius, 14px);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--skeleton-glow) 50%, transparent 100%);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skeleton-card {
  height: 130px;
  min-width: 180px;
  flex-shrink: 0;
}
.skeleton-line { height: 12px; margin-bottom: .5rem; border-radius: var(--radius-sm, 8px); }
.skeleton-team-card {
  height: 200px;
  border-radius: var(--radius, 14px);
}

/* ─── LIFF 初始化進度條（Phase 4 期間顯示） ─── */
#liff-init-bar {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 3px;
  z-index: 9990;
  background: linear-gradient(90deg, var(--primary) 0%, #818cf8 50%, var(--primary) 100%);
  background-size: 200% 100%;
  animation: liff-bar-slide 1.6s linear infinite;
  opacity: 1;
  transition: opacity .4s ease;
}
#liff-init-bar.liff-hide { opacity: 0; }
@keyframes liff-bar-slide {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Deep link 等待卡片（分享連結進入時顯示） ─── */
#liff-deeplink-card {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9990;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: .7rem;
  font-size: .875rem;
  color: var(--text-secondary);
  opacity: 1;
  transition: opacity .4s ease;
  pointer-events: none;
}
#liff-deeplink-card.liff-hide { opacity: 0; }
.liff-card-spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: liff-spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes liff-spin { to { transform: rotate(360deg); } }
