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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    background: #f5f5f5;
    color: #333;
    min-height: 100vh;
}

.app {
    max-width: 1340px;
    margin: 0 auto;
    padding: 16px;
}

/* Header */
.app-header {
    padding: 12px 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-help {
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: #111;
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-badge {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: #e5e7eb;
    padding: 2px 7px;
    border-radius: 10px;
}

/* Settings Panel */
.settings-panel {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 12px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.setting-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.color-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

input[type="color"] {
    width: 40px;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    padding: 2px;
    background: #fff;
}

.slider-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="range"] {
    width: 120px;
    accent-color: #2563eb;
}

#thresholdVal {
    min-width: 24px;
    font-weight: 600;
    color: #333;
}

.padding-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

input[type="number"] {
    width: 60px;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0 8px;
    font-size: 14px;
}

.setting-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    align-items: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    height: 32px;
    padding: 0 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:not(:disabled):hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #e5e7eb;
    color: #333;
}

.btn-secondary:not(:disabled):hover {
    background: #d1d5db;
}

.btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    color: #555;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.btn-icon:hover {
    background: #e5e7eb;
}

.btn-icon.active {
    background: #dbeafe;
    color: #2563eb;
    border-color: #93c5fd;
}

.color-input-group.transparent-mode #bgColor,
.color-input-group.transparent-mode #eyedropperBtn {
    opacity: 0.3;
    pointer-events: none;
}

/* Dropzone */
.dropzone {
    border: 2px dashed #bdb76b;
    border-radius: 8px;
    background: #fff;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    margin-bottom: 12px;
    padding: 10px;
}

.dropzone.drag-over {
    border-color: #2563eb;
    background: #eff6ff;
}

.dropzone-inner {
    text-align: center;
    color: #9ca3af;
}

.dropzone-inner svg,
.dropzone-inner p {
    pointer-events: none;
}

.dropzone-inner button {
    pointer-events: auto;
}

.dropzone-inner svg {
    margin-bottom: 10px;
    opacity: 0.5;
}

.dropzone-inner p {
    font-size: 15px;
    margin-bottom: 4px;
}

.dropzone-hint {
    font-size: 12px !important;
    color: #c4c4c4;
}

.select-menu-wrap {
    position: relative;
    display: inline-block;
}

.select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    min-width: 140px;
    z-index: 10;
    overflow: hidden;
}

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

.select-menu-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    text-align: left;
    font-size: 13px;
    background: none;
    border: none;
    cursor: pointer;
    color: #333;
}

.select-menu-item:hover {
    background: #f3f4f6;
}

/* Eyedropper modal */
.ed-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ed-modal.hidden {
    display: none;
}

.ed-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.ed-dialog {
    position: relative;
    z-index: 1;
    background: #fff;
    border-radius: 12px;
    width: min(740px, 95vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.ed-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.ed-title {
    font-size: 15px;
    font-weight: 600;
    color: #111;
}

.ed-close-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #6b7280;
    padding: 4px 8px;
    border-radius: 4px;
}

.ed-close-btn:hover {
    background: #f3f4f6;
    color: #111;
}

.ed-body {
    display: flex;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.ed-image-area {
    position: relative;
    flex: 1;
    min-width: 0;
    background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 0 / 12px 12px;
    border-radius: 6px;
    overflow: hidden;
    cursor: crosshair;
    display: flex;
    align-items: center;
    justify-content: center;
}

#eyedropperCanvas {
    display: block;
    max-width: 100%;
    max-height: 500px;
}

#eyedropperLoupeCanvas {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.7);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
    display: none;
    transform: translate(-50%, -50%);
}

.ed-sidebar {
    width: 140px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    overflow: hidden;
}

.ed-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.ed-swatch {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    flex-shrink: 0;
    background: #fff;
}

.ed-hex {
    font-size: 12px;
    font-family: monospace;
    color: #374151;
    word-break: break-all;
}

.ed-hint {
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.5;
}

.ed-thumblist {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
}

.ed-thumb-btn {
    width: 100%;
    flex-shrink: 0;
    padding: 3px;
    border: 2px solid #e5e7eb;
    border-radius: 5px;
    background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 0 / 8px 8px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s;
}

.ed-thumb-btn:hover {
    border-color: #93c5fd;
}

.ed-thumb-btn.active {
    border-color: #2563eb;
}

.ed-thumb-btn img {
    width: 100%;
    height: 80px;
    object-fit: contain;
    display: block;
}

.ed-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

/* Results */
.results-section {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: visible;
}

.results-header {
    padding: 10px 16px;
    border-bottom: 1px solid #e0e0e0;
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.results-header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

.check-all-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
}

