* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f0e8;
  color: #333;
  line-height: 1.6;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 20px;
}

/* ヘッダー */
.app-header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #fff;
  text-align: center;
  padding: 20px 16px 16px;
  margin: 0 -16px 20px;
}

.app-header h1 {
  font-family: "Noto Serif JP", serif;
  font-size: 2rem;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: 0.1em;
}

.app-subtitle {
  font-size: 0.85rem;
  color: #c9a94e;
  letter-spacing: 0.05em;
}

h2 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: #555;
}

.section {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

label {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

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

.input-row input,
.input-row select {
  flex: 1;
}

input[type="text"],
input[type="password"],
select {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
  width: 100%;
}

button {
  padding: 8px 16px;
  background: #8b0000;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

button:hover {
  background: #6b0000;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

/* ヘッダーバー */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.header-bar span {
  font-weight: bold;
}

.btn-small {
  padding: 4px 12px;
  font-size: 0.8rem;
  background: #666;
}

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

/* 2カラムレイアウト */
.main-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* サイドバー */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #1a1a2e;
  color: #fff;
  font-weight: bold;
  font-size: 0.9rem;
}

.sidebar-header .btn-small {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-header .btn-small:hover {
  background: rgba(255, 255, 255, 0.3);
}

.folder-tree {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 4px 0;
}

.tree-loading {
  padding: 12px;
  color: #999;
  font-size: 0.9rem;
}

.folder-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}

.folder-item:hover {
  background: #f5f0e8;
}

.folder-item.active {
  background: #fdf6e3;
  border-left-color: #c9a94e;
  font-weight: bold;
  color: #5a4a1e;
}

.folder-toggle {
  width: 16px;
  flex-shrink: 0;
  font-size: 0.7rem;
  color: #999;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.folder-item .folder-icon {
  margin-right: 4px;
  flex-shrink: 0;
}

.folder-item .folder-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-children {
  display: none;
}

.folder-children.open {
  display: block;
}

/* スピナー */
.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  color: #999;
  font-size: 0.9rem;
  gap: 12px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #eee;
  border-top-color: #8b0000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* メインコンテンツ */
.main-content {
  flex: 1;
  min-width: 0;
}

/* 画像登録エリア */
.upload-placeholder {
  text-align: center;
  font-size: 1.4rem;
  color: #8b0000;
  font-weight: bold;
  padding: 40px 20px;
  border: 2px dashed #8b0000;
  border-radius: 8px;
  background: #fff;
}

.upload-placeholder .arrow-icon {
  display: inline-block;
  animation: arrowBounce 1s ease-in-out infinite;
}

@keyframes arrowBounce {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-10px); }
}

.upload-area-header {
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
  font-weight: bold;
}

.upload-area-header span {
  color: #8b0000;
}

#uploadAreaContainer {
  display: flex;
  gap: 12px;
  transition: opacity 0.3s;
}

#uploadAreaContainer.disabled {
  opacity: 0.3;
  pointer-events: none;
  cursor: not-allowed;
}

.upload-box {
  flex: 1;
  border: 2px dashed #ccc;
  border-radius: 8px;
  padding: 30px 12px;
  text-align: center;
  color: #999;
  transition: border-color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  outline: none;
}

.upload-box:hover {
  background: #fdf6e3;
  border-color: #c9a94e;
}

.upload-box.active {
  border-color: #8b0000;
  background: #fff5f5;
}

.upload-icon {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 4px;
  pointer-events: none;
}

#clickZone {
  cursor: pointer;
}

#pasteZone:focus {
  border-color: #8b0000;
  border-style: solid;
}

#pasteZone {
  flex-direction: column;
  cursor: pointer;
}

#pasteZone.has-preview {
  padding: 12px;
}

.upload-box > p {
  pointer-events: none;
  margin: 0;
  line-height: 1.5;
  white-space: nowrap;
}

/* ペーストプレビュー */
#pastePreview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#pastePreviewImg {
  max-width: 100%;
  max-height: 120px;
  border-radius: 4px;
  object-fit: contain;
}

