/* === リセット・基本 === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Meiryo', 'Yu Gothic', sans-serif;
  font-size: 16px;
  color: #333;
  background: #f5f5f5;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === ヘッダー === */
#header {
  background: #2c6fbb;
  color: #fff;
  padding: 10px 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 20px;
}

#header h1 {
  font-size: 20px;
  font-weight: bold;
}

#app-version {
  font-size: 13px;
  font-weight: normal;
  opacity: 0.85;
}

.version-badge {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.version-badge:hover {
  background: rgba(255, 255, 255, 0.28);
}

.btn-header {
  background: #fff;
  color: #2c6fbb;
  font-weight: bold;
  padding: 8px 20px;
  font-size: 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-header:hover {
  background: #e0ecf8;
}

/* === 保存状態バナー === */
.storage-banner {
  flex-shrink: 0;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  font-size: 13px;
  line-height: 1.4;
}

.storage-banner.storage-nas {
  background: #e8f5e9;
  color: #155724;
}

.storage-banner.storage-local {
  background: #fff3cd;
  color: #6b4f00;
}

.storage-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

#storage-message {
  font-weight: bold;
  white-space: nowrap;
}

#storage-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 48vw;
  opacity: 0.9;
}

.storage-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#storage-error {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 38vw;
}

.storage-nas #storage-error,
.storage-nas #retry-nas-btn {
  display: none;
}

.btn-storage {
  background: #fff;
  color: #6b4f00;
  border: 1px solid #d6a700;
  padding: 5px 12px;
  font-size: 13px;
  white-space: nowrap;
}

.btn-storage:hover {
  background: #ffe8a1;
}

.btn-storage:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* === メインレイアウト === */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* === 左パネル: 利用者一覧 === */
#left-panel {
  width: 280px;
  min-width: 280px;
  background: #fff;
  border-right: 2px solid #ddd;
  display: flex;
  flex-direction: column;
}

#filter-box {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px 0;
}

#filter-box select {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

#stay-type-select,
#sort-select {
  flex: 0 0 100% !important;
}

#filter-box select:focus {
  border-color: #2c6fbb;
  outline: none;
}

#search-box {
  padding: 10px;
  border-bottom: 1px solid #eee;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
  outline: none;
}

#search-input:focus {
  border-color: #2c6fbb;
}

#archive-toggle-box {
  padding: 4px 10px 6px;
  border-bottom: 1px solid #eee;
}

#archive-toggle-box label {
  font-size: 12px;
  color: #888;
  cursor: pointer;
}

#resident-list-container {
  flex: 1;
  overflow-y: auto;
}

#resident-list {
  list-style: none;
}

#resident-list li {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.15s;
}

#resident-list li:hover {
  background: #e8f0fe;
}

#resident-list li.selected {
  background: #2c6fbb;
  color: #fff;
}

.resident-name {
  font-size: 17px;
  font-weight: bold;
}

.resident-furigana {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

.resident-stay-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: normal;
  background: #f0ad4e;
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

#resident-list li.selected .resident-stay-badge {
  background: rgba(255, 255, 255, 0.3);
}

#resident-list li.drag-over {
  background: #ffe9a8 !important;
  outline: 2px dashed #f0ad4e;
}

#pdf-section.drag-over {
  background: #fff7e0;
  outline: 3px dashed #f0ad4e;
  outline-offset: -8px;
}

#resident-list li.archived {
  opacity: 0.5;
}

.resident-archived-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: normal;
  background: #999;
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.resident-unit {
  font-size: 11px;
  color: #aaa;
  margin-top: 1px;
  font-weight: bold;
}

/* PDF件数・最終取込日バッジ */
.resident-summary {
  font-size: 11px;
  color: #666;
  margin-top: 2px;
}

.resident-summary.zero {
  color: #d9534f;
  font-weight: bold;
}

.resident-summary.stale {
  color: #e08e00;
  font-weight: bold;
}

