/* ============================================================
   ホームラーニング セッション管理システム — Global Stylesheet
   Design: warm, professional, calming
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
  --primary:       #e8734a;
  --primary-light: #fdf0eb;
  --primary-dark:  #c45a35;
  --secondary:     #5a8fa3;
  --bg:            #fafaf8;
  --surface:       #ffffff;
  --surface-alt:   #f5f3f0;
  --border:        #e8e4df;
  --text:          #2d2926;
  --text-muted:    #8a7f78;
  --success:       #4caf82;
  --warning:       #f0a830;
  --danger:        #e05252;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md:     0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ── CSS Reset ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base ───────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

body {
  font-family: system-ui, '游ゴシック体', 'Yu Gothic', YuGothic,
               'Hiragino Kaku Gothic ProN', 'ヒラギノ角ゴ ProN W3',
               Meiryo, 'メイリオ', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img, svg {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ── App Header ─────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo:hover {
  text-decoration: none;
  opacity: 0.85;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* ── Navigation ─────────────────────────────────────────────── */
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-links a:hover {
  background: var(--primary-light);
  color: var(--primary);
  text-decoration: none;
}

.nav-links a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* ── Main Content ───────────────────────────────────────────── */
.main-content {
  padding-top: 72px;
  max-width: 960px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 48px;
}

/* ── Page Title ─────────────────────────────────────────────── */
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
  line-height: 1.3;
}

.page-title small {
  display: block;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

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

.card-header h2,
.card-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

/* Primary */
.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(232, 115, 74, 0.35);
}

/* Secondary */
.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

/* Danger */
.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #c44040;
  box-shadow: 0 2px 8px rgba(224, 82, 82, 0.35);
}

/* Ghost / text */
.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--primary-light);
}

/* Size modifiers */
.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  gap: 4px;
}

.btn-lg {
  padding: 13px 24px;
  font-size: 1rem;
}

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

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
  appearance: auto;
}

.form-control:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

.form-control::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.form-control:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--primary-light);
  transition: background 0.12s;
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

/* Phase badges */
.badge-初期 {
  background: #e3f2fd;
  color: #1976d2;
}

.badge-成長 {
  background: #e8f5e9;
  color: #388e3c;
}

.badge-自走 {
  background: #fff3e0;
  color: #e65100;
}

/* Status badges */
.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-warning {
  background: #fff8e1;
  color: #f57f17;
}

.badge-danger {
  background: #fdecea;
  color: #c62828;
}

.badge-muted {
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* ── Energy Emoji ───────────────────────────────────────────── */
.energy-emoji {
  font-size: 1.4rem;
  cursor: default;
  line-height: 1;
}

.energy-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.energy-picker label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0;
}

.energy-picker input[type="radio"] {
  display: none;
}

.energy-picker input[type="radio"]:checked + .energy-picker-label {
  border-color: var(--primary);
  background: var(--primary-light);
}

.energy-picker label:has(input[type="radio"]:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.energy-picker label:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}

.energy-picker-emoji {
  font-size: 1.6rem;
  display: block;
  line-height: 1;
}

.energy-picker-caption {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  text-align: center;
}

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.alert-error {
  background: #fdecea;
  color: #c62828;
  border-left: 4px solid var(--danger);
}

.alert-success {
  background: #e8f5e9;
  color: #2e7d32;
  border-left: 4px solid var(--success);
}

.alert-warning {
  background: #fff8e1;
  color: #f57f17;
  border-left: 4px solid var(--warning);
}

.alert-info {
  background: #e3f2fd;
  color: #1565c0;
  border-left: 4px solid var(--secondary);
}

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

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

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

/* ── Back Link ──────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 16px;
  font-weight: 500;
  font-size: 0.9rem;
  transition: opacity 0.15s;
}

.back-link:hover {
  text-decoration: none;
  opacity: 0.75;
}

.back-link::before {
  content: '←';
}

/* ── Loading ────────────────────────────────────────────────── */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 0.9rem;
  gap: 10px;
}

.loading::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ── Topic Row ──────────────────────────────────────────────── */
.topic-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.topic-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.15s;
}

.topic-add-btn:hover {
  opacity: 0.7;
  text-decoration: underline;
}

/* ── Section Divider ────────────────────────────────────────── */
.section-divider {
  border: none;
  border-top: 2px solid var(--border);
  margin: 24px 0;
  position: relative;
}

.section-divider[data-title]::after {
  content: attr(data-title);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  padding: 0 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Inline divider with title span */
.section-divider-titled {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
}

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

.section-divider-titled span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Output Box ─────────────────────────────────────────────── */
.output-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  font-family: inherit;
}

/* ── Copy Button ────────────────────────────────────────────── */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.copy-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
  background: #e8f5e9;
}

/* ── Stats / Info 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: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

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

/* ── Chip / Tag ─────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

/* ── Utility ────────────────────────────────────────────────── */
.text-muted      { color: var(--text-muted); }
.text-primary    { color: var(--primary); }
.text-success    { color: var(--success); }
.text-danger     { color: var(--danger); }
.text-warning    { color: var(--warning); }
.text-center     { text-align: center; }
.text-right      { text-align: right; }
.font-bold       { font-weight: 700; }
.font-semibold   { font-weight: 600; }

.mt-0  { margin-top: 0; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0  { margin-bottom: 0; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.gap-8           { gap: 8px; }
.gap-12          { gap: 12px; }
.gap-16          { gap: 16px; }

.w-full          { width: 100%; }

/* ── Modal (future use) ─────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.18s ease;
}

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

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--surface-alt);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-header {
    padding: 0 12px;
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
  }

  .logo {
    font-size: 0.9rem;
  }

  .nav-links {
    gap: 2px;
    flex-wrap: wrap;
  }

  .nav-links a {
    padding: 5px 8px;
    font-size: 0.8rem;
  }

  .main-content {
    padding-top: 80px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-title {
    font-size: 1.25rem;
    margin-bottom: 16px;
  }

  .card {
    padding: 14px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .topic-row {
    grid-template-columns: 1fr 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal {
    padding: 20px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 0.85rem;
  }

  .table {
    font-size: 0.8rem;
  }

  .table th,
  .table td {
    padding: 8px;
  }
}

@media (max-width: 400px) {
  .topic-row {
    grid-template-columns: 1fr;
  }

  .energy-picker {
    gap: 4px;
  }

  .energy-picker label {
    padding: 6px 7px;
  }
}
