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

body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
}

.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 320px;
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    margin: 0;
    color: #495057;
    font-size: 1.1em;
}

.new-sheet-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
}

.new-sheet-btn:hover {
    background: #218838;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

.header-left {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-left .logo {
    display: flex;
    align-items: center;
    color: white;
}

.header-center {
    flex: 2;
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.app-menu {
    display: flex;
    gap: 15px;
}

.app-menu a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-size: 0.9em;
}

.app-menu a:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.app-menu a.active {
    background: #3498db;
    color: white;
    font-weight: 500;
}

.header-center h1 {
    margin: 0;
    font-size: 1.5em;
}

.navigation-header {
    background: #34495e;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
}

.nav-links {
    display: flex;
    gap: 15px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.nav-links a:hover {
    background: rgba(255,255,255,0.2);
}

.nav-links a.active {
    background: #3498db;
}

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

.logo svg {
    flex-shrink: 0;
}

.save-load-group {
    border-top: 1px solid #ddd;
    padding-top: 10px;
    margin-top: 10px;
}

.save-load-group button {
    background: #27ae60;
    color: white;
}

.save-load-group button:hover {
    background: #219a52;
}

.save-load-group button:nth-child(3) {
    background: #f39c12;
}

.save-load-group button:nth-child(3):hover {
    background: #e67e22;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 20px;
    border: 1px solid #888;
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.modal-header h2 {
    margin: 0;
    color: #2c3e50;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.saved-sheet-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f9f9f9;
}

.saved-sheet-info {
    flex: 1;
}

.saved-sheet-name {
    font-weight: bold;
    color: #2c3e50;
}

.saved-sheet-details {
    font-size: 0.9em;
    color: #666;
    margin-top: 5px;
}

.saved-sheet-actions {
    display: flex;
    gap: 10px;
}

.saved-sheet-actions button {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

.load-btn {
    background: #3498db;
    color: white;
}

.load-btn:hover {
    background: #2980b9;
}

.delete-btn {
    background: #e74c3c;
    color: white;
}

.delete-btn:hover {
    background: #c0392b;
}

.no-saved-sheets {
    text-align: center;
    color: #666;
    padding: 20px;
    font-style: italic;
}

/* Sidebar saved sheet items */
.sidebar-sheet-item {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-sheet-item:hover {
    border-color: #007bff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sidebar-sheet-item.active {
    border-color: #007bff;
    background: #e3f2fd;
}

.sidebar-sheet-name {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95em;
    margin-bottom: 4px;
}

.sidebar-sheet-details {
    font-size: 0.8em;
    color: #6c757d;
    margin-bottom: 6px;
}

.sidebar-sheet-preview {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 6px;
    font-size: 0.75em;
    color: #495057;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
}

.sidebar-sheet-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.sidebar-sheet-actions button {
    flex: 1;
    padding: 4px 8px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
    font-weight: 500;
}

.sidebar-rename-btn {
    background: #ffc107;
    color: #212529;
}

.sidebar-rename-btn:hover {
    background: #e0a800;
}

.sidebar-delete-btn {
    background: #dc3545;
    color: white;
}

.sidebar-delete-btn:hover {
    background: #c82333;
}

.no-saved-sheets-sidebar {
    text-align: center;
    color: #6c757d;
    padding: 20px;
    font-style: italic;
    font-size: 0.9em;
}

h1 {
    margin: 0;
}

.template-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.template-selector label {
    font-weight: bold;
}

.template-selector select {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: white;
    color: #2c3e50;
}

.instructions {
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
}

.instructions details {
    margin: 0;
}

.instructions summary {
    font-size: 18px;
    font-weight: bold;
    color: #2c3e50;
    cursor: pointer;
    padding: 8px 0;
    user-select: none;
    list-style: none;
    position: relative;
}

.instructions summary::-webkit-details-marker {
    display: none;
}

.instructions summary::before {
    content: "▶";
    display: inline-block;
    width: 16px;
    margin-right: 8px;
    transition: transform 0.2s ease;
}

.instructions details[open] summary::before {
    transform: rotate(90deg);
}

.instructions summary:hover {
    color: #007aff;
}

.instruction-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.instruction-column h3 {
    margin: 0 0 10px 0;
    color: #34495e;
    font-size: 14px;
}

.instruction-column ul {
    margin: 0;
    padding-left: 20px;
}

.instruction-column li {
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.4;
}

.instruction-column strong {
    color: #2c3e50;
}

.controls {
    padding: 10px 20px;
    background: #ecf0f1;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.control-section label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9em;
    white-space: nowrap;
}

.control-section input[type="range"] {
    width: 80px;
    margin: 0 5px;
}

.control-section select {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 0.85em;
}

.control-section span {
    font-size: 0.85em;
    color: #666;
    min-width: 30px;
}

/* Compact buttons */
.btn-sm {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-green { background: #27ae60; color: white; }
.btn-green:hover { background: #219a52; }

.btn-blue { background: #3498db; color: white; }
.btn-blue:hover { background: #2980b9; }

.btn-orange { background: #f39c12; color: white; }
.btn-orange:hover { background: #e67e22; }

.btn-red { background: #e74c3c; color: white; }
.btn-red:hover { background: #c0392b; }

.btn-purple { background: #9b59b6; color: white; }
.btn-purple:hover { background: #8e44ad; }

.btn-gray { background: #95a5a6; color: white; }
.btn-gray:hover { background: #7f8c8d; }

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.input-group label {
    font-weight: bold;
    color: #2c3e50;
}

.input-group input, .input-group select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.input-group input[type="range"] {
    width: 100px;
}

.button-group {
    display: flex;
    gap: 10px;
}

.button-group button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s;
}

#fillAll {
    background: #27ae60;
    color: white;
}

#fillAll:hover {
    background: #219a52;
}

#clearAll {
    background: #e74c3c;
    color: white;
}

#clearAll:hover {
    background: #c0392b;
}

#printLabels {
    background: #3498db;
    color: white;
}

#printLabels:hover {
    background: #2980b9;
}

#editSelected {
    background: #9b59b6;
    color: white;
}

#editSelected:hover {
    background: #8e44ad;
}

.scrollable-area {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.label-container {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
}

.row-numbers {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 0;
    min-width: 40px;
}

.row-number {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #2c3e50;
    font-size: 12px;
    background: #f8f9fa;
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 2px;
    min-width: 30px;
    text-align: center;
}

.label-sheet {
    background: white;
    position: relative;
    width: 8.5in;
    height: 11in;
    margin: 0;
}

/* All templates use absolute positioning for precise label placement */

.label {
    border: 1px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2px;
    font-size: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
    overflow: hidden;
    word-wrap: break-word;
    hyphens: auto;
    user-select: none;
    position: absolute;
}

.label:hover {
    background-color: #f8f9fa;
}

.label.editing {
    background-color: #e3f2fd;
}

.label.selected {
    background-color: #007aff;
    border-color: #007aff;
    color: white;
}

.selection-marquee {
    position: absolute;
    border: 1px solid #007aff;
    background-color: rgba(0, 122, 255, 0.1);
    pointer-events: none;
    z-index: 1000;
}

.label.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    z-index: 100;
}

.label.drop-target {
    background-color: #e8f5e8;
    border-color: #28a745;
    border-width: 2px;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.3);
}

.drag-preview {
    background: #007aff;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

footer {
    background: #2c3e50;
    color: white;
    text-align: center;
    padding: 15px;
    margin-top: 20px;
}

footer p {
    margin: 0;
    font-size: 14px;
    font-weight: bold;
}

/* Edit Dialog Styles */
.edit-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.edit-dialog-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.edit-dialog h3 {
    margin: 0 0 20px 0;
    color: #2c3e50;
    font-size: 18px;
}

.edit-options {
    margin-bottom: 20px;
}

.edit-options label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    cursor: pointer;
}

.edit-options input[type="radio"] {
    margin-right: 8px;
}

.edit-dialog textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 20px;
}

.edit-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.edit-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s;
}

#applyEdit {
    background: #27ae60;
    color: white;
}

#applyEdit:hover {
    background: #219a52;
}

#cancelEdit {
    background: #95a5a6;
    color: white;
}

#cancelEdit:hover {
    background: #7f8c8d;
}

.label input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: inherit;
    font-family: inherit;
    outline: none;
    padding: 0;
    margin: 0;
}

@media print {
    @page {
        size: 8.5in 11in;
        margin: 0;
    }
    
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        width: 8.5in !important;
        height: 11in !important;
        overflow: hidden !important;
    }
    
    .container {
        margin: 0 !important;
        padding: 0 !important;
        width: 8.5in !important;
        height: 11in !important;
        background: white !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    
    header, .controls, .instructions, footer, .selection-marquee, .drag-preview, .row-numbers, .edit-dialog, .sidebar, .navigation-header {
        display: none !important;
    }
    
    .app-layout {
        display: block !important;
    }
    
    .main-content {
        display: block !important;
    }
    
    .scrollable-area {
        overflow: visible !important;
    }

    .label-container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        gap: 0 !important;
    }

    .label-sheet {
        margin: 0 !important;
        padding: 0 !important;
        width: 8.5in !important;
        height: 11in !important;
        background: white !important;
        position: relative !important;
    }
    
    .label {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        outline: none !important;
        color: black !important;
    }
    
    .label.selected {
        background: transparent !important;
        border: none !important;
        color: black !important;
    }
    
    .label.editing {
        background: transparent !important;
        border: none !important;
    }
    
    .label.dragging, .label.drop-target {
        background: transparent !important;
        border: none !important;
        opacity: 1 !important;
        transform: none !important;
        box-shadow: none !important;
    }
}