:root {
  --primary: #0ABAB5;
  --primary-dark: #089490;
  --primary-light: #e0f7f6;
  --primary-xlight: #f0fffe;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a202c;
  --text-secondary: #718096;
  --border: #e2e8f0;
  --success: #22c55e;
  --success-light: #dcfce7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --nav-width: 240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--nav-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  box-shadow: var(--shadow);
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 18px;
  font-weight: 700;
}

.sidebar-logo .logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.main-content {
  margin-left: var(--nav-width);
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}

/* ── Page Header ── */
.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  border: 1px solid var(--border);
}

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

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.stat-unit {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover { background: var(--primary-light); }

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10,186,181,0.1);
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: #16a34a; }
.badge-danger { background: var(--danger-light); color: #dc2626; }
.badge-warning { background: var(--warning-light); color: #d97706; }

/* ── Subject Tag ── */
.subject-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

/* ── Table ── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:hover td { background: var(--primary-xlight); }
tr:last-child td { border-bottom: none; }

/* ── Score Bar ── */
.score-bar-wrap { display: flex; align-items: center; gap: 10px; }

.score-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  min-width: 80px;
}

.score-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.6s ease;
}

.score-bar-fill.low { background: var(--danger); }
.score-bar-fill.mid { background: var(--warning); }
.score-bar-fill.high { background: var(--success); }

.score-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  min-width: 40px;
  text-align: right;
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-xlight);
}

.upload-zone svg {
  width: 48px; height: 48px;
  color: var(--primary);
  margin-bottom: 12px;
}

