:root {
  --bg: #eef5ff;
  --panel: #ffffff;
  --primary: #2f6fed;
  --primary-strong: #1f5ae0;
  --primary-soft: #dbe9ff;
  --primary-soft-strong: #e4efff;
  --warning: #d48b19;
  --warning-soft: #fff2d9;
  --danger: #d84b63;
  --danger-soft: #ffe9ee;
  --success: #1f8a5b;
  --success-soft: #ddf6ea;
  --text: #173052;
  --muted: #6b7a90;
  --border: #c9d9f2;
  --shadow: 0 18px 38px rgba(45, 95, 180, 0.14);
  --shadow-soft: 0 12px 28px rgba(45, 95, 180, 0.1);
  --shadow-primary: 0 14px 30px rgba(47, 111, 237, 0.24);
  --shadow-danger: 0 12px 24px rgba(216, 75, 99, 0.16);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #f5f9ff 0%, #eaf2ff 100%);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  padding: 20px 0;
  display: flex;
  align-items: stretch;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
  gap: 20px;
  align-items: stretch;
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.gallery-panel,
.settings-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  max-height: 100%;
}

.gallery-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  overflow: hidden;
}

.toolbar,
.upload-panel,
.settings-panel {
  padding: 24px;
}

.toolbar,
.upload-panel {
  background: linear-gradient(180deg, rgba(248, 251, 255, 0.98) 0%, rgba(238, 245, 255, 0.92) 100%);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, 0.92fr);
  align-items: stretch;
  gap: 12px;
  border-bottom: 1px solid rgba(201, 217, 242, 0.85);
}

.toolbar h1,
.settings-panel h2,
.upload-title,
.empty-state-title {
  margin: 0;
}

.toolbar h1,
.settings-panel h2 {
  font-size: 1.36rem;
  line-height: 1.2;
}

.toolbar-copy {
  display: grid;
  gap: 4px;
  align-content: start;
}

.hero-subtitle {
  margin: 0;
  color: var(--text);
  font-size: 0.94rem;
  line-height: 1.45;
  max-width: 36ch;
}

.hero-support {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.toolbar-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  justify-self: start;
  align-self: stretch;
  width: 100%;
  max-width: 520px;
  min-height: 100%;
}

.toolbar-inline-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.language-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

#language-select {
  min-width: 100px;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 6px;
}

.selection-count,
.sort-label {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

#sort-mode {
  min-width: 176px;
}

.toolbar-controls button {
  padding: 0 12px;
  white-space: nowrap;
}

button,
select,
input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
}

button,
select {
  min-height: 42px;
}

button {
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(45, 95, 180, 0.08);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease, color 180ms ease;
}

button:active:enabled {
  transform: translateY(0);
  box-shadow: inset 0 2px 8px rgba(23, 48, 82, 0.08);
}

button:hover:enabled,
button:focus-visible,
select:focus-visible,
input[type="number"]:focus-visible {
  outline: none;
  border-color: rgba(47, 111, 237, 0.72);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

button:hover:enabled {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: #f3f6fb;
  box-shadow: none;
  opacity: 0.72;
}

#select-all-btn,
#batch-rotate-btn {
  background: var(--primary-soft-strong);
  color: var(--primary-strong);
  border-color: rgba(47, 111, 237, 0.14);
}

#select-all-btn:hover:enabled,
#batch-rotate-btn:hover:enabled {
  background: #d8e8ff;
  border-color: rgba(47, 111, 237, 0.32);
  box-shadow: 0 10px 22px rgba(47, 111, 237, 0.14);
}

select,
input[type="number"] {
  width: 100%;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
}

select {
  min-width: 150px;
}

input[type="number"] {
  min-height: 44px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 600;
}

.thumbnail-list {
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(219, 233, 255, 0.28) 0%, rgba(255, 255, 255, 0.9) 100%),
    var(--bg);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thumbnail-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  align-content: start;
}

.empty-state-card,
.settings-placeholder {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 32px;
  border: 1px dashed var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: rgba(255, 255, 255, 0.82);
  text-align: center;
}

.empty-state-text,
.upload-text,
.settings-placeholder p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.upload-panel {
  border-top: 1px solid rgba(201, 217, 242, 0.85);
  background: linear-gradient(180deg, #edf5ff 0%, #dfeeff 100%);
  flex-shrink: 0;
}

.upload-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 16px;
}

.upload-trigger-btn {
  min-width: 132px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-primary);
  font-weight: 700;
}

