:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e9ecef;
  --bg-hover: #dee2e6;
  --border: #ced4da;
  --border-focus: #2563eb;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc3545;
  --danger-hover: #b02a37;
  --success: #198754;
  --warning: #ffc107;
  --shadow: 0 8px 32px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
}

[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --border: #30363d;
  --border-focus: #58a6ff;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --danger-hover: #da3633;
  --success: #3fb950;
  --warning: #d29922;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

button {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

button:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

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

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

.btn-primary:disabled,
.btn-primary.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

input, textarea, select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

select {
  cursor: pointer;
  appearance: auto;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* Toolbar */
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  backdrop-filter: blur(8px);
}

.toolbar-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hamburger-btn {
  display: none;
  font-size: 22px;
  padding: 4px 10px;
  cursor: pointer;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-search {
  flex: 1;
  min-width: 180px;
}

.toolbar-search input {
  min-width: 180px;
}

.selected-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: 20px;
}

/* Photo Grid */
.photo-grid {
  margin-top: 52px;
  margin-bottom: 60px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
}

.photo-item:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  z-index: 2;
}

.photo-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-item .photo-checkbox {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
  border-radius: var(--radius-sm);
}

.photo-item:hover .photo-checkbox,
.photo-item .photo-checkbox:checked {
  opacity: 1;
}

.photo-item .photo-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  padding: 2px 8px;
  background: rgba(0,0,0,0.7);
  border-radius: 20px;
  font-size: 10px;
  color: #fff;
  max-width: calc(100% - 12px);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
}

.photo-item .photo-checkbox:checked ~ .photo-badge {
  display: none;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 20px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state h2 {
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 15px;
  max-width: 440px;
  line-height: 1.6;
}

.loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Fullscreen Viewer */
.fullscreen-viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.95);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s;
}

.fullscreen-viewer.hidden {
  display: none;
}

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

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.viewer-toolbar .viewer-counter {
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: auto;
}

.viewer-toolbar .viewer-nav {
  display: flex;
  gap: 4px;
}

.viewer-toolbar .viewer-group-action {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto;
}

.viewer-toolbar .viewer-group-action select {
  width: auto;
  min-width: 120px;
}

.viewer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-width: 0;
}

.viewer-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.viewer-info {
  width: 300px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.viewer-info.collapsed {
  width: 0;
  padding: 0;
  overflow: hidden;
  border-left: none;
}

.viewer-info h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.viewer-info label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.viewer-info label span {
  font-weight: 500;
}

.viewer-info input[readonly] {
  color: var(--text-muted);
  cursor: default;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal.hidden {
  display: none;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 600px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-status {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 0;
}

.group-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.group-chip {
  padding: 6px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  user-select: none;
}

.group-chip:hover {
  background: var(--bg-hover);
}

.group-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.group-form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.group-form-row input {
  flex: 1;
}

.group-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.group-photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 4px;
  margin-top: 8px;
}

.group-photo-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.15s;
}

.group-photo-thumb:hover {
  transform: scale(1.05);
}

.group-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Selection Bar */
.selection-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s;
}

.selection-bar.hidden {
  display: none;
}

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

.selection-bar span {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Context Menu */
.context-menu {
  position: fixed;
  z-index: 250;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 180px;
}

.context-menu.hidden {
  display: none;
}

.context-menu button {
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: left;
  width: 100%;
}

.context-menu button:hover {
  background: var(--bg-hover);
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  flex-wrap: wrap;
}

.pagination-bar.hidden {
  display: none;
}

.pagination-bar button {
  min-width: 36px;
  justify-content: center;
}

.pagination-bar button.active-page {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.page-numbers {
  display: flex;
  gap: 4px;
  align-items: center;
}

.page-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
  white-space: nowrap;
}

/* Settings Dialog */
.settings-dialog {
  max-width: 640px;
  width: 90vw;
}

.settings-table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.settings-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.settings-table td:first-child {
  text-align: center;
  font-size: 18px;
}

.settings-table input {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.settings-row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.settings-row-actions button {
  padding: 4px 10px;
  font-size: 12px;
}

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

.settings-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  font-size: 13px;
  color: var(--text-primary);
}

.settings-field label {
  white-space: nowrap;
}

.settings-number-input {
  width: 80px;
  padding: 4px 8px;
  font-size: 13px;
  text-align: center;
}

.settings-actions button {
  padding: 8px 20px;
}

.status-ok { color: var(--success); }
.status-fail { color: var(--danger); }
.status-wait { color: var(--text-muted); }

/* About Dialog */
.about-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-family: 'Georgia', serif;
  font-size: 16px;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.about-dialog {
  max-width: 360px;
}

.about-body {
  text-align: center;
  padding: 32px 24px !important;
}

.about-logo {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.about-body h3 {
  font-size: 20px;
  margin-bottom: 8px;
}

.about-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Confirm Dialog */
.confirm-dialog {
  max-width: 420px;
}

.confirm-body {
  text-align: center;
  padding: 32px 24px !important;
}

.confirm-body h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.confirm-body p {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

.confirm-actions button {
  min-width: 100px;
  padding: 8px 24px;
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 500;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

.toast.info {
  border-color: var(--accent);
}

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

/* Progress Bar */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s;
}

.progress-overlay.hidden {
  display: none;
}

.progress-bar-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  min-width: 340px;
  box-shadow: var(--shadow);
  text-align: center;
}

.progress-label {
  font-size: 14px;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.progress-track {
  height: 10px;
  background: var(--bg-tertiary);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 5px;
  transition: width 0.25s ease;
}

.progress-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.progress-cancel-btn {
  margin-top: 16px;
  padding: 6px 24px;
  font-size: 13px;
  cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

::selection {
  background: var(--accent);
  color: #fff;
}

/* Responsive */
@media (max-width: 768px) {
  .hamburger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .toolbar {
    padding: 6px 10px;
  }

  .toolbar-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 99;
  }

  .toolbar-content.open {
    display: flex;
  }

  .toolbar-section {
    flex-wrap: wrap;
  }

  .toolbar-search {
    min-width: 0;
    flex: 1 1 100%;
  }

  .toolbar-search input {
    min-width: 0;
    width: 100%;
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 4px;
    padding: 4px;
  }

  .viewer-info {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .viewer-info.collapsed {
    width: 100%;
    height: 0;
    padding: 0;
  }

  .modal-dialog {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .pagination-bar {
    position: static;
    border-top: none;
    padding: 8px;
  }
}