.upload-zone p { color: var(--text-secondary); font-size: 14px; }
.upload-zone strong { color: var(--text); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

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

.modal-title { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  border-radius: 4px;
}

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

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ── Question Card ── */
.question-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

.question-card.correct { border-color: var(--success); background: var(--success-light); }
.question-card.incorrect { border-color: var(--danger); background: var(--danger-light); }

.question-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.question-text { font-size: 15px; font-weight: 500; margin-bottom: 12px; }

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.option-btn {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: all 0.15s;
  font-family: inherit;
}

.option-btn:hover { border-color: var(--primary); background: var(--primary-xlight); }
.option-btn.selected { border-color: var(--primary); background: var(--primary); color: white; }
.option-btn.correct-answer { border-color: var(--success); background: var(--success-light); }
.option-btn.wrong-answer { border-color: var(--danger); background: var(--danger-light); }

/* ── Alert ── */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-info { background: var(--primary-light); color: var(--primary-dark); }
.alert-success { background: var(--success-light); color: #16a34a; }
.alert-danger { background: var(--danger-light); color: #dc2626; }
.alert-warning { background: var(--warning-light); color: #d97706; }

/* ── Loading ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 300;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.loading-overlay.show { display: flex; }

.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text { font-size: 16px; font-weight: 600; color: var(--primary); }

/* ── Login Page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0f7f6 0%, #f4f6f9 50%, #e8f4ff 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(10,186,181,0.12);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  color: white;
  font-size: 32px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(10,186,181,0.3);
}

.login-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 36px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 13px 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  margin-bottom: 12px;
}

.btn-google:hover { border-color: #4285f4; box-shadow: 0 2px 8px rgba(66,133,244,0.2); }

.btn-apple {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 13px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: #000;
  font-size: 15px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-apple:hover { background: #333; }

/* ── Trend Icon ── */
.trend { font-size: 13px; font-weight: 600; }
.trend.improving { color: var(--success); }
.trend.declining { color: var(--danger); }
.trend.stable { color: var(--text-secondary); }

/* ── Suggestion Card ── */
.suggestion-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.suggestion-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

.suggestion-card.high .suggestion-icon { background: var(--danger-light); }
.suggestion-card.medium .suggestion-icon { background: var(--warning-light); }
.suggestion-card.low .suggestion-icon { background: var(--success-light); }

.suggestion-subject {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.suggestion-message { font-size: 14px; color: var(--text); }

/* ── Grid Layouts ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ── Score Result ── */
.result-score {
  text-align: center;
  padding: 32px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius);
  color: white;
  margin-bottom: 24px;
}

.result-score .score-big {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
}

.result-score .score-label { font-size: 16px; opacity: 0.85; margin-top: 8px; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 64px; height: 64px;
  margin-bottom: 16px;
  color: var(--border);
}

.empty-state p { font-size: 16px; margin-bottom: 16px; }

/* ── Chart Containers ── */
.chart-container {
  position: relative;
  height: 220px;
  width: 100%;
}

.chart-container-wide {
  height: 200px;
}

.chart-title-row {
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

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

/* ── Templates Grid ── */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ── Responsive ── */

/* Tablet (≤1024px): collapse sidebar to icon-only */
@media (max-width: 1024px) {
  :root { --nav-width: 64px; }

  .sidebar-logo .logo-text,
  .nav-item span:not(svg),
  .sidebar-footer .user-name,
  .sidebar-footer .btn span { display: none; }

  .sidebar-logo { padding: 16px; justify-content: center; }
  .sidebar-logo .logo-icon { margin: 0; }

  .nav-item {
    justify-content: center;
    padding: 14px 0;
    position: relative;
  }

  /* Tooltip on hover */
  .nav-item[data-label]:hover::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--text);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 200;
  }

  .sidebar-footer { padding: 12px 0; justify-content: center; }
  .sidebar-footer .user-info { justify-content: center; }
  .sidebar-footer .btn { padding: 10px; min-width: 0; }

  .main-content { padding: 24px 20px; }

  .grid-2 { gap: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile (≤768px): bottom navigation bar */
@media (max-width: 768px) {
  :root { --nav-width: 0px; }

  body { overflow-x: hidden; }

  .sidebar {
    width: 100%;
    height: auto;
    min-height: 0;
    position: fixed;
    bottom: 0; top: auto; left: 0;
    border-top: 1px solid var(--border);
    border-right: none;
    flex-direction: row;
    background: var(--surface);
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  }

  .sidebar-logo, .sidebar-footer { display: none; }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    width: 100%;
    padding: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }

  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 8px 6px 10px;
    font-size: 10px;
    font-weight: 600;
    border-left: none;
    border-top: 3px solid transparent;
    white-space: nowrap;
    min-width: 56px;
    justify-content: center;
  }

  .nav-item svg { width: 22px; height: 22px; }

  .nav-item.active {
    border-left: none;
    border-top-color: var(--primary);
    color: var(--primary);
    background: var(--primary-xlight);
  }

  .main-content {
    margin-left: 0;
    margin-bottom: 72px;
    padding: 16px;
  }

  .page-title { font-size: 20px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .options-grid { grid-template-columns: 1fr; }

  /* Cards */
  .card { padding: 16px; }

  /* Stats */
  .stat-card { padding: 14px; }
  .stat-value { font-size: 26px; }

  /* Buttons */
  .btn-lg { padding: 12px 20px; font-size: 15px; }

  /* Table → scrollable */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
  }

  table { min-width: 560px; }

  /* Hide less important table columns on mobile */
  .table-col-hide { display: none; }

  /* Score bar becomes compact */
  .score-bar-wrap { gap: 6px; }
  .score-bar { min-width: 50px; }
  .score-pct { min-width: 36px; font-size: 12px; }

  /* Modal → full screen */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  /* Upload zone */
  .upload-zone { padding: 32px 16px; }
  .upload-zone svg { width: 36px; height: 36px; }

  /* Login */
  .login-card { padding: 32px 24px; border-radius: 16px; }
  .login-title { font-size: 24px; }

  /* Result score */
  .result-score { padding: 24px 16px; }
  .result-score .score-big { font-size: 48px; }

  /* Page header row (title + action) */
  .page-header { flex-direction: column !important; gap: 12px; }
  .page-header > div:last-child { align-self: flex-start; }

  /* Chart container */
  .chart-container { height: 200px; }
  .chart-container-wide { height: 180px; }

  /* Templates: 1 column */
  .templates-grid { grid-template-columns: 1fr; }

  /* Exam step header */
  #step-exam .page-header > div:last-child {
    background: var(--primary-light);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
  }

  /* iOS: prevent zoom on input focus */
  input[type="text"],
  input[type="date"],
  input[type="number"],
  select,
  textarea { font-size: 16px; }
}

/* Small phones (≤480px) */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 22px; }

  .nav-item { font-size: 9px; padding: 8px 4px 10px; min-width: 48px; }

  .btn-google, .btn-apple { font-size: 14px; padding: 12px 16px; }

  .login-card { padding: 28px 18px; margin: 0 8px; }

  /* Stack quick-action buttons */
  .main-content > div[style*="display:flex"] { flex-direction: column; }

  /* Smaller charts */
  .chart-container { height: 180px; }
  .chart-container-wide { height: 160px; }

  /* Templates single column */
  .templates-grid { grid-template-columns: 1fr; }
}
