:root {
    --primary: #6366f1;
    --primary-light: rgba(99,102,241,0.08);
    --primary-glow: rgba(99,102,241,0.25);
    --danger: #ef4444;
    --bg: #f0f2f5;
    --sidebar-bg: #ffffff;
    --sidebar-width: 380px;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --radius: 8px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
    vertical-align: -2px;
    margin-right: 5px;
    flex-shrink: 0;
}

.icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    height: 100vh;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

#sidebar-body {
    flex: 1;
    overflow-y: scroll;
    padding: 4px 0;
    scroll-behavior: smooth;
}

@supports not (overflow-y: overlay) {
    #sidebar-body {
        overflow-y: auto;
        scrollbar-gutter: stable;
    }
}

#sidebar-body::-webkit-scrollbar {
    width: 5px;
}

#sidebar-body::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

#sidebar-body::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

#sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: center;
    gap: 8px;
    background: var(--sidebar-bg);
}

.panel {
    border-bottom: 1px solid var(--border-light);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 20px;
    cursor: pointer;
    user-select: none;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition);
    position: relative;
}

.panel-header:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.panel-header.active {
    color: var(--primary);
    background: var(--primary-light);
}

.panel-header.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

.panel-arrow {
    font-size: 12px;
    transition: transform var(--transition);
    display: inline-flex;
    align-items: center;
    color: var(--text-muted);
}

.panel-header.active .panel-arrow {
    color: var(--primary);
    transform: rotate(90deg);
}

.panel-body {
    display: none;
    padding: 4px 18px 14px;
    animation: panelSlideIn 0.25s ease;
}

@keyframes panelSlideIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-body label {
    display: block;
    margin-bottom: 8px;
    font-size: 12.5px;
    color: var(--text-secondary);
    font-weight: 500;
}

.panel-body label.inline-color {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-body label.inline-color > input[type="color"] {
    width: 100px;
    height: 36px;
    margin-top: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 2px;
    flex-shrink: 0;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.form-row > label {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.form-row .checkbox-label {
    flex: 0 0 auto;
    white-space: nowrap;
    align-self: center;
    margin-top: auto;
}

.hint-text {
    font-size: 12px;
    color: var(--text-muted);
    margin: 2px 0 8px;
    line-height: 1.4;
    text-align: center;
}

.panel-body label > input[type="number"],
.panel-body label > select,
.form-row > label > input[type="number"],
.form-row > label > select {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: #fff;
    color: var(--text);
    transition: all var(--transition);
    outline: none;
}

.panel-body label > input[type="number"]:focus,
.panel-body label > select:focus,
.form-row > label > input[type="number"]:focus,
.form-row > label > select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.panel-body label > input[type="color"] {
    display: block;
    width: 100%;
    height: 36px;
    margin-top: 5px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 3px;
    transition: all var(--transition);
}

.panel-body label > input[type="color"]:hover {
    border-color: var(--primary);
}

.panel-body label > input[type="range"] {
    display: block;
    width: 100%;
    margin-top: 5px;
    accent-color: var(--primary);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.font-row {
    align-items: center;
    gap: 8px;
}

.font-row .font-select-label {
    flex: none;
}

.font-row .bold-icon-btn {
    flex-shrink: 0;
    margin-top: 22px;
}

.font-row .font-select-label > select {
    display: block;
    width: 150px;
    margin-top: 5px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: #fff;
    color: var(--text);
    transition: all var(--transition);
    outline: none;
}

.section-group {
    padding: 8px 0 8px 12px;
    border-left: 2px solid var(--border-light);
    margin-bottom: 4px;
    transition: border-color var(--transition);
}

.section-group:hover {
    border-left-color: var(--primary-glow);
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    padding-left: 4px;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.color-row .color-preset-label {
    margin-bottom: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

.color-row .color-presets {
    flex: 1;
    min-width: 0;
}

.color-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: all var(--transition);
    flex-shrink: 0;
}

.color-dot:hover {
    transform: scale(1.15);
}

.color-dot.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.color-dot[data-color="#ffffff"] {
    border-color: #d1d5db;
}

.color-dot[data-color="#ffffff"].active {
    border-color: var(--primary);
}

.bold-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    padding: 0;
}

.bold-icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.bold-icon-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.toggle-group {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.toggle-group .toggle-btn {
    flex: 1;
    padding: 7px 0;
    border: none;
    background: #fff;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.toggle-group .toggle-btn + .toggle-btn {
    border-left: 1px solid var(--border);
}

.toggle-group .toggle-btn:hover {
    background: var(--primary-light);
}

.toggle-group .toggle-btn.active {
    background: var(--primary);
    color: #fff;
}

.toggle-group .toggle-btn.active svg {
    stroke: #fff;
}

.orientation-toggle {
    margin-top: 5px;
}

.orientation-toggle .toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 12px;
}

.bg-type-toggle {
    margin-bottom: 10px;
}

.bg-fit-toggle {
    margin-bottom: 8px;
}

.bg-fit-toggle .toggle-btn {
    padding: 6px 0;
}

.input-toolbar {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

#name-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    line-height: 1.7;
    min-height: 130px;
    transition: all var(--transition);
    outline: none;
    background: #fafbfc;
}

#name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: #fff;
}

#name-input::placeholder {
    color: var(--text-muted);
}

#import-options {
    margin-top: 10px;
    padding: 12px;
    background: var(--primary-light);
    border-radius: var(--radius);
    border: 1px solid rgba(99,102,241,0.12);
}

#import-options label {
    margin-bottom: 8px;
}

