:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --input-bg: #f8fafc;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 16px;
    --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --bg: #0f172a;
    --card-bg: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    width: 100%;
    max-width: 1400px;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    height: 100vh;
    max-height: 900px;
}

@media (min-width: 1024px) {
    .container {
        grid-template-columns: 420px 1fr;
        align-items: start;
    }
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
    overflow-y: auto;
    border: 1px solid var(--border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.025em;
}

.version-badge {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text);
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background-color: var(--input-bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--input-bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    transition: all 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.hint.error {
    color: #ef4444;
    font-weight: 500;
}

.overlay-box {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--input-bg);
    transition: border-color 0.2s ease;
}

.overlay-thumb {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 8px;
    background: white;
    border: 1px solid var(--border);
    padding: 4px;
}

input[type="file"] {
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 0;
}

input[type="file"]::file-selector-button {
    margin-right: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

input[type="file"]::file-selector-button:hover {
    background: var(--bg);
    border-color: var(--text-secondary);
}

.preview-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
}

.preview-area {
    flex: 1;
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: relative;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.preview-area::-webkit-scrollbar {
    width: 8px;
}

.preview-area::-webkit-scrollbar-track {
    background: transparent;
}

.preview-area::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 4px;
}

#barcodeList {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.spinner {
    display: none;
    width: 70px;
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.spinner > div {
    width: 12px;
    height: 12px;
    background-color: var(--primary);
    border-radius: 100%;
    display: inline-block;
    animation: sk-bouncedelay 1.4s infinite ease-in-out both;
    margin: 0 3px;
}

.spinner .bounce1 {
    animation-delay: -0.32s;
}

.spinner .bounce2 {
    animation-delay: -0.16s;
}

@keyframes sk-bouncedelay {
    0%, 80%, 100% { 
        transform: scale(0);
    } 40% { 
        transform: scale(1.0);
    }
}

.barcode-card {
    background: white;
    border: none;
    border-radius: 12px;
    padding: 0;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

[data-theme="dark"] .barcode-card {
    background: #ffffff; /* Barcodes usually need white bg */
}

.barcode-card img {
    width: 100%;
    height: auto;
    display: block;
    padding: 0;
}

.barcode-actions {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: inherit;
}

.barcode-card:hover .barcode-actions {
    opacity: 1;
}

.barcode-label {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
    text-align: center;
    margin: 0;
}

.barcode-actions .mini-btn {
    background: white;
    border: none;
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}

.barcode-actions .mini-btn:hover {
    transform: scale(1.1);
    background: white;
    color: var(--primary-hover);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    width: 100%;
    gap: 0.5rem;
}

.btn-auto {
    width: auto;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--input-bg);
    border-color: var(--text-secondary);
}

.mini-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.mini-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.btn-icon-danger {
    background: transparent;
    border: 1px solid transparent;
    color: #ef4444;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.btn-icon-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-group {
    display: flex;
    gap: 4px;
    background: var(--input-bg);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.btn-icon-toggle {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-toggle:hover {
    color: var(--text);
}

.btn-icon-toggle.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

#rotateBtn {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px; /* Match btn-icon-toggle padding */
    height: 42px; /* Match height of btn-group (approx) */
    width: 42px;
}

#rotateBtn:hover {
    border-color: var(--text-secondary);
}

#rotateBtn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.position-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

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