* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: #f5f5f7;
  color: #222;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
}

.form-row.input-wide {
  grid-template-columns: 100px 1fr;
}
.form-row.input-wide input {
  grid-column: 2 / span 1;
}
   ヘッダー
/* ========================= */

header {
  padding: 12px 20px;
  background: #1f2933;
  color: #fff;
}

.header-main {
  display: flex;
  justify-content: space-between;
.event-input-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
  align-items: flex-end;
  gap: 12px;
}

header h1 {
  margin: 0;
  font-size: 1.3rem;
}
.form-row {
  display: grid;
  grid-template-columns: 100px 1fr 1fr;
  align-items: center;
  gap: 0 12px;
  margin-bottom: 4px;
}

.form-row > *:first-child {
  flex: 0 0 68%;
}
.form-row > *:nth-child(2) {
  flex: 0 0 32%;
}

.form-row label {
  margin-right: 0;
  text-align: left;
}

.form-row input,
.form-row select {
  width: 100%;
  max-width: 260px;
}

.form-row .hint {
  color: #2563eb;
  font-size: 0.95em;
  white-space: nowrap;
  justify-self: start;
}

/* チェックボックス行（全額など）のレイアウト */
.form-row-checkbox {
  display: grid;
  grid-template-columns: 100px 1fr 80px;
}

.form-row-checkbox input[type="checkbox"] {
  justify-self: start;
  width: auto;
  max-width: none;
  margin: 0;
}

.header-note {
  font-size: 0.8rem;
  opacity: 0.8;
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* =========================
   共通レイアウト
========================= */

#main {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 24px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* 左ペイン / 右ペイン */

#leftPane,
#rightPane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

#rightPane {
  position: relative;
}

/* =========================
   セクション
========================= */

.section {
  margin-bottom: 8px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  background: #fafafa;
}

.section > h2 {
  margin: 0;
  padding: 8px 12px;
  font-size: 0.95rem;
  background: #e5e7eb;
  border-radius: 8px 8px 0 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #e5e7eb;
  border-radius: 8px 8px 0 0;
}

.section-header h2 {
  margin: 0;
  font-size: 0.95rem;
}

.section-toggle {
  flex-shrink: 0;
  border: 1px solid #9ca3af;
  background: #fff;
  color: #111827;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.section.collapsed .section-inner {
  display: none;
}

.section-inner {
  padding: 10px 12px 12px;
  font-size: 0.85rem;
}

/* ラベル行・2カラム入力 */

.section-inner .row {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.section-inner .row > div {
  flex: 1;
}

/* =========================
   フォーム共通
========================= */

label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: #374151;
}

input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  padding: 4px 6px;
  font-size: 0.85rem;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background-color: #ffffff;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37,99,235,0.25);
}

/* 必須入力欄 */
input[data-required="true"],
select[data-required="true"] {
  border-color: #ef4444;
}

input[data-required="true"]:focus,
select[data-required="true"]:focus {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgba(239,68,68,0.25);
}

/* =========================
   イベント追加フォーム
========================= */

.event-input-form {
  margin-top: 8px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  padding: 8px;
  background: #ffffff;
}

.form-row {
  display: grid;
  grid-template-columns: 100px 1fr 1fr;
  align-items: center;
  gap: 0 12px;
  margin-bottom: 4px;
}

.form-row-no-hint {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: center;
  gap: 0 12px;
  margin-bottom: 4px;
}

.form-row label,
.form-row-no-hint label {
  margin-right: 0;
  text-align: left;
}

.form-row input,
.form-row select,
.form-row-no-hint select {
  width: 100%;
  max-width: 260px;
}

.form-row .hint {
  color: #2563eb;
  font-size: 0.95em;
  white-space: nowrap;
  justify-self: start;
}

/* 年齢・金額などの補助表示 */

.hint {
  margin-top: 2px;
  font-size: 0.75rem;
  color: #6b7280;
}

/* =========================
   イベント一覧
========================= */

.event-list-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #fff;
  margin-bottom: 4px;
}

.event-list-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.event-list-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #111827;
  display: block;
}

.event-list-detail {
  font-size: 0.75rem;
  color: #4b5563;
  margin-left: 0;
}

/* =========================
   ボタン
========================= */

