:root {
  color-scheme: light;
  --page: #f4f6f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dce2e5;
  --line-strong: #c4cdd2;
  --text: #162126;
  --muted: #66747b;
  --primary: #1769aa;
  --primary-hover: #105b96;
  --primary-soft: #e9f3fb;
  --success: #137a72;
  --success-soft: #e7f5f2;
  --warning: #a76614;
  --warning-soft: #fff4df;
  --danger: #b63c3c;
  --danger-soft: #fff0ef;
  --shadow: 0 12px 32px rgba(24, 39, 48, 0.09);
  font-family: "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled, select:disabled { cursor: not-allowed; opacity: 0.48; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.24);
  outline-offset: 2px;
}

.tool-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1.5fr) auto;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
}

.brand-link,
.folder-status {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand-link {
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-link img { flex: 0 0 auto; }
.brand-link span, .folder-status > span:last-child { min-width: 0; }
.brand-link strong, .folder-status strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-link small, .folder-status small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.folder-status { gap: 10px; }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #aab3b8; box-shadow: 0 0 0 4px #edf0f1; }
.folder-status.ready .status-dot { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.folder-status.warning .status-dot { background: var(--warning); box-shadow: 0 0 0 4px var(--warning-soft); }

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

button,
.site-link {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button { color: #fff; background: var(--primary); border-color: var(--primary); }
.primary-button:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.secondary-button, .icon-text-button, .site-link { color: var(--text); background: var(--surface); border-color: var(--line-strong); }
.secondary-button:hover:not(:disabled), .icon-text-button:hover:not(:disabled), .site-link:hover { background: #f1f5f7; border-color: #aebbc1; }
.danger-text-button { color: var(--danger); background: var(--surface); border-color: #e5b7b7; }
.danger-text-button:hover:not(:disabled) { background: var(--danger-soft); }
.full-width { width: 100%; }
.compact { min-height: 36px; padding: 7px 13px; }

.app-layout {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.side-nav {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px 14px;
  background: #edf1f2;
  border-right: 1px solid var(--line);
}

.nav-button {
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 9px 13px;
  color: #314047;
  background: transparent;
  border-color: transparent;
  text-align: left;
}

.nav-button:hover { background: rgba(255, 255, 255, 0.72); }
.nav-button.active { color: #0f5f9d; background: var(--surface); border-color: var(--line); box-shadow: 0 4px 14px rgba(29, 52, 63, 0.06); }
.nav-button small { margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 500; }

.support-note { margin-top: auto; padding: 14px 12px; color: #435158; border-top: 1px solid var(--line-strong); }
.support-note strong { font-size: 13px; }
.support-note p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.workspace { min-width: 0; padding: 26px clamp(18px, 3vw, 42px) 48px; }
.view { width: min(1540px, 100%); margin: 0 auto; }
.view[hidden] { display: none; }

.view-heading {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow { color: var(--success); font-size: 12px; font-weight: 750; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.25; }
h2 { margin: 0; font-size: 17px; }
h3 { margin: 0; font-size: 17px; }

.scan-progress { width: min(360px, 40vw); display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px; color: var(--muted); font-size: 12px; }
.scan-progress progress { grid-column: 1 / -1; width: 100%; height: 8px; }

.compatibility-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  color: #704507;
  background: var(--warning-soft);
  border: 1px solid #eccd96;
  border-radius: 6px;
  line-height: 1.55;
}

.compatibility-banner.error { color: #8c2929; background: var(--danger-soft); border-color: #e5b7b7; }
.compatibility-banner.success { color: #125d57; background: var(--success-soft); border-color: #a9d7d1; }

.compare-layout {
  display: grid;
  grid-template-columns: minmax(310px, 1fr) 210px minmax(310px, 1fr);
  gap: 18px;
  align-items: start;
}

.monster-browser,
.action-box,
.group-quick-add,
.history-list-panel,
.history-detail,
.group-list-panel,
.group-workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.monster-browser { min-width: 0; overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 17px 12px; }
.panel-heading > div { display: flex; align-items: center; gap: 9px; }
.step-number { width: 25px; height: 25px; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; background: var(--success); font-size: 12px; font-weight: 750; }
.count-label { color: var(--muted); font-size: 12px; }

.search-field { display: grid; gap: 6px; padding: 0 17px 13px; color: #4d5c63; font-size: 12px; font-weight: 650; }
.search-field input,
.group-input-row input,
.group-input-row select,
.group-quick-add select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.monster-list {
  height: 390px;
  overflow: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.monster-row {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 11px;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid #eef1f2;
  border-radius: 0;
  text-align: left;
}

.monster-row:hover { background: #f5f8fa; }
.monster-row.selected { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.monster-row img { width: 44px; height: 44px; object-fit: contain; image-rendering: auto; }
.monster-row-copy { min-width: 0; }
.monster-row-copy strong, .monster-row-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monster-row-copy strong { font-size: 14px; }
.monster-row-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
.row-state { padding: 4px 7px; color: #56646a; background: #eef2f3; border-radius: 999px; font-size: 11px; }
.row-state.modified { color: #0e665f; background: var(--success-soft); }
.row-state.deleted { color: #982f2f; background: var(--danger-soft); }

.selection-preview { min-height: 150px; display: grid; grid-template-columns: 122px minmax(0, 1fr); gap: 14px; align-items: center; margin: 0; padding: 15px 17px; }
.preview-image-wrap { width: 122px; height: 122px; display: grid; place-items: center; overflow: hidden; background: #f7f9fa; border: 1px solid var(--line); border-radius: 6px; }
.preview-image-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-image-wrap img:not([src]), .preview-image-wrap img[src=""] { visibility: hidden; }
.preview-copy { min-width: 0; }
.selection-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.preview-copy p { margin: 6px 0 9px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { padding: 4px 7px; color: #44545b; background: #edf2f4; border-radius: 999px; font-size: 11px; }
.tag.success { color: #0f665f; background: var(--success-soft); }
.tag.warning { color: #854f0a; background: var(--warning-soft); }

.action-column { display: grid; gap: 13px; padding-top: 112px; }
.action-direction { color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.action-box, .group-quick-add { padding: 15px; }
.action-box h2 { margin-bottom: 12px; }
.toggle-row { display: grid; grid-template-columns: 20px 1fr; gap: 9px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.toggle-row input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--primary); }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row small { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.auto-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 0; color: var(--muted); font-size: 12px; }
.auto-status strong { color: var(--text); font-size: 11px; text-align: right; }
.action-box .primary-button, .action-box .danger-text-button { width: 100%; margin-bottom: 8px; }
.group-quick-add { display: grid; gap: 8px; }
.group-quick-add label { color: var(--muted); font-size: 12px; font-weight: 650; }

.empty-list, .empty-state { display: grid; place-items: center; align-content: center; min-height: 180px; padding: 24px; color: var(--muted); text-align: center; }
.empty-state strong { color: #3d4c53; font-size: 16px; }
.empty-state p { margin: 6px 0 0; font-size: 13px; line-height: 1.55; }

.history-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 18px; min-height: 610px; }
.history-list-panel { overflow: hidden; }
.history-list-panel .search-field { padding-top: 16px; }
.history-list { max-height: 545px; overflow: auto; border-top: 1px solid var(--line); }
.history-row { width: 100%; min-height: 72px; display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 10px; padding: 10px 13px; color: inherit; background: #fff; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; }
.history-row:hover, .history-row.selected { background: var(--primary-soft); }
.history-row img { width: 48px; height: 48px; object-fit: contain; }
.history-row strong, .history-row small { display: block; }
.history-row small { margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 500; }
.history-detail { min-width: 0; padding: 20px; }
.history-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.history-detail-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.history-images { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.history-image-card { min-width: 0; }
.history-image-card span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.history-image-card div { height: 250px; display: grid; place-items: center; overflow: hidden; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.history-image-card img { max-width: 100%; max-height: 100%; object-fit: contain; }
.history-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.history-meta div { padding: 11px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.history-meta span, .history-meta strong { display: block; }
.history-meta span { color: var(--muted); font-size: 11px; }
.history-meta strong { margin-top: 4px; font-size: 13px; }

.groups-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 18px; min-height: 620px; }
.group-list-panel { padding: 10px; }
.group-list { display: grid; gap: 6px; }
.group-row { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 11px 12px; color: inherit; background: #fff; border-color: transparent; text-align: left; }
.group-row:hover, .group-row.selected { background: var(--primary-soft); border-color: #c4dced; }
.group-row strong, .group-row small { display: block; }
.group-row small { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
.group-row > span:last-child { color: var(--muted); font-size: 12px; }
.group-workspace { min-width: 0; overflow: hidden; }
.group-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.group-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.group-header-actions { display: flex; gap: 8px; }
.group-input-row { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 9px; padding: 13px 18px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.group-input-row label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; font-weight: 650; }
.group-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.group-toolbar .toolbar-spacer { flex: 1; }
.group-table-wrap { max-height: 465px; overflow: auto; }
.group-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.group-table th { position: sticky; z-index: 1; top: 0; padding: 9px 10px; color: #506067; background: #eef2f3; border-bottom: 1px solid var(--line-strong); font-size: 11px; text-align: left; }
.group-table td { height: 68px; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.group-table tr:hover td { background: #f8fafb; }
.group-table .check-column { width: 44px; text-align: center; }
.group-table .image-column { width: 74px; }
.group-table .type-column { width: 100px; }
.group-table .status-column { width: 100px; }
.group-table img { width: 58px; height: 58px; object-fit: contain; }
.monster-name-cell strong, .monster-name-cell small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monster-name-cell small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.toast-region { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: grid; gap: 8px; width: min(390px, calc(100vw - 36px)); }
.toast { padding: 12px 14px; color: #fff; background: #26363d; border-radius: 6px; box-shadow: var(--shadow); line-height: 1.45; animation: toast-in 160ms ease-out; }
.toast.success { background: #126b64; }
.toast.error { background: #a63838; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.app-dialog { width: min(470px, calc(100vw - 30px)); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.app-dialog::backdrop { background: rgba(20, 29, 34, 0.48); }
.dialog-shell { display: grid; gap: 16px; padding: 22px; }
.dialog-shell h2 { margin-top: 4px; font-size: 21px; }
.dialog-shell p { margin: 0; color: #536168; line-height: 1.6; }
.dialog-detail { max-height: 180px; overflow: auto; padding: 11px; color: #5a461f; background: var(--warning-soft); border: 1px solid #ecd09b; border-radius: 5px; font-size: 12px; white-space: pre-wrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.progress-dialog progress { width: 100%; height: 10px; }

@media (max-width: 1180px) {
  .tool-header { grid-template-columns: 220px minmax(220px, 1fr); }
  .header-actions { grid-column: 1 / -1; justify-content: flex-start; overflow-x: auto; padding-top: 2px; }
  .app-layout { min-height: calc(100vh - 122px); }
  .side-nav { top: 122px; height: calc(100vh - 122px); }
  .compare-layout { grid-template-columns: minmax(300px, 1fr) 190px minmax(300px, 1fr); }
  .selection-preview { grid-template-columns: 98px minmax(0, 1fr); }
  .preview-image-wrap { width: 98px; height: 98px; }
}

@media (max-width: 980px) {
  .app-layout { grid-template-columns: 1fr; }
  .side-nav { position: sticky; z-index: 15; top: 122px; height: auto; display: grid; grid-template-columns: repeat(3, 1fr); padding: 7px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-button { min-height: 48px; align-items: center; padding: 6px; text-align: center; }
  .nav-button small, .support-note { display: none; }
  .workspace { padding-top: 20px; }
  .compare-layout { grid-template-columns: 1fr 1fr; }
  .action-column { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-top: 0; }
  .action-direction { grid-column: 1 / -1; }
  .history-layout, .groups-layout { grid-template-columns: 1fr; }
  .history-list-panel { max-height: 300px; }
  .history-list { max-height: 225px; }
}

@media (max-width: 680px) {
  .tool-header { position: relative; grid-template-columns: 1fr; gap: 9px; padding: 10px 14px; }
  .brand-link small { display: none; }
  .folder-status { order: 3; }
  .header-actions { grid-column: auto; width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 2px 0 4px; overflow: visible; }
  .header-actions button, .header-actions a { min-width: 0; min-height: 36px; padding: 7px 5px; font-size: 12px; text-align: center; }
  .app-layout { min-height: auto; }
  .side-nav { top: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-button span { font-size: 13px; }
  .workspace { padding: 16px 10px 34px; }
  .view-heading { align-items: flex-start; margin-bottom: 14px; }
  h1 { font-size: 21px; }
  .scan-progress { width: 130px; }
  .compare-layout { display: flex; flex-direction: column; }
  .monster-browser { width: 100%; }
  .action-column { width: 100%; grid-template-columns: 1fr; order: 3; }
  .monster-browser:nth-child(3) { order: 2; }
  .monster-browser:nth-child(1) { order: 1; }
  .monster-list { height: 300px; }
  .selection-preview { min-height: 128px; grid-template-columns: 88px minmax(0, 1fr); padding: 12px; }
  .preview-image-wrap { width: 88px; height: 88px; }
  .history-images, .history-meta { grid-template-columns: 1fr; }
  .history-image-card div { height: 210px; }
  .history-detail-header, .group-header { flex-direction: column; }
  .group-input-row { grid-template-columns: 1fr; }
  .group-input-row label { grid-column: auto; }
  .group-table { min-width: 650px; }
  .view-heading > .primary-button, .view-heading > .secondary-button { padding-inline: 10px; }
}
