/* =========================================================
   style.css
   Material Design風・モバイル最優先のスタイルシート
   (見た目はリファクタリング前から一切変更していません)
   ========================================================= */

:root {
  /* --- Material Design ベースカラー --- */
  --md-primary: #1a73e8;
  --md-primary-dark: #1557b0;
  --md-on-primary: #ffffff;
  --md-surface: #ffffff;
  --md-background: #f1f3f4;
  --md-on-background: #202124;
  --md-outline: #dadce0;
  --md-error: #d93025;
  --md-success: #188038;
  --md-text-secondary: #5f6368;

  /* --- Googleカレンダーの色ID(1〜11)に対応する色 --- */
  --gcolor-1: #7986cb;  /* ラベンダー */
  --gcolor-2: #33b679;  /* セージ */
  --gcolor-3: #8e24aa;  /* ブドウ */
  --gcolor-4: #e67c73;  /* フラミンゴ */
  --gcolor-5: #f6c026;  /* バナナ */
  --gcolor-6: #f5511d;  /* みかん */
  --gcolor-7: #039be5;  /* ピーコック */
  --gcolor-8: #616161;  /* グラファイト */
  --gcolor-9: #3f51b5;  /* ブルーベリー */
  --gcolor-10: #0b8043; /* バジル */
  --gcolor-11: #d60000; /* トマト */

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  --shadow-2: 0 2px 6px rgba(60,64,67,0.25), 0 4px 12px rgba(60,64,67,0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--md-background);
  color: var(--md-on-background);
  font-family: "Roboto", "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  line-height: 1;
}

/* ================= アプリバー ================= */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.app-bar-title {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 500;
  margin: 0;
}
.app-bar-icon { font-size: 24px; opacity: 0.95; }
.app-bar-action {
  color: var(--md-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  text-decoration: none;
  transition: background 0.15s ease;
}
.app-bar-action:active,
.app-bar-action:hover { background: rgba(255,255,255,0.15); }

/* ================= ページ全体 ================= */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}
.page-hint {
  color: var(--md-text-secondary);
  font-size: 0.85rem;
  margin: 4px 4px 16px;
}

/* ================= カード ================= */
.card {
  background: var(--md-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--md-primary);
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 500;
  margin: 0;
  color: var(--md-on-background);
}
.card-hint {
  color: var(--md-text-secondary);
  font-size: 0.82rem;
  margin: 0 0 12px;
}

/* ================= テンプレートチップ ================= */
.template-chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.template-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--md-outline);
  background: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--md-on-background);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.template-chip .material-symbols-outlined { font-size: 18px; color: var(--chip-color, var(--md-primary)); }
.template-chip:active,
.template-chip.selected {
  background: var(--chip-color, var(--md-primary));
  border-color: var(--chip-color, var(--md-primary));
  color: #fff;
}
.template-chip.selected .material-symbols-outlined { color: #fff; }

/* ================= フォーム ================= */
.field { margin-bottom: 18px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--md-text-secondary);
  margin-bottom: 6px;
}
.required {
  color: var(--md-error);
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--md-error);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
}

input[type="text"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--md-outline);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--md-on-background);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--md-primary);
  border-color: transparent;
}
textarea { resize: vertical; }

/* --- スイッチ(終日予定) --- */
.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.switch-field label:first-child { margin: 0; color: var(--md-on-background); font-weight: 400; font-size: 1rem; }
.switch { position: relative; display: inline-block; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  display: block;
  width: 44px;
  height: 26px;
  background: var(--md-outline);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-1);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch-track { background: var(--md-primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }

/* --- 色ピッカー --- */
.color-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--dot-color);
  cursor: pointer;
  padding: 0;
}
.color-dot.selected {
  border-color: var(--md-on-background);
  box-shadow: 0 0 0 2px #fff inset;
}

/* ================= ボタン ================= */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--md-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}
.btn-primary:active { background: var(--md-primary-dark); box-shadow: var(--shadow-2); }
.btn-dialog { width: auto; padding: 10px 20px; }

.btn-text {
  background: transparent;
  border: none;
  color: var(--md-primary);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.btn-text:active { background: var(--md-background); }

.btn-danger {
  background: var(--md-error);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-weight: 500;
  cursor: pointer;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--md-background);
  color: var(--md-primary);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:active { background: var(--md-outline); }

/* ================= トースト通知 ================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #323232;
  color: #fff;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--md-error); }
.toast.success { background: var(--md-success); }

/* ================= ダイアログ ================= */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.dialog-overlay.show { display: flex; }
.dialog {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-2);
  animation: slideUp 0.2s ease;
}
@media (min-width: 600px) {
  .dialog-overlay { align-items: center; }
  .dialog { border-radius: var(--radius-lg); }
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.dialog h3 { margin: 0 0 12px; font-size: 1.05rem; }
.dialog-body { font-size: 0.92rem; color: var(--md-text-secondary); line-height: 1.6; margin-bottom: 20px; }
.dialog-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.dialog-body dt { font-weight: 500; color: var(--md-on-background); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ================= 一覧(history.html) ================= */
.event-list { display: flex; flex-direction: column; gap: 12px; }
.event-item { padding: 16px; }
.event-item-header { display: flex; align-items: center; gap: 10px; }
.event-color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.event-item-main { flex: 1; min-width: 0; }
.event-item-title { font-weight: 500; font-size: 0.98rem; }
.event-item-sub { font-size: 0.8rem; color: var(--md-text-secondary); margin-top: 2px; }
.edit-form { margin-top: 16px; border-top: 1px solid var(--md-outline); padding-top: 16px; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--md-text-secondary); }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }

/* ================= レスポンシブ調整 ================= */
@media (min-width: 600px) {
  .page { padding-top: 24px; }
}