button {
  cursor: pointer;
  border-radius: 4px;
  border: none;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: #2563eb;
  color: #fff;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover {
  background: #1d4ed8;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

/* 小さめボタン */
button.small {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* サブ系ボタン */
button.secondary {
  background: #6b7280;
}

button.secondary:hover {
  background: #4b5563;
}

/* メイン強調ボタン（必要なら） */
button.primary {
  background: #2563eb;
}

/* =========================
   グラフ
========================= */

.chart-block {
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 300px;
}

.chart-title {
  font-size: 0.9rem;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.chart-block canvas {
  flex: 1;
  min-height: 200px;
}

/* =========================
   サマリー
========================= */

#summary {
  margin-top: 8px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.summary-block {
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  padding: 8px 10px;
}

/* =========================
   モーダル（保存 / 復元 / 編集 共通）
========================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;           /* JS で display:flex にする */
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* クラスで制御したい場合用（今は未使用だが残しておく） */
.modal-backdrop.active {
  display: flex;
}

.modal-window {
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
  min-width: 400px;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  border-bottom: 1px solid #e5e7eb;
  background: #f3f4f6;
}

.modal-body {
  padding: 10px 14px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.modal-footer {
  padding: 8px 14px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #f3f4f6;
}

/* 保存 / 復元用テキストエリア */

#saveOutput,
#loadInput {
  margin-top: 4px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.75rem;
  width: 100%;
  height: 180px;
  resize: none;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* 編集モーダル内フォーム */

.event-edit-form .form-row {
  grid-template-columns: 100px 1fr 80px;
  margin-bottom: 6px;
}

.event-edit-form input {
  font-size: 0.8rem;
}

.event-edit-form input[type="checkbox"] {
  justify-self: start;
  width: auto;
  max-width: none;
}

/* =========================
   エラー表示・ステータス
========================= */

.error-message {
  margin-top: 2px;
  font-size: 0.75rem;
  color: #b91c1c;
  min-height: 1em;
}

.load-status {
  margin-top: 4px;
  font-size: 0.8rem;
}

/* =========================
   ユーティリティ
========================= */

.mt-6 {
  margin-top: 6px;
}

.block {
  display: block;
}

/* =========================
   ダークモード
========================= */

body.dark-mode {
  background-color: #1a1a1a;
  color: #e5e5e5;
}

body.dark-mode header {
  background: #0f0f0f;
}

body.dark-mode .section {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .section > h2,
body.dark-mode .section-header {
  background: #333333;
  color: #e5e5e5;
}

body.dark-mode .section-toggle {
  background: #2a2a2a;
  color: #e5e5e5;
  border-color: #555555;
}

body.dark-mode label {
  color: #b5b5b5;
}

body.dark-mode input[type="number"],
body.dark-mode input[type="text"],
body.dark-mode select,
body.dark-mode textarea {
  background-color: #2a2a2a;
  border-color: #404040;
  color: #e5e5e5;
}

/* ダークモード時の無効化フィールドは通常より少し暗く */
body.dark-mode input[type="number"]:disabled,
body.dark-mode input[type="text"]:disabled,
body.dark-mode select:disabled,
body.dark-mode textarea:disabled {
  background-color: #1f1f1f;
  border-color: #3a3a3a;
  color: #bfbfbf;
}

body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59,130,246,0.4);
}

body.dark-mode .event-input-form {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .hint {
  color: #9ca3af;
}

body.dark-mode .event-list-row {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .event-list-title {
  color: #e5e5e5;
}

body.dark-mode .event-list-detail {
  color: #9ca3af;
}

body.dark-mode .chart-block {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .summary-block {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .modal-backdrop {
  background: rgba(0, 0, 0, 0.75);
}

body.dark-mode .modal-window {
  background: #2a2a2a;
}

body.dark-mode .modal-header,
body.dark-mode .modal-footer {
  background: #333333;
  border-color: #404040;
  color: #e5e5e5;
}

body.dark-mode .modal-body {
  color: #e5e5e5;
}

body.dark-mode button {
  background: #3b82f6;
}

body.dark-mode button:hover {
  background: #2563eb;
}

body.dark-mode button.secondary {
  background: #4b5563;
}

body.dark-mode button.secondary:hover {
  background: #374151;
}

body.dark-mode #saveOutput,
body.dark-mode #loadInput {
  background: #1a1a1a;
  color: #e5e5e5;
  border-color: #404040;
}

/* =========================
   レスポンシブ（幅が狭い場合）
========================= */

@media (max-width: 900px) {
  body {
    overflow-y: auto;
  }

  #main {
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
    min-height: auto;
    flex: none;
    padding-bottom: 24px;
  }

  #leftPane,
  #rightPane {
    min-width: 0;
    overflow: visible;
    min-height: auto;
  }
}

@media (max-height: 500px) {
  body {
    overflow-y: auto;
  }

  #main {
    overflow: visible;
  }
}

/* ========================= */
/* ローディングオーバーレイ  */
/* ========================= */

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.05);
  pointer-events: none;
  display: none;
  z-index: 9999;
  border-radius: 8px;
  overflow: hidden;
}

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

.loading-shimmer {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(0, 0, 0, 0.1) 20%,
    rgba(0, 0, 0, 0.05) 50%,
    rgba(0, 0, 0, 0.1) 80%,
    transparent 100%
  );
  animation: shimmer 1s infinite;
  animation-delay: 1s;
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}
