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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: #f3f4f6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: #111827;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
header > .material-symbols-outlined { font-size: 1.5rem; flex-shrink: 0; }
.header-title { flex: 1; min-width: 0; overflow: hidden; }
.header-title h1 { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-title p  { font-size: .7rem; opacity: .65; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.material-symbols-outlined { user-select: none; }

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 16px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

/* ── Note banner ── */
.note {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: .82rem;
  color: #92400e;
  line-height: 1.6;
}
.note strong { display: flex; align-items: center; gap: 4px; margin-bottom: 2px; }
.note .material-symbols-outlined { font-size: 1rem; }

/* ── Buttons (global) ── */
button {
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  font-size: .88rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
button .material-symbols-outlined { font-size: 1.1rem; }
button:active { transform: scale(.96); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: #fff;
  color: #111827;
}
.btn-primary:hover:not(:disabled) { background: #e5e7eb; }

.btn-secondary {
  background: transparent;
  color: #d1d5db;
  border: 1.5px solid #374151;
}
.btn-secondary:hover:not(:disabled) { background: #1f2937; color: #fff; }

/* ── Section cards (accordion) ── */
#sections-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-card {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.section-card.open {
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107,114,128,.12);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #fafafa;
  cursor: pointer;
  user-select: none;
}
.section-header:hover { background: #f3f4f6; }
.section-card.open .section-header { background: #f9fafb; }

.section-num {
  font-size: .72rem;
  font-weight: 700;
  color: #9ca3af;
  background: #f3f4f6;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section-title-text {
  flex: 1;
  font-size: .95rem;
  font-weight: 700;
  color: #111827;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-chevron {
  font-size: 1.2rem;
  color: #9ca3af;
  flex-shrink: 0;
  transition: transform .2s;
}
.section-card.open .section-chevron { transform: rotate(180deg); }

.btn-group {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  padding: 4px;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  border: none;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  font-weight: 400;
}
.btn-icon .material-symbols-outlined { font-size: 1.1rem; }
.btn-icon:hover:not(:disabled) { background: #f3f4f6; color: #111827; }
.btn-icon:disabled { color: #d1d5db; }
.btn-icon.btn-danger:hover:not(:disabled) { background: #fee2e2; color: #dc2626; }

/* ── Accordion content area ── */
.section-content {
  display: none;
  flex-direction: column;
  border-top: 1.5px solid #f3f4f6;
  padding: 14px 16px;
  gap: 10px;
}
.section-card.open .section-content { display: flex; }

.section-title {
  width: 100%;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .95rem;
  font-weight: 700;
  color: #111827;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.section-title:focus { border-color: #6b7280; }
.section-title::placeholder { color: #d1d5db; font-weight: 400; }

.section-body {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 0;
  font-size: .9rem;
  font-family: "Menlo", "Consolas", "Hiragino Sans", monospace;
  line-height: 1.75;
  color: #1f2937;
  background: #fff;
  min-height: 80px;
  display: block;
}
.section-body::placeholder { color: #d1d5db; }

/* ── Add section button ── */
#add-btn {
  align-self: flex-start;
  background: #fff;
  color: #374151;
  border: 1.5px dashed #d1d5db;
  border-radius: 10px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: .88rem;
  width: 100%;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
#add-btn:hover { background: #f9fafb; border-color: #9ca3af; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  color: #9ca3af;
  font-size: .88rem;
  padding: 32px;
  background: #fff;
  border: 1.5px dashed #e5e7eb;
  border-radius: 12px;
}

/* ── Status indicator ── */
#status {
  font-size: .82rem;
  padding: 5px 10px;
  border-radius: 6px;
  display: none;
}
#status.success {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(209,250,229,.2);
  color: #6ee7b7;
}
#status.error {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(254,226,226,.2);
  color: #fca5a5;
}
#status .material-symbols-outlined { font-size: 1rem; }

/* ── Tabs ── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid #e5e7eb;
}

.tab-btn {
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 20px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { color: #374151; background: transparent; }
.tab-btn.active { color: #111827; border-bottom-color: #111827; }
.tab-btn .material-symbols-outlined { font-size: 1.1rem; }

/* ── Timetable editor ── */
#timetable-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#tt-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tt-row {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  transition: box-shadow .2s;
}
.tt-row:focus-within {
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107,114,128,.12);
}

.tt-time {
  border: 1.5px solid #e5e7eb;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .88rem;
  font-family: "Menlo", "Consolas", monospace;
  font-weight: 700;
  color: #111827;
  width: 120px;
  outline: none;
  text-align: center;
}
.tt-time:focus { border-color: #6b7280; }

.tt-task {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .9rem;
  font-family: inherit;
  color: #111827;
  outline: none;
  min-width: 0;
}
.tt-task:focus { border-color: #6b7280; }

#add-tt-btn {
  background: #fff;
  color: #374151;
  border: 1.5px dashed #d1d5db;
  border-radius: 10px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: .88rem;
  width: 100%;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
#add-tt-btn:hover { background: #f9fafb; border-color: #9ca3af; }

/* ── Import area ── */
.import-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#import-toggle-btn {
  align-self: flex-start;
  background: #fff;
  color: #374151;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: .82rem;
}
#import-toggle-btn:hover { background: #f3f4f6; }

#import-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
}

#import-text {
  width: 100%;
  min-height: 180px;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  font-size: .88rem;
  font-family: "Menlo", "Consolas", "Hiragino Sans", monospace;
  line-height: 1.7;
  color: #1f2937;
  outline: none;
  resize: vertical;
}
#import-text:focus { border-color: #6b7280; }

.import-btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#import-append-btn {
  background: #111827;
  color: #fff;
}
#import-append-btn:hover:not(:disabled) { background: #374151; }

#import-replace-btn {
  background: #fff;
  color: #b91c1c;
  border-color: #fca5a5;
}
#import-replace-btn:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #f87171;
}

/* ── 保存ボタン アニメーション ── */
@keyframes save-spin { to { transform: rotate(360deg); } }
.save-spin { animation: save-spin .7s linear infinite; display: inline-block; }

.btn-saved-state {
  background: #dcfce7 !important;
  color: #166534 !important;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  main { padding: 16px 12px; }
  header { padding: 10px 14px; gap: 8px; }
  /* 保存ステータスはボタン内で表示するのでヘッダーの #status は非表示 */
  #status { display: none !important; }
  .btn-secondary span:not(.material-symbols-outlined),
  .btn-primary span:not(.material-symbols-outlined) { display: none; }
  .tab-btn { padding: 10px 14px; font-size: .82rem; }
  .tt-time { width: 66px; font-size: .82rem; }
}
