/* ==========================================
   1. 設計系統與全域樣式 (Design System)
   ========================================== */
:root {
  --bg-main: #0b0f19;         /* 極深太空藍 slate-950 */
  --bg-card: #131c2e;         /* 卡片深藍 slate-900 */
  --bg-table-header: #1e293b; /* 表頭深灰 slate-800 */
  --bg-input: #1e293b;        /* 輸入框背景 */
  --text-main: #f8fafc;       /* 主文字 slate-50 */
  --text-light: #94a3b8;      /* 次要文字 slate-400 */
  --primary: #4f46e5;         /* 靛藍色 indigo-600 */
  --primary-hover: #4338ca;   /* 靛藍深色 indigo-700 */
  --accent: #10b981;          /* 翡翠綠 (進行中/更新成功) */
  --accent-hover: #059669;    /* 翡翠綠深色 */
  --danger: #ef4444;          /* 紅色 (重設與錯誤) */
  --border: #334155;          /* 邊框顏色 slate-700 */
  --border-light: #1e293b;    /* 輕邊框 */
  --gold: #fbbf24;            /* 隊伍清單點綴金 */
  --font-main: 'Outfit', 'Noto Sans TC', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==========================================
   2. 網頁版主佈局 (Wrapper & Container)
   ========================================== */
.main-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.container {
  display: grid;
  grid-template-columns: 3.2fr 1fr;
  gap: 24px;
  margin-top: 24px;
}

@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr; /* 平板與手機版改為單欄 */
  }
}

/* ==========================================
   3. 標頭區設計 (Header)
   ========================================== */
