/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: rgba(255,255,255,0.05);
  --surface: rgba(255,255,255,0.10);
  --border: rgba(255,255,255,0.20);
  --text-primary: #f1f5f9;
  --text-secondary: #e9d5ff;
  --text-muted: rgba(196,181,253,0.5);
  --today-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --today-text: #ffffff;
  --other-month: rgba(196,181,253,0.3);
  --accent: #a78bfa;
  --danger: #f87171;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --radius: 8px;
  --radius-lg: 16px;
  --font: 'Noto Sans JP', 'Segoe UI', 'Hiragino Sans', sans-serif;
  --side-width: 280px;
  --header-h: 64px;
  --blur: blur(10px);
}

body {
  font-family: var(--font);
  background: linear-gradient(135deg, #0f172a 0%, #4a044e 50%, #0f172a 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== ポータルヘッダー ===== */
.portal-header {
  position: sticky; top: 0; z-index: 10;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 56px; padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.portal-header-logo {
  font-size: 1.05rem; font-weight: 700; color: #fff;
}
.portal-header-actions {
  display: flex; align-items: center; gap: 0.5rem;
}
.portal-sidebar-btn {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.8rem; color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px; padding: 0.3rem 0.7rem;
  cursor: pointer; transition: background 0.2s;
}
.portal-sidebar-btn:hover { background: rgba(255,255,255,0.25); }
.portal-header-back {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.8rem; color: rgba(255,255,255,0.8); text-decoration: none;
  padding: 0.3rem 0.7rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.3);
  transition: background 0.2s, color 0.2s;
}
.portal-header-back:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ===== Layout ===== */
.app-wrapper {
  display: grid;
  grid-template-columns: 1fr var(--side-width);
  grid-template-rows: 1fr;
  height: calc(100vh - 56px);
  gap: 0;
}
.app-wrapper.sidebar-hidden {
  grid-template-columns: 1fr;
}
.app-wrapper.sidebar-hidden .side-panel {
  display: none;
}

/* ===== Calendar Area ===== */
.calendar-area {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 24px 24px;
  min-width: 0;
}

/* ===== Calendar Header ===== */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.month-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

.nav-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.nav-btn:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }


/* ===== Calendar Grid ===== */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex: 1;
}