#resident-list li.selected .resident-summary,
#resident-list li.selected .resident-summary.zero,
#resident-list li.selected .resident-summary.stale {
  color: #fff;
}

.resident-unit.floor-1 { color: #006BBC; }
.resident-unit.floor-2 { color: #DC02A3; }
.resident-unit.floor-3 { color: #A8AC0C; }

#resident-list li.selected .resident-unit.floor-1,
#resident-list li.selected .resident-unit.floor-2,
#resident-list li.selected .resident-unit.floor-3 {
  color: #fff;
}

#resident-list li.selected .resident-furigana,
#resident-list li.selected .resident-unit {
  color: #c0d8f0;
}

/* === 右パネル: PDF管理 === */
#right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#no-selection {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-size: 18px;
}

#pdf-section {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#pdf-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

#pdf-header h2 {
  font-size: 20px;
  min-width: 200px;
}

#pdf-header-buttons {
  display: flex;
  gap: 8px;
}

.btn-archive {
  background: #999;
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
}

.btn-archive:hover {
  background: #777;
}

.btn-unarchive {
  background: #5cb85c;
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
}

.btn-unarchive:hover {
  background: #449d44;
}

/* === PDF一覧テーブル === */
#pdf-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#pdf-list-container {
  overflow-y: auto;
  padding: 10px 20px;
  min-height: 120px;
  flex-shrink: 0;
  border-right: 1px solid #ddd;
}

#pdf-table {
  border-collapse: collapse;
  width: auto !important;
  table-layout: auto;
}

#pdf-table thead th:first-child,
#pdf-table tbody td:first-child {
  min-width: 260px;
  max-width: 400px;
}

#pdf-table thead th {
  text-align: left;
  padding: 8px 12px;
  background: #f0f0f0;
  border-bottom: 2px solid #ddd;
  font-size: 14px;
  color: #666;
}

.action-col {
  width: 200px;
  text-align: center !important;
}

.date-col {
  width: 120px;
  text-align: center !important;
}

#pdf-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

#pdf-table tbody tr:hover {
  background: #e8f0fe;
}

#pdf-table tbody tr.viewing {
  background: #d0e4ff;
}

#pdf-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  font-size: 15px;
}

#pdf-table tbody td.action-col {
  text-align: center;
}

#no-pdfs {
  color: #999;
  padding: 20px 0;
  text-align: center;
  font-size: 15px;
}

/* === PDFプレビュー === */
#pdf-preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: #f8f8f8;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

#preview-filename {
  font-size: 14px;
  color: #555;
  font-weight: bold;
}

#preview-header-buttons {
  display: flex;
  gap: 8px;
}

#pdf-preview {
  flex: 1;
  background: #e0e0e0;
}

#pdf-object {
  display: block;
  border: none;
  width: 100%;
  height: 100%;
}

/* === ボタン === */
.btn {
  padding: 8px 20px;
  font-size: 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: #2c6fbb;
  color: #fff;
  font-size: 16px;
  padding: 10px 24px;
}

.btn-primary:hover {
  background: #1e5a9e;
}

.btn-small {
  padding: 5px 12px;
  font-size: 13px;
  background: #e0e0e0;
  color: #333;
}

.btn-small:hover {
  background: #ccc;
}

.btn-danger {
  background: #d9534f;
  color: #fff;
  padding: 4px 10px;
  font-size: 13px;
}

.btn-danger:hover {
  background: #c9302c;
}

.btn-open {
  background: #5cb85c;
  color: #fff;
  padding: 4px 10px;
  font-size: 13px;
}

.btn-open:hover {
  background: #449d44;
}

/* === エラーダイアログ === */
#error-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#error-dialog {
  background: #fff;
  border-radius: 8px;
  padding: 24px 32px;
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#error-dialog h3 {
  color: #d9534f;
  margin-bottom: 12px;
  font-size: 18px;
  flex-shrink: 0;
}

