:root {
    --primary: #e67e22;
    --primary-hover: #d35400;
    --primary-light: #fdf3e7;
    --primary-muted: #f9e4c8;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-focus: #e67e22;
    --bg: #f1f4f9;
    --bg-subtle: #f8fafc;
    --white: #ffffff;
    --success-bg: #f0fff4;
    --success-border: #68d391;
    --success-text: #276749;
    --error-bg: #fff5f5;
    --error-border: #fc8181;
    --error-text: #c53030;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --range-percent: 0%;
}

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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

.config-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.config-form-col {
    flex: 0 0 52%;
    max-width: 52%;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--white);
    border-right: 1px solid var(--border);
}

.form-col-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
}

.header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: var(--white);
    border-radius: 10px;
    flex-shrink: 0;
}

.form-col-header h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.header-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.form-col-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 28px 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.form-col-scroll::-webkit-scrollbar {
    width: 5px;
}

.form-col-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.form-col-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.config-preview-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg);
    padding: 24px;
    overflow: hidden;
}

.form-section {
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}

.form-section:first-child {
    padding-top: 20px;
}

.form-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0;
}

.section-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.section-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: -8px 0 12px;
}

.field-group {
    margin-bottom: 12px;
}

.field-group:last-child {
    margin-bottom: 0;
}

.field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.dim-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text);
}

.dim-hint {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.78rem;
}

.field-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.88rem;
    font-family: inherit;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.field-select:focus {
    border-color: var(--border-focus);
}

.toggle-group {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    width: fit-content;
}

.btn-print {
    padding: 7px 18px;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    border: none;
    background: var(--white);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-print:first-child {
    border-right: 1px solid var(--border);
}

.btn-print:hover {
    background: var(--bg-subtle);
    color: var(--text);
}

.btn-print.active {
    background: var(--primary);
    color: var(--white);
}

.shape-options {
    display: flex;
    gap: 10px;
}

.shape-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    transition: border-color 0.15s, background 0.15s;
    background: var(--white);
}

.shape-option:hover {
    background: var(--bg-subtle);
}

.shape-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.shape-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.shape-icon {
    width: 52px;
    height: 44px;
    object-fit: contain;
    display: block;
}

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

.dimension-row {
    display: flex;
    gap: 16px;
}

.dimension-group {
    flex: 1;
    min-width: 0;
}

.dimension-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
    line-height: 1;
}

.range-wrapper {
    position: relative;
    padding-bottom: 18px;
    padding-top: 4px;
}

.range-wrapper input[type="range"] {
    width: 100%;
    height: 5px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right,
            var(--primary) 0%,
            var(--primary) var(--range-percent, 0%),
            var(--border) var(--range-percent, 0%),
            var(--border) 100%);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2.5px solid var(--white);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.range-wrapper input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2.5px solid var(--white);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.range-min,
.range-max {
    position: absolute;
    bottom: 0;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.range-min {
    left: 0;
}

.range-max {
    right: 0;
}


.refente-options {
    display: flex;
    gap: 8px;
}

.refente-option {
    flex: 1;
    cursor: pointer;
}

.refente-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.refente-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 10px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
    text-align: center;
}

.refente-card strong {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.refente-card small {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.refente-option:has(input:checked) .refente-card {
    border-color: var(--primary);
    background: var(--primary-light);
}

.refente-option:has(input:checked) .refente-card strong {
    color: var(--primary);
}

.refente-option.disabled {
    opacity: 0.38;
    pointer-events: none;
}

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

.orientation-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    background: var(--white);
    transition: border-color 0.15s, background 0.15s;
}

.orientation-option:hover {
    background: var(--bg-subtle);
}

.orientation-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.orientation-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.orientation-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    display: block;
}

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

.form-actions {
    padding: 16px 0 8px;
    margin-top: 4px;
}

.form-actions button[type="submit"] {
    width: 100%;
    padding: 13px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--white);
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    letter-spacing: 0.01em;
}

.form-actions button[type="submit"]:hover {
    background: var(--primary-hover);
}

.form-actions button[type="submit"]:active {
    transform: scale(0.99);
}

.form-actions button[type="submit"]:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.message {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    display: none;
}

.message.visible {
    display: block;
}

.message.success {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
}

.message.error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
}

.preview-panel-header {
    margin-bottom: 16px;
    flex-shrink: 0;
}

.preview-panel-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.preview-panel-header p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.preview {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    min-height: 0;
    overflow: auto;
    padding: 16px;
}

.preview-rolls {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
}

.preview-roll {
    position: relative;
    overflow: hidden;
    transform-origin: center center;
}

.preview-roll-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 0;
}

.preview-roll--count-1 {
    height: 120px;
}

.preview-roll--count-2 {
    height: 130px;
}

.preview-roll--count-3 {
    height: 165px;
}

.preview-roll--count-4 {
    height: 200px;
}

.preview-roll--count-1 .preview-label:nth-child(2) {
    top: 33%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-2 .preview-label:nth-child(2) {
    top: 15%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-2 .preview-label:nth-child(3) {
    top: 55%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-3 .preview-label:nth-child(2) {
    top: 15%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-3 .preview-label:nth-child(3) {
    top: 38%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-3 .preview-label:nth-child(4) {
    top: 60%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-4 .preview-label:nth-child(2) {
    top: 18%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-4 .preview-label:nth-child(3) {
    top: 33.8%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-4 .preview-label:nth-child(4) {
    top: 49.6%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-roll--count-4 .preview-label:nth-child(5) {
    top: 64.9%;
    left: 68%;
    transform: translate(-50%, -50%);
}

.preview-label {
    position: absolute;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    box-sizing: border-box;
}

.preview-shape {
    display: block;
    pointer-events: none;
    z-index: 0;
    max-height: 190.4px !important;
}

.preview-label-letter {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    pointer-events: none;
    z-index: 1;
}

.preview-label--monochrome .preview-shape {
    filter: grayscale(100%);
}

@media (max-width: 900px) {

    html,
    body {
        overflow: auto;
        height: auto;
    }

    .config-layout {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .config-form-col {
        flex: none;
        max-width: 100%;
        height: auto;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .form-col-scroll {
        overflow: visible;
        height: auto;
    }

    .config-preview-col {
        height: auto;
        min-height: 400px;
    }

    .refente-options {
        flex-wrap: wrap;
    }

    .refente-option {
        flex: 1 1 calc(50% - 4px);
    }

    .dimension-row {
        flex-direction: column;
    }
}