/* ===== Design Tokens ===== */
:root {
  --bg-primary: #faf9f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f3f1ee;
  --text-primary: #2d2a26;
  --text-secondary: #6b6560;
  --text-muted: #a39e99;
  --accent-blue: #7ba3c1;
  --accent-teal: #6bb5a0;
  --accent-coral: #d98c7a;
  --accent-amber: #d4a76a;
  --accent-lavender: #a897c5;
  --accent-rose: #c98a9a;
  --border-light: #e8e5e1;
  --shadow-sm: 0 1px 2px rgba(45, 42, 38, 0.04);
  --shadow-md: 0 4px 12px rgba(45, 42, 38, 0.06);
  --shadow-lg: 0 8px 24px rgba(45, 42, 38, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ===== Auth Screen ===== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #f5f3f0 0%, #ebe7e2 100%);
}

.auth-card {
  background: var(--bg-secondary);
  padding: 48px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-blue);
}

.auth-icon svg {
  width: 28px;
  height: 28px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-wrapper {
  position: relative;
}

.input-wrapper input {
  width: 100%;
  padding: 12px 16px;
  padding-right: 44px;
  font-size: 15px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}

.input-wrapper input:focus {
  border-color: var(--accent-blue);
  background: var(--bg-secondary);
  box-shadow: 0 0 0 3px rgba(123, 163, 193, 0.1);
}

.input-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: 0.5;
}

.auth-error {
  color: var(--accent-coral);
  font-size: 13px;
  margin-top: -8px;
  opacity: 0;
  transition: var(--transition);
}

.auth-error.visible {
  opacity: 1;
}

.btn-primary {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 500;
  color: white;
  background: linear-gradient(135deg, var(--accent-blue), #6a9ab8);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(123, 163, 193, 0.3);
}

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

/* ===== Main App ===== */
.main-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.92);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 600;
}

.logo-icon {
  font-size: 20px;
}

.btn-text {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-text:hover {
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

.app-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ===== Sections ===== */
section {
  margin-bottom: 40px;
}

.summary-layout {
  display: grid;
  grid-template-columns: minmax(520px, 620px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  margin-bottom: 32px;
}

.summary-layout > section {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-bottom: 0;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Overview Cards ===== */
.overview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 24px;
  overflow: hidden;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  flex: 1;
  align-content: start;
}

.overview-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: var(--transition);
  cursor: pointer;
}

.overview-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.overview-card.active {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(123, 163, 193, 0.1);
}

.overview-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.overview-card-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.overview-card-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 100px;
  font-weight: 500;
}

.badge-normal {
  background: rgba(107, 181, 160, 0.12);
  color: var(--accent-teal);
}

.badge-high {
  background: rgba(217, 140, 122, 0.12);
  color: var(--accent-coral);
}

.badge-low {
  background: rgba(212, 167, 106, 0.12);
  color: var(--accent-amber);
}

.overview-card-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.overview-card-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.overview-card-delta {
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}

.delta-up { color: var(--accent-coral); }
.delta-down { color: var(--accent-teal); }

/* ===== Timeline ===== */
.timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 24px;
  overflow: hidden;
}

.timeline-month-select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
}

.timeline-calendar {
  display: block;
  flex: 1;
}

.timeline-month {
  max-width: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  padding: 10px;
}

.timeline-month-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.timeline-month-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0;
}

.timeline-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.timeline-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.timeline-day {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--bg-secondary);
  padding: 4px 4px 2px;
  position: relative;
}

.timeline-day.empty {
  background: transparent;
  border-color: transparent;
}

.timeline-day-number {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1;
}

.timeline-day-event {
  margin-top: 3px;
  font-size: 10px;
  line-height: 1;
  color: var(--accent-coral);
  font-weight: 600;
}

.timeline-day-test-dot {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-blue);
}

.timeline-day.event {
  border-color: rgba(217, 140, 122, 0.35);
  background: rgba(217, 140, 122, 0.08);
}

.timeline-day.test {
  border-color: rgba(123, 163, 193, 0.35);
}

.timeline-day.both {
  border-color: rgba(217, 140, 122, 0.45);
  background: linear-gradient(135deg, rgba(217, 140, 122, 0.12), rgba(123, 163, 193, 0.12));
}

.timeline-legend {
  display: flex;
  gap: 20px;
  margin-top: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ===== Filters ===== */
.filters-section {
  position: sticky;
  top: 60px;
  z-index: 90;
  background: var(--bg-primary);
  padding: 16px 0;
  margin-bottom: 24px;
}

.filter-bar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

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

.filter-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-group select {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-width: 160px;
  cursor: pointer;
  outline: none;
}

.filter-group select,
.filter-search-input input,
#toggle-watched {
  min-height: 38px;
}

.filter-search-input input {
  min-width: 160px;
  padding: 8px 32px 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
}

