:root {
  color-scheme: dark;
  --bg: #0e0f18;
  --card: rgba(23, 25, 40, 0.85);
  --accent: #ff2d75;
  --accent-soft: rgba(255, 45, 117, 0.15);
  --accent-gradient: linear-gradient(135deg, #ff2d75, #7a5cff);
  --text: #f5f7ff;
  --text-muted: #9ba1c7;
  --border: rgba(255, 255, 255, 0.08);
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
}

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

body {
  font-family: "Inter", "Noto Sans JP", system-ui, sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 45, 117, 0.15), transparent 55%),
    radial-gradient(circle at bottom, rgba(65, 105, 225, 0.15), transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(14, 15, 24, 0.95);
  backdrop-filter: blur(10px);
  z-index: 100;
}

.branding h1 {
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.back-link:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Main */
main {
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
}

/* Stats Section */
.stats-section {
  margin-bottom: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

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

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}

.stat-card.highlight {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
}

.stat-card.highlight .stat-value {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Tab Section */
.tab-section {
  margin-bottom: 12px;
}

.tab-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  flex-shrink: 0;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tab-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
}

/* Date Section */
.date-section {
  margin-bottom: 16px;
  text-align: center;
}

.date-selector {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.date-selector label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.date-selector select {
  padding: 8px 32px 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(8, 9, 15, 0.5);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ba1c7' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
}

.date-selector select:focus {
  border-color: var(--accent);
}

.date-selector select:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

/* Tab Content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Filter Section */
.filter-section {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 500px) {
  .filter-section {
    flex-direction: column;
  }
}

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

.filter-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.filter-group select {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(8, 9, 15, 0.5);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
  cursor: pointer;
}

.filter-group select:focus {
  border-color: var(--accent);
}

/* Group Section (for by-store, by-machine) */
.group-section {
  margin-bottom: 24px;
}

.group-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Recommendations */
.recommendations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recommendation-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  transition: all 0.2s ease;
}

.recommendation-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.recommendation-card.confidence-high {
  border-left: 3px solid var(--success);
}

.recommendation-card.confidence-medium {
  border-left: 3px solid var(--warning);
}

.recommendation-card.confidence-low {
  border-left: 3px solid var(--text-muted);
}

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

.recommendation-info {
  flex: 1;
  min-width: 0;
}

.recommendation-store {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recommendation-machine {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.recommendation-machine-name {
  white-space: nowrap;
}

.recommendation-unit {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.confidence-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  min-width: 60px;
}

.confidence-label {
  font-size: 0.65rem;
  font-weight: 500;
  opacity: 0.8;
  display: block;
  margin-bottom: 2px;
}

.confidence-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.confidence-high .confidence-value {
  color: var(--success);
}

.confidence-medium .confidence-value {
  color: var(--warning);
}

.confidence-low .confidence-value {
  color: var(--text-muted);
}

/* Details */
.recommendation-details {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.predicted-setting {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--accent-gradient);
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
}

/* Factors */
.recommendation-factors {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.factor-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Result Badge */
.result-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: auto;
}

.result-hit {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
  border: 1px solid var(--success);
}

.result-miss {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid #ef4444;
}

.result-unknown {
  background: rgba(155, 161, 199, 0.2);
  color: var(--text-muted);
  border: 1px solid var(--text-muted);
}

/* Actual Data Section */
.actual-data {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.actual-data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 0.8rem;
}

.actual-data-row:not(:last-child) {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.actual-data-label {
  color: var(--text-muted);
}

.actual-data-value {
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}

.prob-good {
  color: var(--success);
}

.diff-plus {
  color: var(--success);
}

.diff-minus {
  color: #ef4444;
}

/* Card with result */
.recommendation-card.has-result {
  background: rgba(23, 25, 40, 0.95);
}

/* Stats Detail */
.stats-detail {
  margin-bottom: 24px;
}

.stats-detail h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Breakdown */
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-item {
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.breakdown-name {
  font-size: 0.9rem;
  font-weight: 500;
  display: block;
  margin-bottom: 6px;
}

.breakdown-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.breakdown-rate {
  font-size: 1.1rem;
  font-weight: 700;
}

.breakdown-rate.rate-high {
  color: var(--success);
}

.breakdown-rate.rate-medium {
  color: var(--warning);
}

.breakdown-rate.rate-low {
  color: var(--text-muted);
}

.breakdown-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.breakdown-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.breakdown-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.breakdown-fill.rate-high {
  background: var(--success);
}

.breakdown-fill.rate-medium {
  background: var(--warning);
}

.breakdown-fill.rate-low {
  background: var(--text-muted);
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 0.9rem;
}

.error-state {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.retry-btn {
  margin-top: 12px;
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.retry-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Footer */
footer {
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

.recommendation-card {
  animation: fadeIn 0.3s ease forwards;
  opacity: 0;
}

.recommendation-card:nth-child(1) { animation-delay: 0.02s; }
.recommendation-card:nth-child(2) { animation-delay: 0.04s; }
.recommendation-card:nth-child(3) { animation-delay: 0.06s; }
.recommendation-card:nth-child(4) { animation-delay: 0.08s; }
.recommendation-card:nth-child(5) { animation-delay: 0.10s; }
.recommendation-card:nth-child(6) { animation-delay: 0.12s; }
.recommendation-card:nth-child(7) { animation-delay: 0.14s; }
.recommendation-card:nth-child(8) { animation-delay: 0.16s; }
.recommendation-card:nth-child(9) { animation-delay: 0.18s; }
.recommendation-card:nth-child(10) { animation-delay: 0.20s; }

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}