.upload-trigger-btn:hover:enabled,
#export-btn:hover:enabled {
  background: linear-gradient(180deg, #3677f1 0%, #235fe2 100%);
  box-shadow: 0 18px 34px rgba(47, 111, 237, 0.28);
}

.upload-trigger-btn:active:enabled,
#export-btn:active:enabled {
  background: linear-gradient(180deg, #2865e6 0%, #1f58d8 100%);
}

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

.thumb-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 14px;
  border: 1px solid rgba(201, 217, 242, 0.92);
  border-radius: calc(var(--radius) - 6px);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.thumb-card:hover {
  transform: translateY(-2px);
  border-color: rgba(47, 111, 237, 0.34);
  box-shadow: 0 16px 34px rgba(45, 95, 180, 0.12);
}

.thumb-card:active {
  transform: translateY(0);
}

.thumb-card:not(.thumb-card-error) {
  cursor: grab;
}

.thumb-card:not(.thumb-card-error):active {
  cursor: grabbing;
}

.thumb-card-selected {
  border-color: rgba(47, 111, 237, 0.62);
  background: linear-gradient(180deg, rgba(232, 241, 255, 0.98) 0%, rgba(255, 255, 255, 0.98) 100%);
  box-shadow: 0 18px 36px rgba(47, 111, 237, 0.14);
}

.thumb-card-error {
  border-color: rgba(216, 75, 99, 0.3);
  background: linear-gradient(180deg, rgba(255, 244, 246, 0.96) 0%, rgba(255, 255, 255, 0.98) 100%);
}

.sortable-ghost {
  opacity: 0.45;
  border-style: dashed;
}

.thumb-select {
  display: inline-flex;
  align-items: center;
  width: fit-content;
}

.thumb-select input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.thumb-select input:hover,
.thumb-select input:focus-visible {
  filter: saturate(1.12);
}

.thumb-select input:active {
  transform: scale(0.96);
}

.thumb-select input:disabled {
  cursor: not-allowed;
}

.thumb-preview {
  display: grid;
  place-items: center;
  min-height: 156px;
  padding: 12px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(219, 233, 255, 0.7) 0%, rgba(247, 250, 255, 0.92) 100%),
    #f5f9ff;
  overflow: hidden;
}

.thumb-preview img {
  display: block;
  max-width: 100%;
  max-height: 132px;
  object-fit: contain;
  transition: transform 180ms ease;
}

.thumb-preview-error {
  border: 1px dashed rgba(216, 75, 99, 0.28);
  background: linear-gradient(180deg, rgba(255, 232, 237, 0.8) 0%, rgba(255, 246, 248, 0.96) 100%);
}

.thumb-error-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(216, 75, 99, 0.12);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 700;
}

.thumb-meta {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-word;
}

.thumb-meta-error {
  color: #aa3550;
}

.thumb-error-text {
  margin: -4px 0 0;
  color: #aa3550;
  font-size: 0.88rem;
  line-height: 1.5;
}

.thumb-actions {
  display: flex;
  gap: 10px;
}

.thumb-action-btn {
  flex: 1;
  min-height: 38px;
  padding: 0 12px;
}

.thumb-action-btn:hover:enabled {
  border-color: rgba(47, 111, 237, 0.44);
  background: rgba(233, 241, 255, 0.9);
}

.thumb-action-btn:active:enabled {
  background: rgba(219, 233, 255, 0.96);
}

.thumb-action-delete {
  color: var(--danger);
  border-color: rgba(216, 75, 99, 0.22);
  background: linear-gradient(180deg, rgba(255, 244, 246, 0.98) 0%, rgba(255, 249, 250, 1) 100%);
}

#batch-delete-btn {
  color: var(--danger);
  border-color: rgba(216, 75, 99, 0.22);
  background: linear-gradient(180deg, rgba(255, 244, 246, 0.98) 0%, rgba(255, 249, 250, 1) 100%);
}

.thumb-action-delete:hover:enabled {
  border-color: rgba(216, 75, 99, 0.44);
  background: rgba(255, 236, 240, 0.98);
  box-shadow: var(--shadow-danger);
}

#batch-delete-btn:hover:enabled {
  border-color: rgba(216, 75, 99, 0.44);
  background: rgba(255, 236, 240, 0.98);
  box-shadow: var(--shadow-danger);
}

.thumb-action-delete:active:enabled {
  background: rgba(255, 220, 227, 0.98);
}