header {
  background: linear-gradient(135deg, #1e1b4b 0%, #111827 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.header-info h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(to right, #818cf8, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.header-info p {
  color: var(--text-light);
  font-size: 0.95rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ==========================================
   4. 通用按鈕樣式 (Buttons)
   ========================================== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: white;
}

.btn-primary {
  background-color: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.btn-accent {
  background-color: var(--accent);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-accent:hover:not(:disabled) {
  background-color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn:active {
  transform: translateY(0);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}

/* ==========================================
   5. 看板表格設計 (Scoreboard Table)
   ========================================== */
.scoreboard-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  min-width: 850px;
}

th, td {
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

thead tr:first-child th {
  font-size: 1.15rem;
  font-weight: 600;
  background-color: var(--bg-table-header);
  color: var(--text-main);
  border-bottom: 2px solid var(--border);
}

thead tr:nth-child(2) th {
  font-size: 0.85rem;
  font-weight: 500;
  background-color: rgba(15, 23, 42, 0.4);
  color: var(--text-light);
  padding: 8px;
}

.time-col {
  font-family: monospace;
  font-weight: 700;
  color: var(--text-light);
  background-color: rgba(15, 23, 42, 0.3);
  border-right: 1px solid var(--border);
  font-size: 0.95rem;
  width: 110px;
}

.match-cell {
  font-size: 0.95rem;
  font-weight: 500;
  width: 17%;
}

.score-cell {
  border-right: 2px solid rgba(255, 255, 255, 0.08);
  width: 9%;
}

.score-cell:last-child {
  border-right: none;
}

.score-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 30px;
  font-weight: 700;
  font-family: 'Outfit', monospace;
  font-size: 1.05rem;
  background-color: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  color: var(--text-light);
  min-width: 62px;
  transition: all 0.3s ease;
}

.score-badge.has-score {
  background-color: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

tbody tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.015);
}

tbody tr:hover {
  background-color: rgba(99, 102, 241, 0.03);
}

/* ==========================================
   6. 側邊欄元件 (Sidebar Elements)
   ========================================== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.sidebar-card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  border-left: 4px solid var(--primary);
  padding-left: 10px;
  color: var(--text-main);
}

.team-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.team-item {
  padding: 10px 12px;
  background-color: rgba(15, 23, 42, 0.4);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
  font-size: 0.9rem;
  font-weight: 500;
  transition: transform 0.2s ease;
}

.team-item:hover {
  transform: translateX(4px);
  background-color: rgba(15, 23, 42, 0.6);
}

.qr-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-container {
  background-color: white;
  padding: 12px;
  border-radius: 12px;
  margin: 16px 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.qr-container img {
  display: block;
  width: 140px;
  height: 140px;
}

.qr-link-text {
  font-size: 0.8rem;
  color: var(--text-light);
  word-break: break-all;
  background: rgba(15, 23, 42, 0.5);
  padding: 8px 12px;
  border-radius: 8px;
  width: 100%;
  user-select: all;
}

/* ==========================================
   7. 裁判手機介面佈局 (Referee Dashboard)
   ========================================== */
.dashboard {
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 40px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background-color: var(--bg-card);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  justify-content: center;
}

.filter-btn {
  flex: 1 1 calc(20% - 8px);
  min-width: 60px;
  background-color: transparent;
  border: none;
  color: var(--text-light);
  padding: 10px 6px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.filter-btn.active {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.match-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-bottom: 8px;
}

.match-time {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: bold;
}

.match-court-tag {
  background-color: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

/* 核心優化：醒目局數對戰標題 */
.match-title-large {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-main);
  background-color: rgba(15, 23, 42, 0.4);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  letter-spacing: 0.05rem;
}

/* 比分計分器區塊 */
.stepper-container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 10px;
  padding: 6px 0;
}

.team-stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.team-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-light);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.stepper-ctrl {
  display: flex;
  align-items: center;
  background-color: rgba(15, 23, 42, 0.6);
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
}

.stepper-btn {
  width: 48px;
  height: 48px;
  background-color: transparent;
  border: none;
  color: white;
  font-size: 1.6rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper-btn:active {
  background-color: rgba(255, 255, 255, 0.1);
}

.stepper-value {
  width: 48px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  font-family: 'Outfit', monospace;
}

.stepper-divider {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-light);
  padding-top: 28px;
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn-update {
  flex: 3;
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

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

.btn-reset {
  flex: 1;
  background-color: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--danger);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-reset:active {
  background-color: rgba(239, 68, 68, 0.25);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  background-color: var(--bg-card);
  border-radius: 16px;
  border: 1px dashed var(--border);
}

/* ==========================================
   8. 裁判驗證畫面 (Referee Login Screen)
   ========================================== */
.login-container {
  margin: auto;
  max-width: 360px;
  width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}

.login-logo svg {
  width: 32px;
  height: 32px;
  fill: white;
}

.login-container h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.login-container p {
  color: var(--text-light);
  font-size: 0.9rem;
}

.pin-input {
  width: 100%;
  background-color: rgba(15, 23, 42, 0.6);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 1.25rem;
  color: white;
  text-align: center;
  letter-spacing: 0.5rem;
  font-weight: bold;
  outline: none;
  transition: all 0.2s ease;
}

.pin-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

/* ==========================================
   9. 管理員彈出視窗設計 (Admin Modal Card)
   ========================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(11, 15, 25, 0.85);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.15);
}

.modal-overlay.show .modal-card {
  transform: translateY(0);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-light);
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: 80vh;
}

.form-control {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: white;
  padding: 10px 14px;
  font-size: 0.95rem;
  width: 100%;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
}

/* 後端操作卡片 */
.admin-card {
  background-color: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 16px;
}

.admin-card h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.admin-desc {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 12px;
}

.file-upload-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-name-label {
  font-size: 0.8rem;
  color: var(--text-light);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================
   10. 載入提示與訊息元件 (Loaders & Toast)
   ========================================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(11, 15, 25, 0.85);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--accent);
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 2001;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

.toast-container.show {
  transform: translateX(-50%) translateY(0);
}

.toast-container.error {
  background-color: var(--danger);
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.3);
}

/* 狀態指示燈 */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.6);
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid rgba(255,255,255,0.06);
  font-size: 0.82rem;
  color: var(--text-light);
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent);
  border-radius: 50%;
  position: relative;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}
