/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Minimalist Editorial Theme - Light & Clean */
  --bg-main: #fcfcfc;
  --bg-card: #ffffff;
  --bg-card-hover: #f5f5f7;
  --bg-selected: #242424;
  --bg-output: #fafafa;
  --bg-input: #ffffff;

  --text-primary: #1d1d1f;
  --text-secondary: #515154;
  --text-muted: #86868b;
  --text-on-dark: #f5f5f7;
  --text-on-selected: #ffffff;
  
  --text-output-heading: #1d1d1f;
  --text-output-body: #333336;
  --text-output-accent: #0066cc;

  --border-light: #e5e5ea;
  --border-input: #d2d2d7;
  
  --accent-main: #000000;
  --accent-light: rgba(0,0,0,0.05);

  --radius-card: 4px;
  --radius-input: 4px;
  
  --spacing-section: 48px;

  /* Typography */
  --font-zh-serif: 'Noto Serif TC', serif;
  --font-zh-sans: 'Noto Sans TC', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-zh-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */
.app-header {
  padding: 24px 40px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-main);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-titlerow {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.app-logo {
  font-family: var(--font-zh-serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.05em;
}

.app-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.app-version {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.app-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
  font-weight: 300;
}

.app-container {
  display: grid;
  grid-template-columns: 1fr 480px;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 101px);
}

.form-panel {
  padding: 48px 56px 80px;
  overflow-y: auto;
}

.output-panel {
  position: sticky;
  top: 101px;
  height: calc(100vh - 101px);
  background: var(--bg-output);
  padding: 40px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-light);
}

/* ===== Form Sections ===== */
.form-section {
  margin-bottom: var(--spacing-section);
  animation: fadeIn 0.4s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.section-number {
  font-family: var(--font-zh-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-muted);
  width: 32px;
}

.form-section.has-value .section-number {
  color: var(--text-primary);
}

.section-title {
  font-family: var(--font-zh-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.section-hint {
  margin-left: 48px;
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-weight: 300;
}

/* ===== Inputs ===== */
.text-input-wrapper {
  margin-left: 48px;
}

.text-input {
  width: 100%;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-input);
  outline: none;
  transition: all var(--transition-fast);
}

.text-input:focus {
  border-color: var(--accent-main);
  box-shadow: 0 0 0 1px var(--accent-main);
}

.text-input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

/* ===== Cards Grid ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-left: 48px;
}

.card {
  position: relative;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.card:hover {
  border-color: var(--text-secondary);
  background: var(--bg-card-hover);
}

.card.selected {
  background: var(--bg-selected);
  border-color: var(--bg-selected);
  color: var(--text-on-selected);
}

.card-label {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
}

.card-sublabel {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 300;
}

.card.selected .card-sublabel {
  color: rgba(255, 255, 255, 0.7);
}

.card-check {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 18px;
  height: 18px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card.selected .card-check {
  opacity: 1;
}

.card-check svg {
  width: 16px;
  height: 16px;
}

.custom-role-wrapper {
  margin-top: 16px;
}

/* ===== Tasks List ===== */
.tasks-container {
  margin-left: 48px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state-text {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
  padding: 20px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-card);
  border: 1px dashed var(--border-light);
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.task-item:hover {
  border-color: var(--text-secondary);
  background: var(--bg-card-hover);
}

.task-item.selected {
  border-color: var(--accent-main);
  background: var(--accent-light);
}

.task-checkbox {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent-main);
  cursor: pointer;
  pointer-events: none; /* Let the label/item handle the click */
}

.task-content {
  flex: 1;
}

.task-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.task-desc {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 300;
}

/* ===== Output Panel ===== */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.output-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.output-status-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-main);
  border-radius: 50%;
}

.output-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.05em;
}

.output-char-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.output-content {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-output-body);
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 8px;
  background: var(--bg-card);
  padding: 24px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
}

.output-empty {
  color: var(--text-muted);
  font-family: var(--font-zh-sans);
  font-size: 14px;
  font-style: italic;
}

.output-footer {
  margin-top: 24px;
}

.output-footer-actions {
  display: flex;
  gap: 12px;
}

.btn-copy,
.btn-download {
  flex: 1;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-input);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.btn-copy {
  background: var(--bg-selected);
  color: var(--text-on-selected);
  border: 1px solid var(--bg-selected);
}

.btn-copy:hover {
  background: #000000;
}

.btn-copy.copied {
  background: #2ea043;
  border-color: #2ea043;
}

.btn-download {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-input);
}

.btn-download:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-secondary);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  .output-panel {
    position: relative;
    top: 0;
    height: auto;
    min-height: 500px;
    border-left: none;
    border-top: 1px solid var(--border-light);
  }
}

