/* スケジュール管理モジュール (Google Calendar風) */
:root {
  --sch-bg: #f7f8fa;
  --sch-surface: #fff;
  --sch-border: #dde1e6;
  --sch-border-light: #ebedf0;
  --sch-text: #21272a;
  --sch-text-sub: #5f6368;
  --sch-text-muted: #a2a9b0;
  --sch-accent: #1a73e8;
  --sch-today-bg: #e8f0fe;
  --sch-sun: #d93025;
  --sch-sat: #1a73e8;
}

.schedule-module {
  background: var(--sch-bg); min-height: 100vh;
  font-family: 'Yu Gothic UI','Meiryo','Segoe UI',sans-serif; color: var(--sch-text);
}

/* レイアウト (サイドバー + メイン) */
.sch-layout { display: flex; min-height: calc(100vh - 56px); }
.sch-sidebar {
  width: 260px; background: var(--sch-surface); border-right: 1px solid var(--sch-border);
  padding: 16px 12px; flex-shrink: 0; overflow-y: auto; max-height: calc(100vh - 56px);
}
.sch-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* 新規作成ボタン */
.sch-sidebar-create { margin-bottom: 16px; padding: 0 4px; }
.sch-create-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 20px; background: var(--sch-accent); color: #fff;
  border: none; border-radius: 24px; font-size: 14px; font-weight: 600;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.1);
  transition: box-shadow .15s, background .15s;
}
.sch-create-btn:hover { background: #1557b0; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.sch-create-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; font-size: 18px; font-weight: 400;
}