.filter-search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.4;
}

.toggle-group {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.toggle-btn {
  padding: 7px 14px;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

.btn-outline {
  padding: 8px 16px;
  font-size: 13px;
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-outline:hover, .btn-outline.active {
  border-color: var(--accent-amber);
  color: var(--accent-amber);
  background: rgba(212, 167, 106, 0.06);
}

/* ===== Charts ===== */
.charts-section {
  animation: fadeIn 0.4s ease;
  width: 100%;
}

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

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr));
  gap: 20px;
  width: 100%;
}

.chart-card {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: var(--transition);
}

.chart-card {
  cursor: pointer;
}

.chart-card:hover {
  box-shadow: var(--shadow-md);
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chart-actions {
  display: flex;
  gap: 6px;
}

.chart-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.chart-action-btn:hover {
  background: var(--border-light);
}

.chart-action-btn.active {
  background: rgba(212, 167, 106, 0.15);
}

.chart-container {
  position: relative;
  height: 220px;
}

.chart-legend-custom {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
  font-size: 11px;
}

.legend-custom-item {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
}

.legend-custom-color {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

/* ===== Table ===== */
.table-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 16px;
  border-top: 1px solid var(--border-light);
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tr:hover td {
  background: rgba(123, 163, 193, 0.03);
}

.cell-high { color: var(--accent-coral); font-weight: 500; }
.cell-low { color: var(--accent-amber); font-weight: 500; }
.cell-normal { color: var(--accent-teal); }
.cell-empty { color: var(--text-muted); }
.value-flag {
  display: inline-block;
  margin-left: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.value-flag-high { color: var(--accent-coral); }
.value-flag-low { color: var(--accent-amber); }

/* ===== Category Section ===== */
.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 32px 0 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-light);
}

.category-title {
  font-size: 16px;
  font-weight: 600;
}

.category-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 10px;
  border-radius: 100px;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border-light);
}

/* ===== Tooltip Custom ===== */
.custom-tooltip {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: 12px;
  pointer-events: none;
}

/* ===== Modal / Detail View ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(45, 42, 38, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.96);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 17px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--border-light);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .summary-layout {
    display: block;
    margin-bottom: 24px;
  }

  .app-main {
    padding: 20px 16px;
  }
  
  .header-content {
    padding: 12px 16px;
  }
  
  .overview-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  
  .overview-card {
    padding: 14px;
  }
  
  .overview-card-value {
    font-size: 20px;
  }
  
  .overview-section {
    display: none;
  }

  .overview-panel {
    padding: 16px;
  }
  
  .filter-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
  }
  
  .filter-group {
    min-width: 0;
  }
  
  .filter-group select,
  .filter-group .input-wrapper input,
  #toggle-watched {
    width: 100%;
  }

  .filter-group .input-wrapper input {
    min-width: 0;
  }
  
  .toggle-group {
    width: 100%;
    justify-content: space-between;
  }

  .toggle-btn {
    flex: 1;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .chart-card {
    padding: 16px;
  }
  
  .chart-container {
    height: 200px;
  }
  
  .auth-card {
    padding: 36px 24px;
  }
  
  .timeline {
    padding: 16px;
  }

  .timeline-month {
    max-width: none;
  }
  
  .category-header {
    margin-top: 24px;
  }
}

@media (max-width: 480px) {
  .filter-bar {
    gap: 10px;
    padding: 12px;
  }

  .filter-group label {
    font-size: 11px;
  }
  
  .toggle-btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .timeline-month {
    padding: 8px;
  }

  .timeline-days {
    gap: 4px;
  }

  .timeline-day {
    min-height: 34px;
    padding: 3px 3px 2px;
  }
  
  .logo-text {
    font-size: 15px;
  }
  
  .section-title {
    font-size: 16px;
  }
}

/* ===== Scroll to Top ===== */
.scroll-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  transition: var(--transition);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scroll-top:hover {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

/* ===== Detail Modal enhancements ===== */
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-top: 8px;
}

.detail-table th {
  background: var(--bg-tertiary);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  border-bottom: 2px solid var(--border-light);
}

.detail-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
}

.detail-table tr:hover td {
  background: rgba(123, 163, 193, 0.03);
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.detail-summary-item {
  background: var(--bg-tertiary);
  padding: 14px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.detail-summary-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-summary-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.detail-chart-wrapper {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0;
  height: 340px;
  position: relative;
}

@media (max-width: 768px) {
  .detail-chart-wrapper {
    height: 260px;
    padding: 10px;
  }
  
  .modal-content {
    max-width: 100%;
    max-height: 95vh;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    margin-top: auto;
  }
  
  .modal-overlay {
    align-items: flex-end;
  }
}

/* ===== Print ===== */
@media print {
  .app-header, .filters-section, .app-footer, .chart-actions {
    display: none !important;
  }
  
  .chart-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
