/* ============================================================
   style.css - 施設薬管理カレンダー デザインシステム
   ============================================================ */

/* ----------------------------------------------------------
   Google Fonts
   ---------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;600;700&display=swap');

/* ----------------------------------------------------------
   CSS Variables
   ---------------------------------------------------------- */
:root {
  /* 背景色 */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1c2a4a;
  --bg-input: #0d1b2a;

  /* テキスト */
  --text-primary: #e0e0e0;
  --text-secondary: #8892a4;
  --text-muted: #5a6478;

  /* 施設カラー */
  --color-sato: #ff8c42;
  --color-ikoi: #4ecdc4;
  --color-hinata: #ff6b9d;
  --color-horiyasu: #ffd93d;
  --color-toseki: #51cf66;

  /* UI カラー */
  --color-accent: #667eea;
  --color-danger: #ff6b6b;
  --color-success: #51cf66;
  --color-warning: #ffd93d;
  --color-sunday: #ff6b6b;
  --color-saturday: #6ba3ff;

  /* ボーダー */
  --border-color: #2a2a4a;
  --border-radius: 12px;
  --border-radius-sm: 8px;

  /* シャドウ */
  --shadow-sm: 0 2px 8px 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);

  /* トランジション */
  --transition: all 0.2s ease;
  --transition-slow: all 0.3s ease;

  /* サイドバー */
  --sidebar-width: 220px;

  /* ヘッダー背景 */
  --header-bg: linear-gradient(135deg, #1a1a2e, #1e2746);
}

/* ----------------------------------------------------------
   ライトモード
   ---------------------------------------------------------- */
body.light-mode {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #f8f9fa;
  --bg-card-hover: #e9ecef;
  --bg-input: #ffffff;

  --text-primary: #1a1a2e;
  --text-secondary: #495057;
  --text-muted: #868e96;

  --color-accent: #4c6ef5;
  --color-sunday: #e03131;
  --color-saturday: #1971c2;

  --border-color: #dee2e6;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

  --header-bg: linear-gradient(135deg, #ffffff, #f0f2f5);
}

body.light-mode ::-webkit-scrollbar-track {
  background: #f0f2f5;
}

body.light-mode ::-webkit-scrollbar-thumb {
  background: #ced4da;
}

body.light-mode .calendar-day.holiday {
  background: rgba(224, 49, 49, 0.06);
}

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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ----------------------------------------------------------
   Scrollbar
   ---------------------------------------------------------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #3a3a5a;
}

/* ----------------------------------------------------------
   Layout
   ---------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 100;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-sato), var(--color-ikoi));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ----------------------------------------------------------
   Sidebar
   ---------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  transition: var(--transition-slow);
}

.sidebar-section {
  padding: 16px;
}

.sidebar-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-sm);
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-toggle:hover {
  background: var(--bg-card-hover);
}

/* 施設リスト */
.facility-list {
  list-style: none;
}

.facility-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
  font-size: 0.9rem;
}

.facility-item:hover {
  background: var(--bg-card-hover);
}

.facility-item.active {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.facility-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.facility-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.facility-item-active {
  font-size: 0.7rem;
  color: var(--color-accent);
}

.add-facility-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  width: 100%;
  border: 1px dashed var(--border-color);
  border-radius: var(--border-radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: var(--transition);
  margin-top: 8px;
}

.add-facility-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: rgba(102, 126, 234, 0.1);
}

/* モード切替ボタン */
.view-mode-buttons {
  display: flex;
  gap: 4px;
  background: var(--bg-primary);
  border-radius: var(--border-radius-sm);
  padding: 4px;
}

.view-mode-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.view-mode-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.view-mode-btn:hover:not(.active) {
  color: var(--text-primary);
}

/* ----------------------------------------------------------
   Main Content
   ---------------------------------------------------------- */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.content-view {
  display: none;
  flex: 1;
  overflow: auto;
}

.content-view.active {
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------
   Calendar Navigation
   ---------------------------------------------------------- */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
}

.nav-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
}