/* ミニカレンダー */
.sch-mini-cal { padding: 0 4px 16px; border-bottom: 1px solid var(--sch-border-light); margin-bottom: 12px; }
.sch-mini-cal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; font-size: 13px; font-weight: 600;
}
.sch-mini-cal-title { color: var(--sch-text); }
.sch-mini-cal-nav { display: flex; gap: 2px; }
.sch-icon-btn.sch-mini { width: 24px; height: 24px; font-size: 16px; }
.sch-mini-cal-days {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 0;
}
.sch-mini-cal-day-label {
  text-align: center; font-size: 10px; color: var(--sch-text-sub);
  padding: 4px 0; font-weight: 500;
}
.sch-mini-cal-day-label.sun { color: var(--sch-sun); }
.sch-mini-cal-day-label.sat { color: var(--sch-sat); }
.sch-mini-cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
}
.sch-mini-cal-cell {
  border: none; background: transparent; width: 100%; height: 28px;
  font-size: 11px; cursor: pointer; border-radius: 50%;
  color: var(--sch-text); font-family: inherit;
  transition: background .1s;
}
.sch-mini-cal-cell:hover { background: var(--sch-bg); }
.sch-mini-cal-cell.other { color: var(--sch-text-muted); }
.sch-mini-cal-cell.today { background: var(--sch-accent); color: #fff; font-weight: 700; }
.sch-mini-cal-cell.today:hover { background: #1557b0; }
.sch-mini-cal-cell.selected { background: var(--sch-today-bg); color: var(--sch-accent); font-weight: 600; }
.sch-mini-cal-cell.sun:not(.today):not(.selected) { color: var(--sch-sun); }
.sch-mini-cal-cell.sat:not(.today):not(.selected) { color: var(--sch-sat); }

/* サイドバー セクション */
.sch-sidebar-section { padding: 8px 4px; }
.sch-sidebar-heading {
  font-size: 11px; font-weight: 700; color: var(--sch-text-sub);
  text-transform: uppercase; letter-spacing: .5px; padding: 4px 8px; margin-bottom: 4px;
}
.sch-sidebar-toggle-all {
  padding: 2px 8px 8px; font-size: 11px; color: var(--sch-text-sub);
}
.sch-link-btn {
  background: none; border: none; color: var(--sch-accent); font-size: 11px;
  cursor: pointer; padding: 2px 4px; font-family: inherit;
}
.sch-link-btn:hover { text-decoration: underline; }

/* ユーザー行 */
.sch-user-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  cursor: pointer; border-radius: 4px; transition: background .1s;
  font-size: 13px;
}
.sch-user-row:hover { background: var(--sch-bg); }
.sch-user-check {
  width: 14px; height: 14px; cursor: pointer; flex-shrink: 0;
  accent-color: var(--user-color, var(--sch-accent));
}
.sch-user-color-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.sch-user-name {
  color: var(--sch-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sch-user-name.me { font-weight: 600; }
.sch-user-row:not(.visible) .sch-user-color-dot { opacity: .3; }
.sch-user-row:not(.visible) .sch-user-name { color: var(--sch-text-muted); }

/* ツールバー */
.sch-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--sch-surface);
  border-bottom: 1px solid var(--sch-border); gap: 12px; flex-wrap: wrap;
}
.sch-toolbar-left { display: flex; align-items: center; gap: 8px; }
.sch-toolbar-right { display: flex; gap: 4px; align-items: center; }
.sch-title { font-size: 18px; font-weight: 600; margin-left: 8px; }

/* ボタン */
.sch-btn {
  padding: 8px 16px; border: 1px solid var(--sch-border); border-radius: 6px;
  background: var(--sch-surface); color: var(--sch-text); font-size: 13px;
  cursor: pointer; font-weight: 500; transition: background .1s;
}
.sch-btn:hover { background: var(--sch-bg); }
.sch-btn-primary { background: var(--sch-accent); color: #fff; border-color: var(--sch-accent); }
.sch-btn-primary:hover { background: #1557b0; }
.sch-btn-danger { color: var(--sch-sun); border-color: #f4c7c3; }
.sch-btn-danger:hover { background: #fdebe8; }
.sch-view-btn.active { background: var(--sch-today-bg); color: var(--sch-accent); border-color: #c6dafc; font-weight: 600; }
.sch-icon-btn {
  width: 32px; height: 32px; border: none; background: transparent;
  color: var(--sch-text-sub); cursor: pointer; border-radius: 50%;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.sch-icon-btn:hover { background: var(--sch-bg); }

/* ボディ */
.sch-body { background: var(--sch-surface); padding: 0; min-height: calc(100vh - 120px); }
.sch-loading { text-align: center; padding: 60px; color: var(--sch-text-sub); }

/* 月ビュー */
.sch-month { padding: 0; }
.sch-month-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--sch-border);
}
.sch-month-day-label {
  padding: 10px 8px; font-size: 11px; font-weight: 600; color: var(--sch-text-sub);
  text-align: center; text-transform: uppercase; letter-spacing: .5px;
}
.sch-month-day-label.sun { color: var(--sch-sun); }
.sch-month-day-label.sat { color: var(--sch-sat); }

.sch-month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr); min-height: calc(100vh - 180px);
}
.sch-month-cell {
  border-right: 1px solid var(--sch-border-light);
  border-bottom: 1px solid var(--sch-border-light);
  padding: 4px; cursor: pointer; min-height: 100px;
  position: relative; transition: background .1s;
}
.sch-month-cell:hover { background: #fafbfc; }
.sch-month-cell.other-month { background: #fafbfc; }
.sch-month-cell.other-month .sch-month-date { color: var(--sch-text-muted); }
.sch-month-date {
  display: inline-block; width: 26px; height: 26px; line-height: 26px;
  text-align: center; font-size: 12px; font-weight: 500; border-radius: 50%;
}
.sch-month-cell.sun .sch-month-date:not(.today) { color: var(--sch-sun); }
.sch-month-cell.sat .sch-month-date:not(.today) { color: var(--sch-sat); }
.sch-month-date.today { background: var(--sch-accent); color: #fff; font-weight: 700; }
.sch-month-event {
  display: block; font-size: 11px; color: #fff; padding: 2px 6px;
  border-radius: 3px; margin-top: 2px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sch-month-event:hover { opacity: .9; }
.sch-month-more {
  font-size: 10px; color: var(--sch-text-sub); padding: 2px 6px;
  margin-top: 2px; cursor: pointer;
}
.sch-month-more:hover { color: var(--sch-accent); text-decoration: underline; }

/* 祝日 */
.sch-month-cell.holiday { background: #fef7f6; }
.sch-month-date.holiday { color: var(--sch-sun) !important; }
.sch-month-holiday {
  font-size: 10px; color: var(--sch-sun); padding: 1px 4px;
  margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 600;
}
.sch-month-diet {
  font-size: 10px; color: #8a6d3b; padding: 1px 4px;
  margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #fffbeb; border-radius: 3px;
}
/* 週ビューの祝日ラベル */
.sch-week-day-head.holiday .sch-week-day-num { color: var(--sch-sun); }
.sch-week-holiday-label {
  font-size: 10px; color: var(--sch-sun); font-weight: 600;
  padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 日ビューの祝日ラベル */
.sch-day-holiday-label {
  display: inline-block; font-size: 13px; color: var(--sch-sun); font-weight: 600;
  padding: 4px 12px; background: #fef7f6; border-radius: 4px; margin-top: 6px; margin-right: 8px;
}
.sch-day-diet-label {
  display: inline-block; font-size: 13px; color: #8a6d3b; font-weight: 600;
  padding: 4px 12px; background: #fffbeb; border-radius: 4px; margin-top: 6px;
}

/* 週ビュー / 日ビュー共通 */
.sch-week, .sch-day { }
.sch-week-header {
  display: grid; grid-template-columns: 60px repeat(7, 1fr);
  border-bottom: 1px solid var(--sch-border); position: sticky; top: 0;
  background: var(--sch-surface); z-index: 10;
}
.sch-week-time-col-head { }
.sch-week-day-head {
  padding: 8px; text-align: center; border-left: 1px solid var(--sch-border-light);
  cursor: pointer;
}
.sch-week-day-head:hover { background: var(--sch-bg); }
.sch-week-day-head.sun .sch-week-day-name { color: var(--sch-sun); }
.sch-week-day-head.sat .sch-week-day-name { color: var(--sch-sat); }
.sch-week-day-name { font-size: 11px; color: var(--sch-text-sub); font-weight: 600; text-transform: uppercase; }
.sch-week-day-num {
  font-size: 22px; font-weight: 400; margin-top: 2px;
  display: inline-block; width: 36px; height: 36px; line-height: 36px;
  border-radius: 50%;
}
.sch-week-day-num.today { background: var(--sch-accent); color: #fff; font-weight: 500; }

.sch-week-grid {
  display: grid; grid-template-columns: 60px repeat(7, 1fr);
  position: relative;
}
.sch-day-grid { display: grid; grid-template-columns: 60px 1fr; position: relative; }

.sch-week-time-col {
  border-right: 1px solid var(--sch-border-light);
}
.sch-week-time-slot {
  height: 60px; padding: 4px 8px; font-size: 10px; color: var(--sch-text-sub);
  text-align: right; border-top: 1px solid var(--sch-border-light);
  position: relative;
}
.sch-week-time-slot:first-child { border-top: none; }

.sch-week-day-col, .sch-day-col {
  position: relative; border-left: 1px solid var(--sch-border-light);
}
.sch-week-slot {
  height: 30px; cursor: pointer; border-top: 1px solid var(--sch-border-light);
}
.sch-week-slot.half { border-top: 1px dashed #f0f2f5; }
.sch-week-slot:first-child { border-top: none; }
.sch-week-slot:hover { background: var(--sch-bg); }

.sch-week-event {
  position: absolute; left: 2px; right: 2px; color: #fff;
  padding: 4px 6px; border-radius: 4px; overflow: hidden; cursor: grab;
  box-shadow: 0 1px 2px rgba(0,0,0,.1); z-index: 2;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.sch-week-event:hover { opacity: .92; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.sch-week-event.dragging { opacity: .85; cursor: grabbing; box-shadow: 0 4px 12px rgba(0,0,0,.3); z-index: 10; }
.sch-week-event-time { font-size: 10px; opacity: .9; }
.sch-week-event-title { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sch-week-event-loc { font-size: 10px; opacity: .9; margin-top: 2px; }
.sch-week-event-creator { font-size: 10px; opacity: .85; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sch-week-event:not(.mine) { cursor: pointer; opacity: .78; }
.sch-week-event:not(.mine):hover { opacity: .88; }
.sch-week-event.mine { cursor: grab; }
.sch-week-event.mine.dragging { cursor: grabbing; }

/* リサイズハンドル */
.sch-resize-handle {
  position: absolute; bottom: 0; left: 0; right: 0; height: 6px;
  cursor: ns-resize; background: rgba(255,255,255,.2);
  border-bottom-left-radius: 4px; border-bottom-right-radius: 4px;
}
.sch-resize-handle:hover { background: rgba(255,255,255,.4); }

/* 日ビュー */
.sch-day-header { padding: 16px 24px; border-bottom: 1px solid var(--sch-border); }
.sch-day-header h3 { margin: 0; font-size: 20px; font-weight: 500; }
.sch-day-allday {
  padding: 8px 16px; border-bottom: 1px solid var(--sch-border); display: flex; gap: 8px; flex-wrap: wrap;
}
.sch-day-allday-event {
  padding: 6px 12px; color: #fff; border-radius: 4px; font-size: 13px; cursor: pointer;
}

/* モーダル */
.sch-modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(33,39,42,.5); z-index: 9500;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.sch-modal {
  background: var(--sch-surface); border-radius: 8px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.sch-modal-header {
  display: flex; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--sch-border); gap: 8px;
}
.sch-title-input {
  flex: 1; border: none; font-size: 18px; font-weight: 600; outline: none;
  background: transparent; padding: 6px 0;
}
.sch-title-input::placeholder { color: var(--sch-text-muted); }
.sch-title-readonly {
  flex: 1; font-size: 18px; font-weight: 600; padding: 6px 0; color: var(--sch-text);
}

/* 作成者情報 */
.sch-creator-info { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--sch-text); }
.sch-readonly-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #f1f3f4; color: var(--sch-text-sub); font-weight: 500;
}
.sch-owner-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--sch-today-bg); color: var(--sch-accent); font-weight: 600;
}
/* 無効化された入力 */
.sch-text-input:disabled, .sch-date-input:disabled {
  color: var(--sch-text); opacity: .8;
}

.sch-modal-body { padding: 12px 16px; }
.sch-field-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.sch-field-icon {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  color: var(--sch-text-sub); font-size: 14px; flex-shrink: 0;
}
.sch-text-input, .sch-date-input {
  flex: 1; border: none; border-bottom: 1px solid transparent; padding: 6px 0;
  font-size: 14px; font-family: inherit; background: transparent; outline: none;
  color: var(--sch-text);
}
.sch-text-input:focus, .sch-date-input:focus { border-bottom-color: var(--sch-accent); }
textarea.sch-text-input { resize: vertical; min-height: 60px; }

.sch-allday-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.sch-allday-label input { width: 16px; height: 16px; }

.sch-color-row { display: flex; gap: 6px; }
.sch-color-dot {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.sch-color-dot.active { border-color: var(--sch-text); }

.sch-modal-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--sch-border); gap: 8px;
}

/* トースト */
.sch-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--sch-text); color: #fff; padding: 10px 22px; border-radius: 4px;
  font-size: 13px; z-index: 10000; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.sch-toast.error { background: var(--sch-sun); }

/* モバイル */
@media (max-width: 768px) {
  .sch-layout { flex-direction: column; }
  .sch-sidebar {
    width: 100%; max-height: none; border-right: none;
    border-bottom: 1px solid var(--sch-border); padding: 8px 12px;
  }
  /* モバイルではミニカレンダーとユーザー一覧を折りたたみ */
  .sch-sidebar-section { display: none; }
  .sch-mini-cal { display: none; }
  .sch-sidebar-create { margin-bottom: 0; }
  .sch-create-btn { padding: 10px 18px; font-size: 13px; }

  .sch-toolbar { padding: 8px 12px; }
  .sch-title { font-size: 14px; }
  .sch-btn { padding: 6px 10px; font-size: 12px; }
  .sch-view-btn { padding: 6px 8px; }
  .sch-month-cell { min-height: 60px; padding: 2px; }
  .sch-month-event { font-size: 9px; padding: 1px 3px; }
  .sch-month-date { width: 20px; height: 20px; line-height: 20px; font-size: 10px; }
  .sch-week-day-num { font-size: 16px; width: 28px; height: 28px; line-height: 28px; }
  .sch-modal { max-height: 95vh; margin: 10px; }
  .sch-week-time-col { font-size: 9px; }
  .sch-week-grid { grid-template-columns: 40px repeat(7, 1fr); }
  .sch-day-grid { grid-template-columns: 40px 1fr; }
  .sch-week-header { grid-template-columns: 40px repeat(7, 1fr); }
}