.paste-filename {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
}

.paste-filename input {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  text-align: center;
}

.paste-filename span {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
}

.paste-actions {
  display: flex;
  gap: 8px;
}

.paste-actions button {
  padding: 4px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

#pasteUploadBtn {
  background: #8b0000;
  color: #fff;
}

#pasteUploadBtn:hover {
  background: #6b0000;
}

#pasteCancelBtn {
  background: #e0e0e0;
  color: #333;
}

#pasteCancelBtn:hover {
  background: #ccc;
}

/* アップロードキュー */
#uploadQueue {
  margin-bottom: 12px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

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

.queue-item img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.queue-item .file-info {
  flex: 1;
  min-width: 0;
}

.queue-item .file-name {
  font-size: 0.85rem;
  color: #777;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item .file-size-warn {
  color: #e00;
  font-size: 0.8rem;
}

.queue-item input[type="text"] {
  width: 100%;
  padding: 4px 6px;
  font-size: 0.9rem;
}

.queue-item .remove-btn {
  background: none;
  color: #999;
  font-size: 1.2rem;
  padding: 4px 8px;
}

.queue-item .remove-btn:hover {
  color: #e00;
  background: none;
}

.queue-item .status {
  font-size: 0.8rem;
  white-space: nowrap;
}

.status-ok { color: #2a2; }
.status-err { color: #e00; }
.status-wait { color: #999; }
.status-uploading { color: #07c; }

/* 進捗バー */
#progress {
  text-align: center;
  margin-bottom: 12px;
}

#progressBar {
  width: 100%;
  height: 6px;
  background: #ddd;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: #8b0000;
  transition: width 0.3s;
}

#progressText {
  font-size: 0.85rem;
  color: #555;
}

/* 画像一覧ヘッダー */
.files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

.files-header span {
  font-size: 0.85rem;
  color: #555;
}

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

.files-controls label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: normal;
  margin-bottom: 0;
}

.files-controls select {
  width: auto;
  padding: 4px 6px;
  font-size: 0.85rem;
}

/* ページネーション */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 8px 0;
  flex-wrap: wrap;
}

.pagination:empty {
  display: none;
}

.page-btn {
  min-width: 32px;
  height: 28px;
  padding: 0 8px;
  font-size: 0.85rem;
  background: #fff;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
}

.page-btn:hover {
  background: #f0f0f0;
}

.page-btn.active {
  background: #c9a94e;
  color: #fff;
  border-color: #c9a94e;
}

.page-btn:disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
}

/* 既存画像 */
#existingFiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.existing-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid #ddd;
  cursor: pointer;
  transition: border-color 0.15s;
}

.existing-thumb:hover {
  border-color: #999;
}

.existing-thumb.selected {
  border-color: #c9a94e;
  box-shadow: 0 0 0 2px rgba(201, 169, 78, 0.3);
}

/* 右サイド画像詳細パネル */
.detail-panel {
  width: 300px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  align-self: flex-start;
  position: sticky;
  top: 20px;
}

.detail-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  font-weight: bold;
  font-size: 0.9rem;
}

.detail-close {
  font-size: 1.4rem;
  color: #999;
  cursor: pointer;
  line-height: 1;
}

.detail-close:hover {
  color: #333;
}

.detail-panel-body {
  padding: 12px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.detail-preview {
  display: block;
  max-width: 100%;
  max-height: 200px;
  margin: 0 auto 12px;
  border-radius: 4px;
  border: 1px solid #ddd;
}

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

.detail-table th {
  text-align: left;
  padding: 4px 8px;
  color: #777;
  white-space: nowrap;
  width: 100px;
  vertical-align: top;
}

.detail-table td {
  padding: 4px 8px;
  word-break: break-all;
}

.detail-url {
  font-size: 0.8rem;
  color: #07c;
}

/* トースト */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1a2e;
  color: #fff;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 1000;
}

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

#startUpload {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

/* ログイン画面は狭め */
#loginScreen {
  max-width: 400px;
  margin: 0 auto;
}