.preview-box {
    margin: 10px 0;
    padding: 14px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    background: var(--border-light);
    position: relative;
}

.preview-box img {
    max-width: 100%;
    max-height: 80px;
    object-fit: contain;
}

.remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

.btn-secondary {
    padding: 11px 14px;
    background: var(--primary);
    color: #fff;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary:hover {
    background: #4f46e5;
}

.btn-secondary:active {
    transform: scale(0.97);
}

button {
    font-family: inherit;
}

#btn-import, #btn-clear-input, #btn-upload-bg, #btn-upload-logo {
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

#btn-import {
    background: var(--primary);
}

#btn-import:hover {
    background: #4f46e5;
}

#btn-clear-input {
    background: var(--danger);
}

#btn-clear-input:hover {
    background: #dc2626;
}

#btn-upload-bg, #btn-upload-logo {
    background: var(--primary);
}

#btn-upload-bg:hover, #btn-upload-logo:hover {
    background: #4f46e5;
}

#preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

#preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    gap: 16px;
    min-height: 40px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-wrap: wrap;
    line-height: 1;
}

.toolbar-left label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1;
}

.toolbar-left select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    height: 28px;
    line-height: 1;
}

.toolbar-left .toggle-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    height: 28px;
}

.toolbar-left .toggle-group .toggle-btn {
    padding: 0 8px;
    border: none;
    background: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    height: 100%;
}

.toolbar-left .toggle-group .toggle-btn.active {
    background: var(--primary);
    color: #fff;
}

.toolbar-left .toggle-group .toggle-btn + .toggle-btn {
    border-left: 1px solid var(--border);
}

.toolbar-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1;
    height: 28px;
    font-size: 13px;
    color: var(--text-secondary);
}

.toolbar-switch input {
    display: none;
}

.toolbar-switch .switch-track {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    background: #d1d5db;
    border-radius: 10px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.toolbar-switch .switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toolbar-switch input:checked + .switch-track {
    background: var(--primary);
}

.toolbar-switch input:checked + .switch-track::after {
    transform: translateX(16px);
}

.toolbar-custom-size {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    line-height: 1;
}

.toolbar-custom-size label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    line-height: 1;
}

.toolbar-custom-size input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
    height: 28px;
    line-height: 1;
}

.toolbar-right {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.toolbar-right label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

#zoom-slider {
    width: 100px;
    accent-color: var(--primary);
}

#zoom-value {
    min-width: 40px;
    font-variant-numeric: tabular-nums;
}

#preview-container {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background:
        radial-gradient(circle at 1px 1px, #e5e7eb 1px, transparent 0) 0 0 / 24px 24px;
}

.name-drag-tooltip {
    position: fixed;
    display: none;
    padding: 6px 12px;
    background: rgba(17, 24, 39, 0.85);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transform: translate(-50%, -100%) translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.preview-page {
    background: #fff;
    box-shadow: var(--shadow-lg);
    margin: 0 auto 24px;
    position: relative;
    border-radius: 2px;
}

.nameplate-half {
    position: relative;
    overflow: hidden;
}

.nameplate-name {
    text-align: center;
    word-break: break-all;
    line-height: 1.3;
}

.nameplate-sub {
    text-align: center;
    margin-top: 4px;
    word-break: break-all;
}

.nameplate-logo {
    position: absolute;
    transition: box-shadow 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
}

.nameplate-half.bottom .nameplate-logo {
    cursor: move;
}

.nameplate-half.bottom .nameplate-logo:hover {
    box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px var(--primary-glow);
}

.nameplate-half.bottom .nameplate-logo:hover .logo-resize-handle {
    opacity: 1;
}

.nameplate-half.bottom .nameplate-logo:active {
    box-shadow: 0 0 0 2px var(--primary), 0 0 8px rgba(99,102,241,0.4);
}

.logo-resize-handle {
    opacity: 0;
    transition: opacity 0.15s ease;
    background: rgba(255,255,255,0.8);
    border-radius: 0 0 0 3px;
}

.crop-mark {
    position: absolute;
    z-index: 5;
    pointer-events: none;
}

.crop-mark-h {
    height: 0;
    border-top: 1px dashed #999;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 12px 28px;
    background: var(--text);
    color: #fff;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    box-shadow: var(--shadow-lg);
    letter-spacing: 0.3px;
}

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

#print-area {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }

    #print-area,
    #print-area * {
        visibility: visible;
    }

    #print-area {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
    }

    .preview-page {
        box-shadow: none !important;
        page-break-after: always;
        margin: 0 !important;
    }

    .preview-page:last-child {
        page-break-after: auto;
    }

    .crop-mark {
        border-color: #ccc !important;
    }

    .nameplate-half,
    .nameplate-half * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
