:root {
  color-scheme: light dark;
  font-family: "Segoe UI", Arial, sans-serif;
  background-color: #0e1420;
  color: #f4f7ff;
}

body {
  margin: 0;
  padding: 0 0 48px;
  background: radial-gradient(circle at top, #1a2540, #0e1420 55%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 改善手機觸控體驗 */
  -webkit-tap-highlight-color: rgba(57, 160, 255, 0.2);
  touch-action: manipulation;
}

header {
  padding: 32px 24px 16px;
}

.header-content {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  position: absolute;
  top: 0;
  right: 0;
}

.header-content > div:first-child {
  text-align: center;
  width: 100%;
  flex: 0 0 auto;
}

header h1 {
  margin-bottom: 8px;
  font-size: 2rem;
}

header p {
  margin: 0;
  color: #c9d7ff;
}

.language-switcher {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lang-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(201, 215, 255, 0.3);
  background: rgba(18, 26, 44, 0.6);
  color: #c9d7ff;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-btn:hover {
  background: rgba(18, 26, 44, 0.8);
  border-color: rgba(201, 215, 255, 0.5);
}

.lang-btn.active {
  background: linear-gradient(135deg, #2f8cff, #39a0ff);
  border-color: #39a0ff;
  color: #f4f7ff;
  box-shadow: 0 4px 12px rgba(57, 160, 255, 0.3);
}

.button--ghost {
  background: rgba(18, 26, 44, 0.6);
  border: 1px solid rgba(201, 215, 255, 0.3);
  box-shadow: none;
  color: #c9d7ff;
}

.button--ghost:hover {
  background: rgba(18, 26, 44, 0.85);
  border-color: rgba(201, 215, 255, 0.5);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* 主面板寬度不變 */
.panel {
  background: rgba(18, 26, 44, 0.92);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

/* 登入視窗寬度設為主面板的1/4 */
#login-panel {
  max-width: 275px;
  width: 100%;
  margin: 0 auto 24px auto;
}

form {
  display: grid;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.triple {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.field.toggles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px 14px;
  align-items: center;
}

.field.toggles .label {
  grid-column: 1 / -1;
  font-weight: 600;
  color: #b8c7ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field.toggles label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: #d8e4ff;
}

label {
  font-weight: 600;
  color: #b8c7ff;
}

input[type="file"],
input[type="number"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #32425f;
  background: #eef2ff;
  color: #1b2538;
  font-size: 0.95rem;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #2f8cff, #39a0ff);
  color: #f4f7ff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(57, 160, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(57, 160, 255, 0.45);
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

#status {
  margin: 12px 0 0;
  color: #d1ddff;
}

#status.error {
  color: #ffb6b9;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

#metadata, #summary {
  margin: 16px 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.meta-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(40, 58, 96, 0.65);
}

.meta-item .label {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #aacaef;
  margin-bottom: 4px;
}

.table-wrapper {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid rgba(88, 117, 166, 0.4);
  max-height: 480px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

thead th {
  position: sticky;
  top: 0;
  background: #24335a;
  color: #f4f7ff;
  text-align: right;
  padding: 8px 12px;
  font-size: 0.85rem;
}

tbody td, thead th:first-child {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(80, 109, 160, 0.35);
  font-variant-numeric: tabular-nums;
}

tbody tr:nth-child(odd) {
  background: rgba(24, 36, 62, 0.65);
}

tbody tr:nth-child(even) {
  background: rgba(18, 26, 44, 0.65);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 24px;
  position: relative;
}

.chart-card {
  background: rgba(16, 24, 40, 0.92);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(72, 108, 168, 0.35);
  position: relative;
  overflow: visible;
  transition: z-index 0s;
}

.chart-card:hover {
  z-index: 100;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 200;
}

.chart-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #e7efff;
}

.chart-header button {
  padding: 8px 12px;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(57, 160, 255, 0.25);
  position: relative;
  z-index: 201;
}

.chart-card--square .chart-canvas {
  aspect-ratio: 1 / 1;
  height: auto;
}

/* .chart-card--square 的放大效果已由 .chart-card:hover .chart-canvas 統一處理 */

.chart-canvas {
  width: 100%;
  height: 260px;
  border-radius: 10px;
  background: rgba(12, 18, 32, 0.85);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: zoom-in;
  transform-origin: center top;
  position: relative;
  z-index: 1;
  touch-action: manipulation; /* 改善觸控響應 */
}

.chart-card:hover .chart-canvas {
  transform: scale(1.5);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  z-index: 1;
}

.chart-note {
  font-size: 0.8rem;
  color: #9eb8ff;
}

/* 手機版響應式設計 */
@media (max-width: 768px) {
  /* Header 優化 */
  header {
    padding: 20px 16px 12px;
  }

  header h1 {
    font-size: 1.5rem;
    margin-bottom: 6px;
  }

  header p {
    font-size: 0.85rem;
  }

  .header-content {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    position: relative;
  }

  .header-content > div:first-child {
    text-align: center;
    width: 100%;
  }

  .header-actions {
    position: relative;
    top: auto;
    right: auto;
    justify-content: center;
    width: 100%;
    flex-wrap: wrap;
  }

  .language-switcher {
    justify-content: center;
  }

  .lang-btn {
    padding: 8px 16px;
    font-size: 0.95rem;
    min-width: 80px;
  }

  .header-actions .button {
    width: auto;
  }

  /* Main 區域 */
  main {
    padding: 0 12px;
    gap: 16px;
  }

  /* Panel 優化 */
  .panel {
    padding: 16px;
    border-radius: 10px;
  }

  /* 登入面板 */
  #login-panel {
    max-width: 100%;
    padding: 20px;
  }

  /* 表單優化 */
  form {
    gap: 14px;
  }

  .field {
    gap: 8px;
  }

  .field.triple {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  label {
    font-size: 0.9rem;
  }

  input[type="file"],
  input[type="number"] {
    padding: 12px 14px;
    font-size: 1rem;
    min-height: 44px; /* 觸控目標最小尺寸 */
  }

  /* 按鈕優化 */
  button,
  .button {
    padding: 14px 20px;
    font-size: 1rem;
    min-height: 44px; /* 觸控目標最小尺寸 */
    width: 100%;
  }

  .button--small {
    padding: 10px 16px;
    font-size: 0.95rem;
    min-height: 40px;
  }

  /* 結果區域 */
  .result-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .result-header h2 {
    font-size: 1.3rem;
    margin: 0;
  }

  .actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }

  .actions .button {
    width: 100%;
  }

  /* Metadata 和 Summary */
  #metadata, #summary {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .meta-item {
    padding: 12px;
  }

  /* 表格優化 */
  .table-wrapper {
    max-height: 400px;
    -webkit-overflow-scrolling: touch; /* iOS 平滑滾動 */
  }

  table {
    min-width: 500px;
    font-size: 0.85rem;
  }

  thead th {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  tbody td {
    padding: 6px 8px;
  }

  /* 圖表網格優化 */
  .chart-grid {
    grid-template-columns: 1fr; /* 手機上單列顯示 */
    gap: 16px;
    margin-top: 20px;
  }

  .chart-card {
    padding: 12px;
    width: 100%;
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .chart-header h3 {
    font-size: 1rem;
    width: 100%;
  }

  .chart-header button {
    width: 100%;
    padding: 10px;
    font-size: 0.9rem;
  }

  .chart-canvas {
    height: 240px;
    width: 100%;
  }

  .chart-card--square .chart-canvas {
    height: auto;
    min-height: 240px;
  }

  /* 禁用 hover 放大效果，改為點擊 */
  .chart-card:hover .chart-canvas {
    transform: none;
    box-shadow: none;
  }

  .chart-note {
    font-size: 0.75rem;
    line-height: 1.4;
  }

  /* Uploads 區域 */
  .uploads-section {
    margin-top: 20px;
    padding-top: 20px;
  }

  .uploads-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .uploads-section h3 {
    font-size: 1rem;
  }

  .uploads-header button {
    width: 100%;
  }

  .uploads-list {
    height: 220px;
    max-height: 220px;
    -webkit-overflow-scrolling: touch;
  }

  .upload-item {
    padding: 12px;
    min-height: 48px; /* 觸控目標 */
  }

  .upload-filename {
    font-size: 0.85rem;
  }

  .upload-meta {
    font-size: 0.75rem;
  }

  .uploads-pagination {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .uploads-pagination-btns {
    width: 100%;
    display: flex;
    gap: 10px;
  }

  .uploads-pagination-btns button {
    flex: 1;
  }

  .uploads-page-info {
    text-align: center;
    font-size: 0.85rem;
  }

  /* Status */
  #status {
    font-size: 0.9rem;
    margin: 10px 0 0;
  }
}

/* 更小的手機（< 480px） */
@media (max-width: 480px) {
  header h1 {
    font-size: 1.3rem;
  }

  header p {
    font-size: 0.8rem;
  }

  main {
    padding: 0 10px;
  }

  .panel {
    padding: 14px;
  }

  .chart-canvas {
    height: 200px;
  }

  .chart-card--square .chart-canvas {
    min-height: 200px;
  }

  .uploads-list {
    height: 180px;
    max-height: 180px;
  }
}

/* Uploads 區域樣式 */
.uploads-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(201, 215, 255, 0.1);
}

.uploads-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.uploads-section h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #e7efff;
}

.button--small {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.uploads-list {
  height: 260px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid rgba(201, 215, 255, 0.1);
  border-radius: 8px;
  padding: 8px;
  background: rgba(12, 18, 32, 0.5);
}

.uploads-list .loading,
.uploads-list .empty,
.uploads-list .error {
  text-align: center;
  padding: 24px;
  color: #9eb8ff;
  margin: 0;
}

.uploads-list .error {
  color: #ff6b6b;
}

.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: rgba(18, 26, 44, 0.6);
  border-radius: 6px;
  border: 1px solid rgba(201, 215, 255, 0.05);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  cursor: pointer;
  user-select: none;
}

.upload-item:hover {
  background: rgba(18, 26, 44, 0.8);
  border-color: rgba(201, 215, 255, 0.15);
  transform: translateX(2px);
}

.upload-item:focus {
  outline: 2px solid rgba(57, 160, 255, 0.5);
  outline-offset: 2px;
}

.upload-item:active {
  transform: translateX(1px);
}

.upload-item:last-child {
  margin-bottom: 0;
}

.upload-filename {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  color: #e7efff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-meta {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: #9eb8ff;
}

.uploads-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.uploads-page-info {
  font-size: 0.9rem;
  color: #9eb8ff;
}

.uploads-pagination-btns {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #32425f;
  background: #eef2ff;
  color: #1b2538;
  font-size: 0.95rem;
}

#profile {
  display: grid;
  gap: 12px;
}

.table-wrapper button {
  margin: 0 6px 6px 0;
  padding: 8px 12px;
  font-size: 0.9rem;
}

[hidden] {
  display: none !important;
}