@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .app-header {
    padding: 16px 24px;
  }
  .form-panel, .output-panel {
    padding: 24px;
  }
  .cards-grid, .text-input-wrapper, .tasks-container, .section-hint {
    margin-left: 0;
  }
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .output-footer-actions {
    flex-direction: column;
  }
}
    /* ===== Stats Dashboard Bar ===== */
    .stats-bar {
      position: relative;
      z-index: 10;
      display: flex;
      align-items: stretch;
      gap: 14px;
      max-width: 1400px;
      margin: 0 auto;
      padding: 16px 40px;
      flex-wrap: wrap;
    }

    .stat-item {
      flex: 1 1 200px;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 18px;
      background: var(--bg-card);
      border: 1px solid var(--border-light);
      border-radius: var(--radius-card);
      box-shadow: 0 0 16px -10px rgba(56, 189, 248, 0.35);
      transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
    }

    .stat-item:hover {
      border-color: var(--accent-vermilion);
      box-shadow: 0 0 20px -6px rgba(56, 189, 248, 0.45);
    }

    .stat-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #4ade80;
      box-shadow: 0 0 8px 1px rgba(74, 222, 128, 0.7);
      flex-shrink: 0;
      animation: pulse-dot 2.4s ease-in-out infinite;
    }

    .stat-label {
      font-size: 12px;
      color: var(--text-muted);
      font-family: var(--font-en);
      letter-spacing: 0.03em;
      white-space: nowrap;
    }

    .stat-note {
      font-size: 10px;
      color: var(--text-muted);
      opacity: 0.75;
      margin-left: 2px;
    }

    .stat-value {
      font-size: 13px;
      font-weight: 500;
      color: var(--text-primary);
      font-family: var(--font-en);
      letter-spacing: 0.02em;
      margin-left: auto;
      white-space: nowrap;
    }

    @media (max-width: 640px) {
      .stats-bar {
        padding: 12px 20px;
        gap: 8px;
      }
      .stat-item {
        flex: 1 1 calc(50% - 8px);
        padding: 10px 12px;
        gap: 6px;
      }
      .stat-label {
        font-size: 10.5px;
      }
      .stat-value {
        font-size: 12px;
      }
      .stat-note {
        display: none;
      }
    }

    /* ===== Usage Analytics ===== */
    .stat-toggle {
      cursor: pointer;
      font: inherit;
      text-align: left;
      color: inherit;
      flex: 0 1 190px;
    }

    .stat-toggle .stat-value {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      color: var(--accent-vermilion);
    }

    .stat-toggle svg {
      width: 11px;
      height: 11px;
      transition: transform var(--transition-fast);
    }

    .stat-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

    .analytics {
      /* Chart tokens — 皆已對卡片底 #121826 驗證（亮度帶 / 色度 / 色盲分離 / 對比 ≥3:1） */
      --viz-surface: #121826;
      --viz-bar: #2f8bff;
      --viz-grid: #212a3c;
      --viz-c1: #3987e5;
      --viz-c2: #d95926;
      --viz-c3: #199e70;
      --viz-c4: #c98500;
      --viz-c5: #d55181;
      --viz-c6: #008300;

      position: relative;
      z-index: 10;
      max-width: 1400px;
      margin: 0 auto;
      padding: 0 40px 18px;
      display: grid;
      grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
      gap: 14px;
    }

    .analytics[hidden] { display: none; }

    .chart-card {
      min-width: 0;
      background: var(--bg-card);
      border: 1px solid var(--border-light);
      border-radius: var(--radius-card);
      padding: 18px 20px 14px;
      box-shadow: 0 0 16px -10px rgba(232, 107, 216, 0.35);
    }

    .chart-card.full { grid-column: 1 / -1; padding: 0; background: transparent; border: none; box-shadow: none; }

    .chart-head {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 18px;
    }

    .chart-title {
      font-size: 14px;
      font-weight: 600;
      letter-spacing: 0.03em;
      color: var(--text-primary);
      line-height: 1.4;
    }

    .chart-sub {
      font-size: 11px;
      line-height: 1.6;
      color: var(--text-muted);
      margin-top: 2px;
    }

    .chart-tabs { display: flex; gap: 4px; flex-shrink: 0; }

    .chart-tab {
      font: inherit;
      font-size: 11.5px;
      padding: 4px 12px;
      border-radius: 999px;
      border: 1px solid var(--border-input);
      background: transparent;
      color: var(--text-secondary);
      cursor: pointer;
      transition: all var(--transition-fast);
    }

    .chart-tab:hover { border-color: var(--accent-vermilion); color: var(--text-primary); }

    .chart-tab.active {
      background: var(--accent-vermilion);
      border-color: transparent;
      color: var(--text-on-selected);
      font-weight: 500;
    }

    /* --- Hourly column chart --- */
    .bars { position: relative; }

    .bars-plot {
      position: relative;
      display: flex;
      align-items: flex-end;
      gap: 2px; /* surface gap between adjacent columns */
      height: 150px;
      border-bottom: 1px solid var(--viz-grid);
      border-top: 1px solid var(--viz-grid); /* y-max hairline */
    }

    .bar-col {
      flex: 1 1 0;
      min-width: 0;
      height: 100%;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      border-radius: 3px 3px 0 0;
      transition: background var(--transition-fast);
    }

    .bar-col:hover, .bar-col.hovered { background: rgba(245, 240, 250, 0.05); }

    .bar-fill {
      width: 100%;
      max-width: 22px;
      background: var(--viz-bar);
      border-radius: 4px 4px 0 0; /* rounded data-end, square at baseline */
      transition: height var(--transition-normal);
    }

    .bars-ymax {
      position: absolute;
      top: -16px;
      left: 0;
      font-size: 10px;
      font-family: var(--font-en);
      color: var(--text-muted);
    }

    .bars-axis {
      display: flex;
      gap: 2px;
      margin-top: 6px;
    }

    .bars-axis span {
      flex: 1 1 0;
      min-width: 0;
      text-align: center;
      font-size: 10px;
      font-family: var(--font-en);
      color: var(--text-muted);
    }

    .bars-axis span:not(:nth-child(3n+1)) { visibility: hidden; }

    .bars-note { margin-top: 8px; font-size: 10.5px; color: var(--text-muted); }

    .viz-tip {
      position: absolute;
      z-index: 30;
      transform: translate(-50%, -100%);
      padding: 6px 10px;
      background: #0a0b0e;
      border: 1px solid var(--border-input);
      border-radius: 8px;
      font-size: 11px;
      line-height: 1.5;
      color: var(--text-primary);
      white-space: nowrap;
      pointer-events: none;
      box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.9);
    }

    .viz-tip[hidden] { display: none; }
    .viz-tip b { font-family: var(--font-en); font-weight: 600; }

    /* --- Country donut --- */
    .donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
    .donut-figure { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
    .donut-figure svg { width: 100%; height: 100%; display: block; }

    .donut-center {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      pointer-events: none;
    }

    .donut-total { font-family: var(--font-en); font-size: 22px; font-weight: 600; color: var(--text-primary); line-height: 1.1; }
    .donut-total-label { font-size: 10px; color: var(--text-muted); letter-spacing: 0.05em; }

    .donut-slice { transition: opacity var(--transition-fast); cursor: default; }
    .donut-wrap.dim .donut-slice:not(.active) { opacity: 0.35; }

    .donut-legend { list-style: none; flex: 1 1 150px; min-width: 0; display: flex; flex-direction: column; gap: 7px; }

    .donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 1.4; }
    .donut-legend .lg-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
    .donut-legend .lg-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .donut-legend .lg-val { margin-left: auto; font-family: var(--font-en); font-size: 11.5px; color: var(--text-primary); white-space: nowrap; }
    .donut-legend .lg-pct { font-family: var(--font-en); font-size: 11px; color: var(--text-muted); width: 38px; text-align: right; }

    .viz-empty { font-size: 12px; color: var(--text-muted); padding: 24px 0; text-align: center; }

    /* --- Table view --- */
    .viz-table { border: 1px solid var(--border-light); border-radius: var(--radius-card); background: var(--bg-card); }
    .viz-table > summary { cursor: pointer; font-size: 12px; color: var(--text-secondary); padding: 10px 18px; list-style: none; }
    .viz-table > summary::-webkit-details-marker { display: none; }
    .viz-table > summary::before { content: '▸ '; color: var(--text-muted); }
    .viz-table[open] > summary::before { content: '▾ '; }
    .viz-table > summary:hover { color: var(--text-primary); }
    .viz-table-body { display: flex; flex-wrap: wrap; gap: 28px; padding: 4px 18px 18px; }
    .viz-table table { border-collapse: collapse; font-size: 11.5px; font-family: var(--font-en); }
    .viz-table caption { text-align: left; font-size: 11px; color: var(--text-muted); padding-bottom: 6px; font-family: var(--font-zh); }
    .viz-table th, .viz-table td { padding: 3px 14px 3px 0; text-align: left; color: var(--text-secondary); white-space: nowrap; }
    .viz-table th { color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border-light); }
    .viz-table td:last-child, .viz-table th:last-child { text-align: right; padding-right: 0; }

    @media (max-width: 1023px) {
      .analytics { grid-template-columns: 1fr; }
    }

    @media (max-width: 640px) {
      .analytics { padding: 0 20px 14px; gap: 10px; }
      .stat-toggle { flex: 1 1 100%; }
      .bars-plot { height: 120px; gap: 1px; }
      .bars-axis { gap: 1px; }
      .bars-axis span:not(:nth-child(6n+1)) { visibility: hidden; }
      .chart-head { flex-direction: column; }
    }
