/* ===== Design Tokens ===== */
:root {
  --bg-main: #0a0e1a;
  --bg-card: #131829;
  --bg-card-hover: #1a2038;
  --bg-surface: #1c2240;
  --bg-modal: #151a30;
  --text-primary: #e8ecf4;
  --text-secondary: #8b95b0;
  --text-muted: #5a6480;
  --accent-green: #34d399;
  --accent-green-dim: rgba(52, 211, 153, 0.12);
  --accent-yellow: #fbbf24;
  --accent-yellow-dim: rgba(251, 191, 36, 0.12);
  --accent-red: #f87171;
  --accent-red-dim: rgba(248, 113, 113, 0.12);
  --accent-blue: #60a5fa;
  --accent-blue-dim: rgba(96, 165, 250, 0.12);
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(96, 165, 250, 0.3);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.6);
  --font-main: 'Inter', 'Noto Sans JP', system-ui, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #1a1f38 0%, #0f1325 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-icon {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.4));
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #f87171, #fbbf24, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 100px;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-blue);
}

/* ===== Controls ===== */
.controls {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}

.controls-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

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

.control-group label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group input,
.control-group select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}

.control-group input:focus,
.control-group select:focus {
  border-color: var(--border-accent);
}

.control-group input[type="text"] { min-width: 220px; }

.btn-refresh {
  background: var(--accent-blue-dim);
  border: 1px solid rgba(96, 165, 250, 0.2);
  color: var(--accent-blue);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-refresh:hover {
  background: rgba(96, 165, 250, 0.2);
  border-color: var(--accent-blue);
}

.btn-install {
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.32);
  color: var(--accent-green);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-install:hover {
  background: rgba(52, 211, 153, 0.22);
}

/* ===== Chart ===== */
.chart-section {
  max-width: 1400px;
  margin: 24px auto 0;
  padding: 0 24px;
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
}

.chart-container h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.chart-container canvas {
  max-height: 220px;
}

/* ===== Main / Cards ===== */
.main {
  max-width: 1400px;
  margin: 24px auto;
  padding: 0 24px 40px;
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}

/* Card */
.report-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-card);
}

.report-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  background: var(--bg-surface);
}

.card-body {
  padding: 16px;
}

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

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
}

.health-good {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.health-warning {
  background: var(--accent-yellow-dim);
  color: var(--accent-yellow);
}

.health-critical {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

.card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-diagnosis {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-conditions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.condition-tag {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* ===== Loading ===== */
.loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state p:first-child { font-size: 1.3rem; margin-bottom: 8px; }
.empty-hint { font-size: 0.85rem; opacity: 0.7; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: modalIn 0.25s ease-out;
}

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

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.modal-image-wrap {
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.modal-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 500px;
}

.modal-info {
  padding: 28px 24px;
}

.modal-health {
  margin-bottom: 12px;
}

.modal-info h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.5;
}

.modal-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section h4 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-section ul li {
  font-size: 0.85rem;
  color: var(--text-primary);
  padding-left: 16px;
  position: relative;
}

.modal-section ul li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent-blue);
}

.modal-raw {
  margin-top: 12px;
}

.modal-raw summary {
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
}

.modal-raw pre {
  font-size: 0.72rem;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-secondary);
  max-height: 200px;
  overflow-y: auto;
  margin-top: 8px;
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .header-stats { width: 100%; }
  .controls-inner { flex-direction: column; }
  .control-group input[type="text"] { min-width: unset; width: 100%; }
  .reports-grid { grid-template-columns: 1fr; }
  .modal-body { grid-template-columns: 1fr; }
  .modal-image-wrap { max-height: 250px; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .stat-chip { min-width: 80px; padding: 6px 10px; }
}