#error-message {
  white-space: pre-wrap;
  margin-bottom: 20px;
  font-size: 15px;
  line-height: 1.6;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#error-ok-btn {
  display: block;
  margin-left: auto;
  background: #2c6fbb;
  color: #fff;
  padding: 8px 32px;
}

/* === 更新履歴 === */
#history-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

#history-dialog {
  background: #fff;
  border-radius: 8px;
  width: min(720px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#history-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #ddd;
}

#history-dialog-header h3 {
  font-size: 18px;
  color: #2c6fbb;
}

#history-version {
  font-size: 13px;
  color: #666;
  font-weight: normal;
}

#history-content {
  padding: 12px 20px;
  overflow-y: auto;
  line-height: 1.7;
  font-size: 14px;
}

#history-content h4 {
  margin: 12px 0 6px;
  font-size: 16px;
  color: #333;
}

#history-content ul {
  margin: 0 0 10px 1.4em;
}

#history-content li {
  margin: 3px 0;
}

#history-content p {
  margin: 6px 0;
}

#history-footer {
  padding: 12px 18px;
  border-top: 1px solid #ddd;
  display: flex;
  justify-content: flex-end;
}

#history-close-btn {
  background: #2c6fbb;
  color: #fff;
  padding: 8px 28px;
}

/* === ローディング === */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#loading-spinner p {
  font-size: 18px;
  color: #555;
}

/* === 一括取込モーダル === */
#bulk-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

#bulk-modal {
  background: #fff;
  border-radius: 8px;
  width: 95%;
  height: 90%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
  transition: width 0.15s, height 0.15s, border-radius 0.15s;
}

/* 最大化: ビューポート全体を使う */
#bulk-modal.maximized {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

#bulk-modal.maximized #bulk-modal-header {
  border-radius: 0;
}

/* 最大化時のサムネイル拡大は JS 側で bulkThumbScale を調整して実現 */

#bulk-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #2c6fbb;
  color: #fff;
  border-radius: 8px 8px 0 0;
}

#bulk-modal-header h2 {
  font-size: 18px;
}

#bulk-modal-header-buttons {
  display: flex;
  gap: 8px;
}

#bulk-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 左: ページ一覧 */
#bulk-pages {
  flex: 3;
  display: flex;
  flex-direction: column;
  border-right: 2px solid #ddd;
}

#bulk-pages h3 {
  padding: 10px 16px;
  font-size: 15px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#bulk-page-info {
  font-weight: normal;
  font-size: 13px;
  color: #666;
}

/* ズームコントロール */
#bulk-zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin-left: auto;
}

#bulk-zoom-controls .btn-small {
  padding: 2px 10px;
  font-size: 15px;
  min-width: 32px;
  line-height: 1.2;
}

#bulk-zoom-label {
  font-size: 13px;
  color: #333;
  min-width: 44px;
  text-align: center;
}

#bulk-zoom-hint {
  font-size: 11px;
  color: #888;
  font-weight: normal;
}

#bulk-page-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-content: flex-start;
  --bulk-thumb-scale: 1;
}

.bulk-page-item {
  width: calc(140px * var(--bulk-thumb-scale));
  border: 3px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, width 0.15s, box-shadow 0.15s;
  position: relative;
  background: #fff;
}

.bulk-page-item:hover {
  border-color: #2c6fbb;
}

.bulk-page-item.selected {
  border-color: #ff6a00;
  box-shadow: 0 0 0 4px #ff6a00, 0 0 14px rgba(255, 106, 0, 0.6);
}

.bulk-page-item.assigned {
  border-color: #5cb85c;
  opacity: 0.7;
}

.bulk-page-thumb {
  width: 100%;
  height: calc(180px * var(--bulk-thumb-scale));
  background: #e8e8e8;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: height 0.15s;
  position: relative;
}

.bulk-page-thumb object {
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: transform 0.15s;
  transform-origin: center center;
}