.nav-today-btn {
  padding: 6px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  transition: var(--transition);
}

.nav-today-btn:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

#calendar-nav-label {
  font-size: 1rem;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}

/* ----------------------------------------------------------
   Calendar Grid
   ---------------------------------------------------------- */
.calendar-scroll-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#calendar-container {
  display: flex;
  gap: 16px;
  min-width: max-content;
}

.calendar-month {
  flex: 0 0 auto;
  width: 340px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.calendar-month-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.calendar-month-title {
  font-weight: 700;
  font-size: 1rem;
}

.calendar-grid {
  padding: 8px;
}

.calendar-weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 4px;
}

.calendar-weekday {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 0;
  color: var(--text-secondary);
}

.calendar-weekday.sunday {
  color: var(--color-sunday);
}

.calendar-weekday.saturday {
  color: var(--color-saturday);
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.calendar-day {
  min-height: 60px;
  padding: 4px;
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}

.calendar-day:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-sm);
}

.calendar-day.empty {
  background: transparent;
  cursor: default;
}

.calendar-day.empty:hover {
  box-shadow: none;
}

.calendar-day.today {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.calendar-day.sunday .calendar-day-number span:first-child {
  color: var(--color-sunday);
}

.calendar-day.saturday .calendar-day-number span:first-child {
  color: var(--color-saturday);
}

.calendar-day.holiday {
  background: rgba(255, 107, 107, 0.08);
}

.calendar-day-number {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}

.calendar-day-number span:first-child {
  font-weight: 600;
  font-size: 0.85rem;
}

.holiday-name {
  font-size: 0.55rem;
  color: var(--color-danger);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-day-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ----------------------------------------------------------
   Event Badge
   ---------------------------------------------------------- */
.event-badge {
  font-size: 0.6rem;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  line-height: 1.3;
}

.event-badge-mini {
  display: inline-flex;
  align-items: center;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 500;
}

/* 予測イベントのスタイル（破線ボーダー・低不透明度） */
.event-badge.predicted {
  border-style: dashed !important;
  opacity: 0.75;
  font-style: italic;
}

/* ----------------------------------------------------------
   Modal
   ---------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 420px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}

.modal-holiday-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: rgba(255, 107, 107, 0.15);
  color: var(--color-danger);
  border-radius: 20px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--color-danger);
  color: white;
}

.modal-body {
  padding: 16px 20px;
}

.modal-events {
  margin-bottom: 16px;
  min-height: 40px;
}

.modal-event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.event-delete-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 107, 107, 0.15);
  color: var(--color-danger);
  cursor: pointer;
  font-size: 0.7rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.event-delete-btn:hover {
  background: var(--color-danger);
  color: white;
}

.no-events {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px;
}

.modal-input-area {
  display: flex;
  gap: 8px;
}

.event-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

.event-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.event-add-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: var(--color-accent);
  color: white;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.event-add-btn:hover {
  background: #5a6fd6;
  box-shadow: var(--shadow-sm);
}

/* ----------------------------------------------------------
   Autocomplete Dropdown
   ---------------------------------------------------------- */
.autocomplete-dropdown {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 250px;
  overflow-y: auto;
  animation: fadeIn 0.15s ease;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.85rem;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--bg-card-hover);
}

.autocomplete-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ----------------------------------------------------------
   Overview (管理マスタ)
   ---------------------------------------------------------- */
#overview-container {
  padding: 20px;
}

.overview-header {
  margin-bottom: 20px;
}