.weekday-header {
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.weekday-header:first-child { color: #fca5a5; }   /* 日 */
.weekday-header:last-child  { color: #93c5fd; }   /* 土 */

/* ===== Day Cell ===== */
.day-cell {
  background: rgba(255,255,255,0.04);
  min-height: 90px;
  padding: 6px 4px 4px 4px;
  position: relative;
  overflow: visible;
  cursor: pointer;
  transition: background 0.12s;
}
.day-cell:hover { background: rgba(255,255,255,0.08); }

.day-cell.other-month .day-number {
  color: var(--other-month);
}
.day-cell.other-month { background: rgba(255,255,255,0.02); }

.day-number {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin-bottom: 2px;
  position: relative;
  z-index: 1;
}

/* 今日 */
.day-cell.today .day-number {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-weight: 700;
}

/* 日曜・土曜の数字色 */
.day-cell.sunday .day-number   { color: #fca5a5; }
.day-cell.saturday .day-number { color: #93c5fd; }

/* ===== Task Bars ===== */
.task-bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px -4px 0; /* セルの横パディング分だけ広げてセル端まで帯を伸ばす */
}

.task-bar {
  height: 18px;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 18px;
  padding: 0 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  position: relative;
  cursor: pointer;
  transition: filter 0.12s;
}
.task-bar.is-hovered { filter: brightness(1.18); }

/* セルの端で丸める */
.task-bar.bar-start  { border-radius: 9px 0 0 9px; padding-left: 7px; }
.task-bar.bar-end    { border-radius: 0 9px 9px 0; padding-right: 7px; }
.task-bar.bar-single { border-radius: 9px; }
.task-bar.bar-middle { border-radius: 0; }

/* 全セル同一色 */

/* 前のセルとの1px隙間を埋める（後のセルが上に重なって隙間をカバー） */
.task-bar.bar-end,
.task-bar.bar-middle { margin-left: -1px; }

/* 空レーン用スペーサー: 同じ高さを確保しつつ不可視 */
.task-bar--spacer { visibility: hidden; pointer-events: none; }

/* 完了タスクバー */
.task-bar.is-completed { opacity: 0.35; filter: grayscale(0.7); }

/* ===== Side Panel ===== */
.side-panel {
  background: rgba(255,255,255,0.10);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.side-panel-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.panel-toggle-btn {
  border: none; background: none; cursor: pointer;
  color: var(--text-secondary); font-size: 0.75rem;
  padding: 4px;
  display: none; /* PCでは非表示 */
}

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 40px 0;
}

/* ===== Task List (Side Panel) ===== */
.task-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  position: relative;
  border-left: 4px solid var(--accent);
  background: rgba(255,255,255,0.04);
  transition: background 0.15s;
}
.task-item:hover { background: rgba(255,255,255,0.08); }

.task-item-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  padding-right: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.task-item-meta span {
  display: block;
}

.task-item-notes {
  font-size: 0.72rem;
  color: var(--text-secondary);
  opacity: 0.75;
  margin-top: 4px;
  padding-right: 48px;
  white-space: pre-wrap;
  word-break: break-word;
}

.days-left {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 4px;
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
}
.days-left.urgent { background: rgba(248,113,113,0.2); color: #fca5a5; }
.days-left.soon   { background: rgba(251,191,36,0.2);  color: #fcd34d; }
.days-left.ok     { background: rgba(52,211,153,0.2);  color: #6ee7b7; }
.days-left.past   { background: rgba(255,255,255,0.08); color: var(--text-muted); }

.task-item-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 2px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.icon-btn.delete:hover { background: rgba(248,113,113,0.15); color: var(--danger); }

/* 完了タスクアイテム */
.task-item.is-completed { opacity: 0.5; }
.task-item.is-completed .task-item-name { text-decoration: line-through; color: var(--text-muted); }

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 28px;
  right: calc(var(--side-width) + 28px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(102,126,234,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 8px 32px rgba(102,126,234,0.5); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: rgba(15,23,42,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  width: 32px; height: 32px;
  border: none; background: rgba(255,255,255,0.08); cursor: pointer;
  font-size: 1.3rem; color: var(--text-secondary);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.modal-close-btn:hover { background: rgba(255,255,255,0.15); color: var(--text-primary); }

.modal-form {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: -8px;
}

.required { color: var(--danger); }

.modal-form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: rgba(0,0,0,0.3);
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.modal-form textarea:focus { border-color: var(--accent); }

.modal-form input[type="text"],
.modal-form input[type="date"],
.modal-form input[type="number"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: rgba(0,0,0,0.3);
  outline: none;
  transition: border-color 0.15s;
}
.modal-form input:focus { border-color: var(--accent); }
.modal-form input.error { border-color: var(--danger); }

.modal-form select {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background-color: rgba(0,0,0,0.3);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a0aec0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.modal-form select:focus { border-color: var(--accent); }
.modal-form select option {
  background-color: #1a1535;
  color: #f1f5f9;
}

/* date ピッカーアイコンを白に */
.modal-form input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

/* ===== Color Picker ===== */
.color-picker {
  display: flex;
  gap: 8px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  outline: none;
  box-sizing: border-box;
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected {
  border-color: #fff;
  transform: scale(1.15);
}

/* ===== Modal Actions ===== */
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn-primary {
  padding: 9px 22px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }

.btn-secondary {
  padding: 9px 18px;
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

/* ===== Drag Selection ===== */
.day-cell.drag-selecting {
  background: rgba(102,126,234,0.2) !important;
}
.day-cell.drag-edge {
  background: rgba(102,126,234,0.3) !important;
}

/* ===== Popover ===== */
.popover {
  position: fixed;
  z-index: 300;
  width: 264px;
  background: rgba(15,23,42,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 10px 32px -4px rgba(0,0,0,0.5);
  overflow: hidden;
  animation: popover-in 0.14s ease;
}
.popover[hidden] { display: none; }

@keyframes popover-in {
  from { opacity: 0; transform: scale(0.94) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 14px;
  gap: 8px;
}

.popover-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.popover-close-btn {
  width: 24px; height: 24px; flex-shrink: 0;
  border: none; background: rgba(255,255,255,0.2); cursor: pointer;
  color: #fff; font-size: 1rem; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
.popover-close-btn:hover { background: rgba(255,255,255,0.35); }

.popover-body {
  padding: 12px 14px 8px;
}

.popover-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 0.78rem;
}
.popover-dl dt {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  padding-top: 1px;
}
.popover-dl dd {
  color: var(--text-primary);
  font-weight: 500;
}
.popover-dl .badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 2px;
}

.popover-notes {
  margin-top: 8px;
  padding: 7px 10px;
  background: rgba(255,255,255,0.06);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.popover-notes[hidden] { display: none; }

.popover-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
}

.btn-primary-sm {
  padding: 5px 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary-sm:hover { opacity: 0.85; }

.btn-complete-sm {
  padding: 5px 14px;
  background: rgba(52,211,153,0.1);
  color: #6ee7b7;
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-complete-sm:hover { background: rgba(52,211,153,0.2); }
.btn-complete-sm.is-active {
  background: rgba(148,163,184,0.12);
  color: #94a3b8;
  border-color: rgba(148,163,184,0.3);
}
.btn-complete-sm.is-active:hover { background: rgba(148,163,184,0.22); }

.btn-danger-sm {
  padding: 5px 14px;
  background: rgba(248,113,113,0.1);
  color: var(--danger);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger-sm:hover { background: rgba(248,113,113,0.2); }

/* ===== Scrollbar ===== */
.side-panel-body::-webkit-scrollbar { width: 4px; }
.side-panel-body::-webkit-scrollbar-track { background: transparent; }
.side-panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-wrapper {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .calendar-area {
    padding: 12px;
  }

  .side-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 280px;
  }

  .panel-toggle-btn { display: flex; }

  .side-panel.collapsed .side-panel-body { display: none; }
  .side-panel.collapsed .panel-toggle-btn { transform: rotate(180deg); }

  .fab {
    right: 20px;
    bottom: 300px;
  }

  .day-cell {
    min-height: 60px;
  }

  .task-bar {
    height: 14px;
    font-size: 0;
    line-height: 14px;
  }

  .month-title { font-size: 1.1rem; }
}

@media (max-width: 480px) {
  .day-cell { min-height: 48px; padding: 4px 2px 2px; }
  .day-number { width: 20px; height: 20px; font-size: 0.75rem; }
  .task-bar { height: 6px; }
}