#batch-delete-btn:active:enabled {
  background: rgba(255, 220, 227, 0.98);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: 14px;
}

.settings-stack {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.settings-card {
  padding: 10px;
  border: 1px solid rgba(201, 217, 242, 0.85);
  border-radius: calc(var(--radius) - 6px);
  background: linear-gradient(180deg, rgba(244, 248, 255, 0.95) 0%, rgba(255, 255, 255, 0.96) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.settings-card h3 {
  margin: 0 0 6px;
  font-size: 0.92rem;
}

.settings-grid {
  display: grid;
  gap: 8px;
}

.settings-grid-compact {
  gap: 10px;
}

.field-row {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 0.92rem;
}

.field-row-compact {
  gap: 6px;
  font-size: 0.9rem;
}

.field-row-compact span {
  line-height: 1.3;
}

.field-row input[aria-invalid="true"] {
  border-color: rgba(216, 75, 99, 0.62);
  background: linear-gradient(180deg, rgba(255, 243, 246, 0.98) 0%, rgba(255, 255, 255, 1) 100%);
}

.settings-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.field-group {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 8px;
}

.field-group-compact {
  gap: 8px;
}

.field-group legend {
  padding: 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
}

.orientation-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

.margin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}

.margin-field {
  display: grid;
  align-content: start;
}

.choice-chip input {
  margin: 0;
}

.field-error {
  min-height: 20px;
  margin: -2px 0 0;
  color: #b13b55;
  font-size: 0.86rem;
  line-height: 1.45;
}

.field-error-compact {
  min-height: 16px;
  margin-top: 2px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#export-btn {
  width: 100%;
  margin-top: 6px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-primary);
  font-weight: 700;
}

#export-btn:disabled {
  background: #d8e2f2;
  color: #7a8798;
}

#toast-region {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  gap: 12px;
  pointer-events: none;
  z-index: 20;
}

.toast-message {
  min-width: min(320px, calc(100vw - 40px));
  max-width: 420px;
  padding: 12px 14px;
  border: 1px solid rgba(23, 48, 82, 0.1);
  border-radius: 14px;
  background: rgba(23, 48, 82, 0.92);
  box-shadow: 0 16px 36px rgba(23, 48, 82, 0.22);
  color: #fff;
  font-size: 0.92rem;
  line-height: 1.5;
}

.toast-message[data-level="success"] {
  border-color: rgba(31, 138, 91, 0.22);
  background: rgba(31, 138, 91, 0.96);
  box-shadow: 0 16px 36px rgba(31, 138, 91, 0.22);
}

.toast-message[data-level="warning"] {
  border-color: rgba(212, 139, 25, 0.22);
  background: rgba(212, 139, 25, 0.96);
  box-shadow: 0 16px 36px rgba(212, 139, 25, 0.22);
}

.toast-message[data-level="error"] {
  border-color: rgba(216, 75, 99, 0.22);
  background: rgba(216, 75, 99, 0.96);
  box-shadow: 0 16px 36px rgba(216, 75, 99, 0.24);
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    align-items: start;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .gallery-panel,
  .settings-panel {
    min-height: auto;
    height: auto;
    max-height: none;
  }

  .thumbnail-list,
  .settings-panel,
  .settings-stack {
    overflow: visible;
  }

  .margin-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .toolbar-side {
    display: grid;
    width: 100%;
    max-width: none;
    justify-items: stretch;
    justify-self: stretch;
    align-self: auto;
    min-height: auto;
  }

  .toolbar-inline-group {
    justify-content: flex-start;
    width: 100%;
    flex-wrap: wrap;
  }

  #language-select,
  #sort-mode {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100% - 24px, 960px);
    padding: 20px 0 32px;
  }
}

@media (max-width: 640px) {
  .toolbar-controls {
    justify-content: flex-start;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .toolbar-copy {
    gap: 4px;
  }

  .sort-label {
    grid-column: 1 / -1;
  }

  .toolbar-inline-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .toolbar-inline-group #language-select,
  .toolbar-inline-group #sort-mode,
  .toolbar-controls button {
    width: 100%;
  }

  .toolbar,
  .upload-panel,
  .settings-panel,
  .thumbnail-list {
    padding: 20px;
  }

  .settings-card {
    padding: 12px;
  }

  .thumbnail-list-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
  }

  .thumb-actions {
    flex-direction: column;
  }

  #toast-region {
    right: 12px;
    left: 12px;
    bottom: 12px;
  }

  .toast-message {
    min-width: 0;
    max-width: none;
  }
}