.overview-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.overview-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.overview-table-wrapper {
  overflow-x: auto;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.overview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.overview-table thead {
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.overview-table th {
  padding: 10px 12px;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  font-size: 0.78rem;
}

.th-facility {
  text-align: left !important;
  min-width: 90px;
}

.th-predict {
  background: rgba(102, 126, 234, 0.1) !important;
}

.overview-table td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.group-header-row td {
  font-size: 0.85rem;
  padding: 6px 12px;
  text-align: left !important;
}

.group-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.data-row {
  transition: var(--transition);
}

.data-row:hover {
  background: var(--bg-card-hover);
}

.data-row.has-5w-suggestion {
  background: rgba(255, 217, 61, 0.05);
}

.td-facility {
  text-align: left !important;
}

.facility-name {
  font-weight: 600;
}

.td-date {
  font-variant-numeric: tabular-nums;
}

.td-date.editable {
  cursor: pointer;
  position: relative;
}

.td-date.editable:hover {
  background: rgba(102, 126, 234, 0.1);
  color: var(--color-accent);
}

.td-date.current {
  font-weight: 600;
}

.td-date.predict {
  color: var(--color-accent);
  background: rgba(102, 126, 234, 0.05);
}

.td-date.adjusted {
  color: var(--color-warning);
}

.td-date.end-date {
  color: var(--text-muted);
}

.td-interval {
  color: var(--text-secondary);
}

.adjust-badge {
  display: inline-block;
  font-size: 0.6rem;
  background: rgba(255, 217, 61, 0.2);
  color: var(--color-warning);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  cursor: help;
}

.inline-date-input {
  width: 130px;
  padding: 4px 8px;
  border: 2px solid var(--color-accent);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

/* ----------------------------------------------------------
   前回データ列のデフォルト非表示 & トグル
   ---------------------------------------------------------- */

/* ツールバー */
.overview-toolbar {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

/* トグルボタン */
.btn-toggle-prev {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-toggle-prev:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: rgba(102, 126, 234, 0.08);
}

.btn-toggle-prev.active {
  background: rgba(102, 126, 234, 0.12);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* 前回データ列 - デフォルト非表示 */
.th-prev-data,
.td-prev-data {
  display: none;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  padding: 0;
  border: 0;
  transition: max-width 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

/* テーブルに .show-prev-data が付与された時に表示 */
.overview-table.show-prev-data .th-prev-data,
.overview-table.show-prev-data .td-prev-data {
  display: table-cell;
  max-width: 200px;
  overflow: visible;
  opacity: 1;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
}

.overview-table.show-prev-data .th-prev-data {
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-color);
}


/* ----------------------------------------------------------
   5w提案パネル
   ---------------------------------------------------------- */
.panel-5w {
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  animation: slideUp 0.3s ease;
}

.panel-5w-ok {
  background: rgba(81, 207, 102, 0.08);
  border: 1px solid rgba(81, 207, 102, 0.2);
}

.panel-5w-warning {
  background: rgba(255, 217, 61, 0.08);
  border: 1px solid rgba(255, 217, 61, 0.2);
}

.panel-5w-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.panel-5w-content {
  flex: 1;
}

.panel-5w-content strong {
  font-size: 1rem;
  display: block;
  margin-bottom: 8px;
}

.panel-5w-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.suggestion-5w-item {
  margin-top: 12px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius-sm);
}

.suggestion-facility {
  font-weight: 700;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 4px;
}

.suggestion-reason {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}

.suggestion-detail {
  font-size: 0.8rem;
  line-height: 1.6;
}

/* ----------------------------------------------------------
   Buttons
   ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
}

.btn-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

.btn-primary:hover {
  background: #5a6fd6;
}

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

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.15);
  border-color: var(--color-danger);
}

/* ----------------------------------------------------------
   Responsive - iPad
   ---------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 180px;
  }

  .calendar-month {
    width: 300px;
  }

  .app-header h1 {
    font-size: 1.1rem;
  }
}

/* ----------------------------------------------------------
   Responsive - Tablet Portrait
   ---------------------------------------------------------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    width: 260px;
    z-index: 150;
    box-shadow: var(--shadow-lg);
    transition: var(--transition-slow);
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .app-header {
    padding-left: 60px;
  }

  .calendar-month {
    width: 280px;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 140;
  }

  .sidebar-overlay.visible {
    display: block;
  }
}

/* ----------------------------------------------------------
   Responsive - Mobile
   ---------------------------------------------------------- */
@media (max-width: 600px) {
  .calendar-month {
    width: calc(100vw - 48px);
    min-width: 280px;
  }

  .calendar-nav {
    padding: 8px 12px;
    gap: 8px;
  }

  #calendar-nav-label {
    font-size: 0.85rem;
    min-width: auto;
  }

  .header-actions {
    gap: 4px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .overview-table {
    font-size: 0.75rem;
  }

  .overview-table th,
  .overview-table td {
    padding: 6px 8px;
  }

  .modal-content {
    width: 95%;
  }
}

/* ----------------------------------------------------------
   Toast Notification
   ---------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  z-index: 2000;
  animation: slideUp 0.3s ease;
  max-width: 320px;
}

.toast.success {
  border-left: 4px solid var(--color-success);
}

.toast.error {
  border-left: 4px solid var(--color-danger);
}

/* ----------------------------------------------------------
   Animations
   ---------------------------------------------------------- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ----------------------------------------------------------
   Theme Toggle Button
   ---------------------------------------------------------- */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
  transform: rotate(20deg);
}

body.light-mode .theme-toggle {
  background: #e9ecef;
  border-color: #ced4da;
}

body.light-mode .theme-toggle:hover {
  background: #dee2e6;
}

/* ライトモードでのヘッダータイトル */
body.light-mode .app-header h1 {
  background: linear-gradient(135deg, #e67700, #0ca678);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ----------------------------------------------------------
   Gantt Chart
   ---------------------------------------------------------- */
.gantt-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.gantt-nav-label {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 140px;
  text-align: center;
}

.gantt-scroll-wrapper {
  flex: 1;
  overflow: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.gantt-table {
  border-collapse: collapse;
  font-size: 0.75rem;
  min-width: 100%;
  table-layout: fixed;
}

.gantt-facility-th {
  position: sticky;
  left: 0;
  z-index: 20;
  background: var(--bg-card);
  min-width: 80px;
  max-width: 80px;
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.gantt-day-th {
  min-width: 32px;
  padding: 4px 2px;
  text-align: center;
  font-weight: 700;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.gantt-dow-th {
  min-width: 32px;
  padding: 2px;
  text-align: center;
  font-weight: 500;
  font-size: 0.65rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.gantt-day-th.gantt-holiday,
.gantt-dow-th.gantt-holiday {
  color: var(--color-sunday);
  background: rgba(255, 107, 107, 0.08);
}

.gantt-day-th.gantt-saturday,
.gantt-dow-th.gantt-saturday {
  color: var(--color-saturday);
}

.gantt-day-th.gantt-today,
.gantt-dow-th.gantt-today {
  background: rgba(102, 126, 234, 0.15);
  color: var(--color-accent);
}

.gantt-facility-td {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--bg-secondary);
  min-width: 80px;
  max-width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt-facility-name {
  font-weight: 600;
  font-size: 0.78rem;
}

.gantt-cell {
  min-width: 32px;
  height: 32px;
  padding: 2px;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--border-color);
  position: relative;
}

.gantt-holiday-cell {
  background: rgba(255, 107, 107, 0.12);
}

.gantt-saturday-cell {
  background: rgba(107, 163, 255, 0.1);
}

.gantt-today-cell {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.gantt-bar-cell {
  /* 帯の背景は inline style で施設色を適用 */
}

/* マーカー */
.gantt-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  color: white;
  font-size: 0.65rem;
  font-weight: 900;
  line-height: 1;
  vertical-align: middle;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.gantt-marker-presc {
  border-radius: 50%;
}

.gantt-marker-deliv {
  border-radius: 3px;
}

.gantt-marker-end {
  border-radius: 50%;
  opacity: 0.7;
}

/* 凡例 */
.gantt-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 16px;
  margin: 0 16px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
}

.gantt-legend-title {
  font-weight: 600;
  color: var(--text-secondary);
}

.gantt-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ビューモード3つ */
.view-mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-primary);
  border-radius: var(--border-radius-sm);
  padding: 4px;
}

@media (max-width: 600px) {
  .gantt-table { font-size: 0.65rem; }
  .gantt-day-th, .gantt-dow-th, .gantt-cell { min-width: 26px; }
  .gantt-facility-th, .gantt-facility-td { min-width: 60px; max-width: 60px; font-size: 0.7rem; }
  .gantt-marker { width: 15px; height: 15px; font-size: 0.5rem; }
}

/* ----------------------------------------------------------
   3ヶ月ガントチャート用スタイル
   ---------------------------------------------------------- */
.gantt-month-section {
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.gantt-secondary-month {
  opacity: 0.92;
  border-style: dashed;
}

.gantt-month-label {
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 700;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

/* ----------------------------------------------------------
   処方日数バッジ・入力用スタイル
   ---------------------------------------------------------- */
.th-cycle-days {
  width: 90px;
  text-align: center;
}

.td-cycle-days {
  text-align: center;
  font-weight: 600;
  cursor: pointer;
}

.cycle-days-badge {
  display: inline-block;
  padding: 3px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: var(--transition-fast);
}

.td-cycle-days:hover .cycle-days-badge {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.inline-number-input {
  width: 60px;
  padding: 4px 6px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  border: 2px solid var(--accent-primary);
  border-radius: var(--border-radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ----------------------------------------------------------
   Dr.提案パネル（改修⑤c）
   ---------------------------------------------------------- */
.dr-proposal-panel {
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.dr-proposal-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(236, 72, 153, 0.08));
  border-bottom: 1px solid var(--border-color);
}

.dr-proposal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.dr-icon {
  font-size: 1.25rem;
}

.dr-proposal-desc {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.dr-proposal-cards {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dr-proposal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-left: 6px solid #4f46e5;
  border-radius: var(--border-radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.dr-proposal-card.card-urgent {
  background: rgba(239, 68, 68, 0.04);
  border-color: rgba(239, 68, 68, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.facility-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.prop-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.urgency-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.urgency-badge.urgent {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.urgency-badge.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.88rem;
}

.prop-section {
  padding: 8px 12px;
  border-radius: var(--border-radius-sm);
}

.prop-issue {
  background: rgba(239, 68, 68, 0.06);
  border: 1px dashed rgba(239, 68, 68, 0.3);
}

.prop-action {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.prop-template {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
}

.sec-label {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.sec-content {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.template-box {
  margin-top: 4px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-sm);
  border-left: 3px solid var(--accent-primary);
}

.template-box code {
  font-family: inherit;
  font-size: 0.84rem;
  color: var(--text-primary);
  line-height: 1.5;
  display: block;
}

/* ----------------------------------------------------------
   月送りツールバー & 履歴ドロップダウン
   ---------------------------------------------------------- */
.month-shift-toolbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.month-shift-btn {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%) !important;
  color: #fff !important;
  font-weight: 600;
  padding: 8px 18px;
  border: none;
  border-radius: var(--border-radius-sm);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
  transition: all 0.2s ease;
  cursor: pointer;
}

.month-shift-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.5);
  filter: brightness(1.1);
}

.month-shift-btn:active {
  transform: translateY(0);
}

.history-btn {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--border-radius-sm);
  padding: 8px 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
}

.history-btn:hover {
  background: var(--bg-card-hover) !important;
  border-color: var(--color-accent) !important;
}

.history-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  width: 380px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-height: 400px;
  overflow-y: auto;
}

.history-dropdown-content {
  padding: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  border-radius: 6px;
  transition: background 0.15s ease;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--bg-card);
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-item-date {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.history-item-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 10px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.btn-sm:hover {
  background: var(--bg-card-hover);
}

.history-view-btn {
  color: var(--color-accent);
  border-color: rgba(102, 126, 234, 0.4);
}

.history-view-btn:hover {
  background: rgba(102, 126, 234, 0.15);
}

.history-restore-btn {
  color: var(--color-warning);
  border-color: rgba(255, 217, 61, 0.4);
}

.history-restore-btn:hover {
  background: rgba(255, 217, 61, 0.15);
}

.history-loading,
.history-empty {
  padding: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