.check-all-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: #2563eb;
    cursor: pointer;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f9fafb;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
}

.results-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.results-table td:nth-child(n+2) {
    text-align: center;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table tr:hover td {
    background: #fafafa;
}

.file-name {
    font-size: 13px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Thumbnail */
.thumb-cell {
    width: 120px;
}

.thumb-cell-320 {
    width: 172px;
}

.thumb-cell-224 {
    width: 124px;
}

.thumb-wrapper {
    width: 110px;
    height: 80px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 0 / 12px 12px;
    position: relative;
    cursor: crosshair;
}

.thumb-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.thumb-wrapper-320 {
    width: 160px;
    height: 80px;
}

.thumb-wrapper-224 {
    width: 112px;
    height: 80px;
}

.thumb-wrapper canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Size fit icon (320 = grey overflow, 224 = cyan fit) */
.size-fit-icon {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1.4;
}

.size-fit-icon.overflow {
    background: #d1d5db;
    color: #6b7280;
}

.size-fit-icon.fit {
    background: #ffedd5;
    color: #c2410c;
}

/* Zoom level select */
.zoom-group select {
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0 8px;
    font-size: 14px;
    background: #fff;
    cursor: pointer;
}

/* Hover popup */
.thumb-wrapper .thumb-popup {
    display: none;
    position: fixed;
    z-index: 100;
    pointer-events: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 0 / 12px 12px;
    padding: 4px;
    overflow: hidden;
}

.thumb-wrapper:hover .thumb-popup {
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-popup img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.thumb-wrapper.processing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
}

.size-info {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.status-badge.pending {
    background: #f3f4f6;
    color: #6b7280;
}

.status-badge.done {
    background: #dcfce7;
    color: #16a34a;
}

.status-badge.error {
    background: #fee2e2;
    color: #dc2626;
}

/* DL cell */
.dl-cell {
    text-align: center;
    width: 70px;
}

.dl-wrap {
    position: relative;
    display: inline-block;
}

.dl-btn {
    padding: 0 10px;
    height: 28px;
    font-size: 12px;
    white-space: nowrap;
}

.dl-menu {
    position: absolute;
    top: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    min-width: 90px;
    z-index: 50;
    overflow: hidden;
}

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

.dl-menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    font-size: 13px;
    background: none;
    border: none;
    cursor: pointer;
    color: #333;
}

.dl-menu-item:hover {
    background: #f3f4f6;
}

/* Checkbox cell */
.check-cell {
    text-align: center;
    width: 60px;
}

.check-cell input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #2563eb;
    cursor: pointer;
}

.check-cell input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.3;
}

/* Help modal */
.help-modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-modal.hidden {
    display: none;
}

.help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.help-dialog {
    position: relative;
    z-index: 1;
    background: #fff;
    border-radius: 12px;
    width: min(720px, 92vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.help-title {
    font-size: 16px;
    font-weight: 700;
    color: #111;
    margin: 0;
}

.help-close-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #6b7280;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 4px;
}

.help-close-btn:hover {
    background: #f3f4f6;
    color: #111;
}

.help-body {
    padding: 24px 32px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Markdown body styles */
.markdown-body h1 {
    font-size: 20px;
    font-weight: 700;
    color: #111;
    margin: 0 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.markdown-body h2 {
    font-size: 16px;
    font-weight: 700;
    color: #111;
    margin: 24px 0 10px;
}

.markdown-body h3 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin: 18px 0 8px;
}

.markdown-body p {
    margin: 8px 0;
    line-height: 1.7;
    color: #374151;
}

.markdown-body ul,
.markdown-body ol {
    margin: 8px 0;
    padding-left: 24px;
}

.markdown-body li {
    margin: 4px 0;
    line-height: 1.7;
    color: #374151;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 20px 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.markdown-body th {
    text-align: left;
    padding: 8px 12px;
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
    border: 1px solid #e5e7eb;
}

.markdown-body td {
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    color: #374151;
}

.markdown-body strong {
    font-weight: 600;
    color: #111;
}

.markdown-body code {
    background: #f3f4f6;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.markdown-body blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 3px solid #d1d5db;
    color: #6b7280;
    background: #f9fafb;
    border-radius: 0 4px 4px 0;
}

/* Snackbar */
.snackbar {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #dc2626;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 520px;
    word-break: break-all;
}

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

.snackbar-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    position: absolute;
    top: 6px;
    right: 8px;
    line-height: 1;
    opacity: 0.8;
}

.snackbar-close:hover {
    opacity: 1;
}

/* Downloaded row */
.results-table tr.downloaded td {
    background-color: #e8e8e8;
}
