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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f8f8;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem;
}

header {
    padding: 1rem 0;
    border-bottom: 1px solid #ddd;
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    position: relative;
    min-height: 80px;
    max-height: 300px;
    overflow: hidden;
}

h1 {
    font-size: 1.8rem;
    margin: 0;
    line-height: 1.2;
    color: #2c3e50;
    max-width: 120px;
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.grid-controls, .zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="number"] {
    width: 60px;
    padding: 0.3rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

button {
    padding: 0.4rem 0.8rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #2980b9;
}

.main-content {
    display: flex;
    flex: 1;
    gap: 1rem;
    overflow: hidden;
    padding: 1rem 0;
}

.toolbar {
    width: 220px;
    min-width: 120px;
    max-width: 400px;
    position: relative;
    padding: 1rem;
    background-color: #f5f5f5;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tool-group h3 {
    font-size: 1rem;
    color: #7f8c8d;
    margin-bottom: 0.3rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.3rem;
}

.tool-btn {
    font-size: 1.2rem;
    padding: 0.5rem;
    background-color: #f1f1f1;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 4px;
}

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

.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 1px solid #ddd;
    cursor: pointer;
}

.color-swatch.active {
    border: 2px solid #333;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5);
}

.canvas-container {
    flex: 1;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: auto;
    position: relative;
}

#grid-container {
    position: relative;
    transform-origin: 0 0;
}

#knitting-grid {
    background-color: white;
    cursor: crosshair;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.toggle-container.vertical {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.toggle-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

footer {
    padding: 0.5rem;
    font-size: 0.8rem;
    color: #666;
    text-align: center;
    border-top: 1px solid #ddd;
}

footer p {
    margin: 0;
}

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

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 300px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.close {
    float: right;
    font-size: 1.5rem;
    cursor: pointer;
}

#color-picker {
    width: 100%;
    height: 50px;
    margin: 1rem 0;
}

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .toolbar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 0.5rem;
    }
    
    .tool-group {
        min-width: 150px;
    }
}

/* Add these styles to your existing CSS file */
.layers-list {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
}

.layer-item {
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    background-color: white;
    user-select: none;  /* Prevent text selection while dragging */
}

.layer-item:hover {
    background-color: #f5f5f5;
}

.layer-item.active {
    background-color: #e3f2fd;
}

.layer-item.dragging {
    opacity: 0.5;
    background-color: #e3f2fd;
}

.layer-item.drag-over {
    border-top: 2px solid #2196F3;
}

.layer-item:last-child {
    border-bottom: none;
}

.layer-item.active {
    background-color: #e6f7ff;
    border-left: 3px solid #1890ff;
}

.layer-item .layer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-item .layer-visibility {
    margin-right: 8px;
    cursor: pointer;
    opacity: 0.7;
}

.layer-item .layer-visibility:hover {
    opacity: 1;
}

.layer-properties {
    margin-top: 10px;
}

.small-input {
    width: 40px;
}

.position-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
}

/* Add these styles for the position arrow buttons */
.position-arrows {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 10px;
    gap: 3px;
}

.position-arrows button {
    width: 32px;
    height: 32px;
    padding: 3px;
    background-color: #f1f1f1;
    border: 1px solid #ddd;
    color: #333;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.position-arrows button:hover {
    background-color: #e0e0e0;
}

.horizontal-arrows {
    display: flex;
    gap: 5px;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 1000;
    transition: transform 0.3s ease;
}

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

/* Remove position arrows styles and replace with these */
.layer-drag-info {
    display: none;
}

#layer-drag-toggle {
    padding: 8px;
    background-color: #f1f1f1;
    border: 1px solid #ddd;
    cursor: pointer;
}

#layer-drag-toggle.active {
    background-color: #e0f7fa;
    border-color: #80deea;
    color: #00838f;
}

.layer-position-display {
    font-size: 12px;
    color: #666;
    text-align: center;
    margin-top: 5px;
    min-height: 15px;
}

/* Add cursor styles for dragging */
.canvas-container.layer-drag-mode {
    cursor: move;
}

/* Add styles for the horizontal tool layout */
.top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-bottom: 0;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 15px;
}

.tool-section {
    display: flex;
    gap: 15px;
    align-items: center;
    width: auto;
}

.tool-group.horizontal {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background-color: #f5f5f5;
    padding: 10px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    height: 120px;
}

.tool-group.horizontal h3 {
    margin: 0;
    font-size: 14px;
    white-space: nowrap;
}

.tool-buttons, .mirror-buttons, .grid-size-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Add styles for stacked inputs in the grid controls */
.grid-size-controls {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex: 1;
    justify-content: space-between;
    width: auto;
}

.stacked-input {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.stacked-input label {
    font-size: 12px;
    color: #666;
}

.stacked-input input {
    width: 60px;
    padding: 5px;
}

/* Add resize handle */
.toolbar-resize-handle {
    position: absolute;
    right: -5px;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
}

.toolbar-resize-handle:hover,
.toolbar-resize-handle.active {
    background: rgba(52, 152, 219, 0.2);
}

/* Prevent text selection while resizing */
.resizing {
    user-select: none;
    -webkit-user-select: none;
}

/* Add styles for the header resize handle */
.header-resize-handle {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -5px;
    height: 10px;
    cursor: row-resize;
    background: transparent;
    transition: background 0.2s;
    z-index: 10;
}

.header-resize-handle:hover,
.header-resize-handle.active {
    background: rgba(52, 152, 219, 0.2);
}

.zoom-controls {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

/* Ensure consistent button size and alignment */
.tool-buttons, .mirror-buttons, .grid-size-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-btn, .mirror-btn, #resize-grid, .zoom-controls button {
    height: 40px; /* Set a consistent height */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 40px; /* Set a consistent width for square buttons */
    border-radius: 4px;
    background-color: #f1f1f1;
    color: #333;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: background-color 0.2s;
}

.tool-btn.active, .mirror-btn.active, #resize-grid:hover, .zoom-controls button:hover {
    background-color: #3498db;
    color: white;
}

.eraser-icon {
    position: relative;
}

.eraser-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 12px;
    background-color: #ffb6c1;
    border: 1px solid #ff69b4;
    border-radius: 2px;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.layer-controls-row {
    display: flex;
    gap: 8px;
}

.layer-controls-row button {
    flex: 1;
    padding: 6px;
    font-size: 12px;
    white-space: nowrap;
}

#merge-down {
    background-color: #4CAF50;
}

#merge-down:hover {
    background-color: #45a049;
}

#merge-down:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
} 