@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;600&display=swap');

:root {
  --page-bg: #050816;
  --surface: #0f172a;
  --surface-light: #182640;
  --surface-muted: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f6fb;
  --text-muted: rgba(244, 246, 251, 0.7);
  --brand: #ff9b50;
  --brand-strong: #ff6a3c;
  --accent: #19a7ff;
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --warning: #facc15;
  --danger: #fb7185;
  --card-radius: 18px;
  --nav-width: 220px;
}

* {
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
}

body {
  font-family: 'Noto Sans SC', 'Space Grotesk', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  color: var(--text);
  background: radial-gradient(circle at 15% 20%, rgba(32, 88, 255, 0.2), transparent 55%),
              radial-gradient(circle at 85% 10%, rgba(255, 114, 63, 0.18), transparent 45%),
              var(--page-bg);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
}

/* ===== Layout Shell ===== */
.page-shell {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar Navigation ===== */
.app-nav {
  width: var(--nav-width);
  flex-shrink: 0;
  background: rgba(9, 14, 32, 0.85);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--surface-muted);
  padding: 24px 20px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: 100vh;
}

.app-nav__brand {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.app-nav__brand span {
  display: inline-flex;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: #050816;
}

.nav-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.92rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-links a.is-active {
  background: rgba(255, 155, 80, 0.15);
  color: var(--brand);
  border-left: 3px solid var(--brand);
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.nav-footer {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Main Content ===== */
.page-main {
  flex: 1;
  min-width: 0;              /* KEY: allows flex child to shrink below content width */
  max-width: 100%;
  padding: 24px clamp(16px, 3vw, 36px);
  overflow-x: hidden;        /* prevent any horizontal scroll on the main area */
}

/* ===== Cards & Panels ===== */
.card,
.panel {
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid var(--surface-muted);
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: 0 20px 50px rgba(5, 8, 22, 0.45);
}

.panel + .panel {
  margin-top: 18px;
}

.sync-panel {
  display: grid;
  gap: 14px;
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
  align-items: center;
}

.section-heading {
  margin: 0 0 8px;
  font-size: 1.25rem;
  font-weight: 600;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

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

.btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #050816;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

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

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #f43f5e);
  color: #fff;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

/* ===== Forms ===== */
.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid.two-cols {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-top: 10px;
}

.filter-grid .form-field {
  flex: 1 1 160px;
  max-width: 220px;
}

.form-field label {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.form-field span {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

input[type="text"],
input[type="date"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}

input::placeholder,
textarea::placeholder {
  color: rgba(244, 246, 251, 0.4);
}

textarea {
  min-height: 150px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(25, 167, 255, 0.15);
}

/* ===== Alerts ===== */
.alert {
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.alert-info {
  background: rgba(25, 167, 255, 0.1);
  border: 1px solid rgba(25, 167, 255, 0.4);
}

.alert-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.5);
}

.alert-danger {
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.45);
}

/* ===== Misc ===== */
.guidelines-list {
  list-style: decimal;
  padding-left: 20px;
  line-height: 1.6;
}

.danger-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-inline select {
  width: auto;
  min-width: 140px;
}

.guidelines-list code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

/* ===== Mini Table (sync diff) ===== */
.mini-table table {
  font-size: 0.82rem;
}

.mini-table th,
.mini-table td {
  white-space: nowrap;
}

/* ===== Stat Grid ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-card ul {
  list-style: none;
  padding-left: 0;
  margin: 8px 0 0;
}

.stat-card ul li {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.stat-value {
  margin-top: 4px;
  font-size: 1.5rem;
  font-weight: 600;
}

/* ===== Generic Table Wrapper ===== */
.table-wrapper {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
  background: rgba(8, 12, 25, 0.7);
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-wrapper th,
.table-wrapper td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

.table-wrapper thead {
  background: rgba(255, 255, 255, 0.04);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
}

.table-wrapper tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* ===== Attendance Grid (THE key section) ===== */
.attendance-grid {
  overflow: visible;       /* let child handle scrolling */
  padding: 16px 0;
}

.attendance-grid .table-wrapper {
  overflow-x: auto;        /* only this scrolls horizontally */
  -webkit-overflow-scrolling: touch;
  max-height: 70vh;        /* make it vertically bounded too */
  overflow-y: auto;
}

/* Sticky first two columns: # and player name */
.attendance-grid .table-wrapper th:nth-child(1),
.attendance-grid .table-wrapper td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 3;
  background: rgba(8, 12, 25, 0.97);
  min-width: 36px;
}

.attendance-grid .table-wrapper th:nth-child(2),
.attendance-grid .table-wrapper td:nth-child(2) {
  position: sticky;
  left: 36px;
  z-index: 3;
  background: rgba(8, 12, 25, 0.97);
  min-width: 100px;
}

/* Make header sticky vertically */
.attendance-grid .table-wrapper thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: rgba(15, 23, 42, 0.98);
}

/* Intersection of sticky row and sticky column needs higher z */
.attendance-grid .table-wrapper thead th:nth-child(1),
.attendance-grid .table-wrapper thead th:nth-child(2) {
  z-index: 5;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.player-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.select-attendance {
  min-width: 80px;
  font-size: 0.82rem;
  padding: 6px 8px;
}

/* ===== Status Chips ===== */
.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
}

.status-canyu { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.status-qingjia { background: rgba(14, 165, 233, 0.2); color: var(--accent-strong); }
.status-tibu { background: rgba(250, 204, 21, 0.18); color: var(--warning); }
.status-quexin { background: rgba(251, 113, 133, 0.2); color: var(--danger); }
.status-weirubang { background: rgba(148, 163, 184, 0.2); color: #cbd5f5; }

.chip {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== Auth Page ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: min(420px, 90vw);
  background: rgba(7, 11, 26, 0.8);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 28px;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.55);
}

/* ===== History / Report Grids ===== */
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.history-card {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 16, 33, 0.85);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-card code {
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.details-block {
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.details-block pre {
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.82rem;
}

/* ===== Dialogs ===== */
.report-dialog {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(5, 8, 22, 0.98);
  color: var(--text);
  width: min(720px, 90vw);
  padding: 0;
}

.report-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.dialog-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 70vh;
  overflow-y: auto;
}

.filter-bar {
  margin-top: 14px;
}

.history-grid + .history-grid {
  margin-top: 14px;
}

/* ===== Analysis Section ===== */
.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.trend-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px;
  background: rgba(15, 23, 42, 0.76);
}

.trend-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.sparkline {
  width: 100%;
  height: 50px;
}

.sparkline polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.trend-legends {
  margin-top: 8px;
  display: grid;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ===== Utility ===== */
.mt-3 {
  margin-top: 16px;
}

.app-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(25, 167, 255, 0.15);
  border: 1px solid rgba(25, 167, 255, 0.4);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Dark Mode Contrast Fixes ===== */
/* Ensure all primary text in panels/tables is bright enough on dark backgrounds */
.panel,
.card {
  color: var(--text);
}

.panel h1,
.panel h2,
.panel h3,
.panel h4,
.panel h5,
.panel h6,
.panel p,
.panel span,
.panel label {
  color: var(--text);
}

/* Muted helper text in panels/cards — brighten for dark mode */
.panel .text-muted,
.card .text-muted {
  color: rgba(244, 246, 251, 0.88);
}

/* Improve contrast for table content in dark mode */
.table-wrapper th,
.table-wrapper td {
  color: var(--text);
}

/* Specific labels that were reported as too dark */
.section-heading,
.chip,
.stat-label {
  color: var(--text);
}

/* Status chips keep their semantic colors but brighten text where needed */
.status-chip {
  color: var(--text);
}

/* Strong copy paragraphs that must be fully legible in dark mode */
.section-copy {
  color: #fdfdfd;
  font-size: 0.9rem;
}

/* ===== Live Console (tail -f style) ===== */
.live-console {
  background: #0d1117;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  color: #e6edf3;
}

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.85rem;
}

.console-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.console-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6e7681;
}

.console-status-dot.idle {
  background: #6e7681;
}

.console-status-dot.streaming {
  background: var(--success);
  animation: console-pulse 1s ease-in-out infinite;
}

.console-status-dot.done {
  background: var(--accent);
}

.console-status-dot.error {
  background: var(--danger);
}

@keyframes console-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.console-output {
  max-height: 400px;
  overflow: auto;
  padding: 12px 14px;
  font-family: 'Consolas', 'Monaco', 'Menlo', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.console-output:empty::before {
  content: '暂无输出。提交任务或查询运行中的任务后将在此显示实时日志。';
  color: var(--text-muted);
}

.console-line {
  margin-bottom: 2px;
}

.console-line .ts {
  color: rgba(244, 246, 251, 0.6);
  margin-right: 8px;
}

.console-line .msg {
  color: #e6edf3;
}

/* ===== Responsive: Tablet & Phone ===== */
@media (max-width: 960px) {
  .page-shell {
    flex-direction: column;
  }

  .app-nav {
    position: relative;
    width: 100%;
    flex-direction: column;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--surface-muted);
    padding: 12px 16px;
  }

  .nav-links {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .nav-links a {
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .app-nav__brand {
    margin-bottom: 8px;
    font-size: 0.95rem;
  }

  .nav-footer {
    margin-top: 8px;
    flex-direction: row;
  }

  .page-main {
    padding: 16px 12px;
  }

  .section-heading {
    font-size: 1.1rem;
  }

  .panel {
    padding: 14px;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .history-grid {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    gap: 8px;
  }

  .filter-grid .form-field {
    flex: 1 1 120px;
    max-width: none;
  }

  /* Make the attendance table take more screen real estate on mobile */
  .attendance-grid .table-wrapper {
    max-height: 60vh;
    border-radius: 12px;
  }

  .attendance-grid .table-wrapper th:nth-child(2),
  .attendance-grid .table-wrapper td:nth-child(2) {
    min-width: 80px;
  }

  .select-attendance {
    min-width: 68px;
    font-size: 0.78rem;
    padding: 5px 6px;
  }

  .danger-zone {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .action-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .btn {
    font-size: 0.82rem;
    padding: 8px 14px;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .attendance-grid .table-wrapper {
    max-height: 55vh;
  }
}