/* 回転時でも確実にクリックを拾えるよう、PDF の上に透明な受けを置く */
.bulk-page-thumb-click-catcher {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: pointer;
}

/* 回転クラス:
   180° は同じ縦横比なのでそのまま回転。
   90°/270° は <object> 自体を横長サイズ(180×140)で絶対配置し、回転させて
   縦長のサムネイル枠(140×180)にぴったり収める。
   scale(0.78) で縮小していた従来方式より、同じ拡大率で内容が大きく見える。 */
.bulk-page-thumb.rot-180 object { transform: rotate(180deg); }

.bulk-page-thumb.rot-90 object,
.bulk-page-thumb.rot-270 object {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(180px * var(--bulk-thumb-scale));
  height: calc(140px * var(--bulk-thumb-scale));
}

.bulk-page-thumb.rot-90 object { transform: translate(-50%, -50%) rotate(90deg); }
.bulk-page-thumb.rot-270 object { transform: translate(-50%, -50%) rotate(270deg); }

/* 回転ボタン（サムネイル右上） */
.bulk-rotate-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(44, 111, 187, 0.9);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  padding: 0;
  line-height: 1;
}

.bulk-rotate-btn:hover {
  background: #2c6fbb;
  transform: scale(1.1);
}

.bulk-page-label {
  text-align: center;
  padding: 4px;
  font-size: 13px;
  background: #f8f8f8;
  border-top: 1px solid #eee;
}

.bulk-page-assigned-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(92, 184, 92, 0.9);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  text-align: center;
}

/* 右: 割り当て操作 */
#bulk-assign {
  flex: 2;
  display: flex;
  flex-direction: column;
  min-width: 260px;
  overflow: hidden;
}

#bulk-assign h3 {
  padding: 10px 16px;
  font-size: 15px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

#bulk-assign-controls {
  padding: 12px 16px;
  flex: 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#bulk-selected-pages-label {
  font-size: 14px;
  margin-bottom: 8px;
  color: #555;
}

/* 一括取込の利用者絞り込み */
#bulk-resident-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.bulk-filter-row {
  display: flex;
  gap: 6px;
}

#bulk-resident-filters select,
#bulk-resident-filters input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
}

#bulk-resident-filters input:focus,
#bulk-resident-filters select:focus {
  border-color: #2c6fbb;
  outline: none;
}

#bulk-resident-select {
  width: 100%;
  flex: 1;
  min-height: 80px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin-bottom: 10px;
  padding: 4px;
}

#bulk-resident-select option {
  padding: 6px 8px;
}

#bulk-assign-controls .btn-primary {
  width: 100%;
}

#bulk-assignments-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

.bulk-assignment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #f0f8f0;
  border: 1px solid #c3e6cb;
  border-radius: 4px;
  font-size: 14px;
}

.bulk-assignment-item .assignment-info {
  flex: 1;
}

.bulk-assignment-item .assignment-name {
  font-weight: bold;
}

.bulk-assignment-item .assignment-pages {
  font-size: 12px;
  color: #666;
}

#bulk-save-area {
  padding: 12px 16px;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

#bulk-save-area .btn-primary {
  width: 100%;
  font-size: 17px;
  padding: 12px;
}

#bulk-save-area .btn-primary:disabled {
  background: #aaa;
  cursor: not-allowed;
}

/* === スクロールバー === */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f0f0f0;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* === サンプル版（ブラウザデモ）専用スタイル === */
.demo-badge {
  background: #e8b93c;
  color: #4a3800;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
}

.demo-facility {
  font-size: 13px;
  opacity: 0.9;
  white-space: nowrap;
}

/* サンプル版では NAS 再接続は意味を持たないため非表示 */
#retry-nas-btn {
  display: none;
}

/* デモ用トースト通知 */
#demo-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(16px);
  max-width: 80vw;
  background: rgba(40, 50, 60, 0.94);
  color: #fff;
  padding: 12px 22px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
}

#demo-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
