/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Malgun Gothic', '맑은 고딕', 'Segoe UI', Roboto, sans-serif;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.6;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.app-header h1 {
    color: #2c3e50;
    font-size: 1.8rem;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
}

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

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

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-outline {
    background: transparent;
    color: #3498db;
    border: 2px solid #3498db;
}

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

/* Main Content */
.app-main {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.content-info {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.info-bar {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: #6c757d;
}

/* Editor Section */
.editor-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 500px;
}

.text-editor {
    padding: 20px;
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
}

.text-editor textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 16px;
    line-height: 1.5;
    padding: 10px;
    border-radius: 6px;
    background: #f8f9fa;
    min-height: 400px;
}

.text-content {
    flex: 1;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    min-height: 400px;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: #333;
    font-size: 16px;
    line-height: 1.5;
    overflow-y: auto;
}

.text-info {
    margin-top: 10px;
    font-size: 12px;
    color: #6c757d;
    text-align: right;
}

/* Canvas Section */
.canvas-editor {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.canvas-toolbar {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tool-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.tool-btn:hover {
    background: #e9ecef;
}

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

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

#brush-size {
    width: 80px;
}

#brush-size-display {
    font-size: 12px;
    color: #6c757d;
    min-width: 30px;
}

#drawing-canvas, #shared-canvas {
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: crosshair;
    max-width: 100%;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

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

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

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.share-info p {
    margin-bottom: 15px;
}

.share-link-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.share-link-container input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.qr-code-container {
    text-align: center;
}

.qr-code-container img {
    max-width: 200px;
    height: auto;
}

/* Loading */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#loading.hidden {
    display: none;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* View Only Styles */
.view-only .canvas-toolbar {
    display: none;
}

.view-only #shared-canvas {
    cursor: default;
}

/* Mode Tabs */
.canvas-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 10px;
}

.mode-tab {
    padding: 8px 20px;
    border: 1px solid #ddd;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-weight: 500;
}

.mode-tab:first-child {
    border-radius: 4px 0 0 4px;
}

.mode-tab:last-child {
    border-radius: 0 4px 4px 0;
    border-left: none;
}

.mode-tab:hover {
    background: #e9ecef;
}

.mode-tab.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

/* Hidden class */
.hidden {
    display: none !important;
}

/* Diagram Container */
.diagram-container {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Shape Palette */
.shape-palette {
    width: 140px;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 10px;
    flex-shrink: 0;
    max-height: 500px;
    overflow-y: auto;
}

.palette-section {
    margin-bottom: 15px;
}

.palette-section h4 {
    font-size: 11px;
    color: #666;
    margin-bottom: 8px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.palette-item {
    padding: 8px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 5px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    transition: all 0.2s;
}

.palette-item:hover {
    border-color: #3498db;
    background: #f0f7ff;
}

.palette-item:active {
    cursor: grabbing;
}

.shape-preview {
    width: 24px;
    height: 18px;
    border: 2px solid #333;
    flex-shrink: 0;
}

.rect-preview {
    background: #fff;
}

.diamond-preview {
    background: #fff;
    transform: rotate(45deg) scale(0.7);
}

.class-preview {
    background: #fff;
    position: relative;
}

.class-preview::before,
.class-preview::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: #333;
}

.class-preview::before {
    top: 33%;
}

.class-preview::after {
    top: 66%;
}

.interface-preview {
    background: #f0f0f0;
    border-style: dashed;
}

.actor-preview {
    background: #e3f2fd;
    border-radius: 2px;
}

.lifeline-preview {
    width: 2px;
    height: 18px;
    border: none;
    border-left: 2px dashed #333;
    margin-left: 11px;
}

.activation-preview {
    width: 12px;
    background: #e8e8e8;
    margin-left: 6px;
}

/* Diagram Canvas Wrapper */
.diagram-canvas-wrapper {
    flex: 1;
    position: relative;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    background: white;
    min-height: 500px;
}

.diagram-canvas-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
}

#diagram-grid-canvas,
#shared-diagram-grid-canvas {
    z-index: 1;
}

#diagram-canvas,
#shared-diagram-canvas {
    z-index: 2;
}

#diagram-interaction-canvas {
    z-index: 3;
}

/* Property Panel */
.property-panel {
    width: 180px;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 15px;
    flex-shrink: 0;
}

.property-panel h4 {
    font-size: 14px;
    color: #333;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

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

.property-group label {
    display: block;
    font-size: 11px;
    color: #666;
    margin-bottom: 4px;
    text-transform: uppercase;
    font-weight: 500;
}

.property-group input,
.property-group textarea,
.property-group select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

.property-group input:focus,
.property-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.property-group textarea {
    resize: vertical;
    min-height: 60px;
}

/* Tool Select (dropdown) */
.tool-select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    background: white;
    cursor: pointer;
}

.tool-select:focus {
    outline: none;
    border-color: #3498db;
}

/* Grid and Snap Toggles */
.grid-toggle,
.snap-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}

.grid-toggle input,
.snap-toggle input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Diagram Text Input (floating) */
.diagram-text-input {
    position: fixed;
    border: 2px solid #3498db;
    padding: 6px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    resize: none;
    z-index: 1000;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.diagram-text-input:focus {
    outline: none;
}

/* ClassBox Edit Modal */
#classbox-edit-modal .modal-body .property-group {
    margin-bottom: 16px;
}

#classbox-edit-modal .modal-body input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

#classbox-edit-modal .modal-body input[type="text"]:focus,
#classbox-edit-modal .modal-body textarea:focus {
    outline: none;
    border-color: #3498db;
}

#classbox-edit-modal .modal-body textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', monospace;
    resize: vertical;
}

#classbox-edit-modal .modal-body label {
    display: block;
    font-size: 13px;
    color: #555;
    margin-bottom: 6px;
    font-weight: 500;
}

#classbox-save-btn {
    width: 100%;
    margin-top: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .app-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .editor-section {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    .text-editor {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }

    .canvas-toolbar {
        gap: 10px;
    }

    .tool-group {
        gap: 5px;
    }

    #drawing-canvas, #shared-canvas {
        width: 100%;
        height: 300px;
    }

    .modal-content {
        margin: 20px;
        width: calc(100% - 40px);
    }

    .share-link-container {
        flex-direction: column;
    }

    /* Diagram responsive */
    .diagram-container {
        flex-direction: column;
    }

    .shape-palette {
        width: 100%;
        max-height: 150px;
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    .palette-section {
        flex: 1;
        min-width: 100px;
        margin-bottom: 0;
    }

    .property-panel {
        width: 100%;
    }

    .diagram-canvas-wrapper {
        min-height: 300px;
    }

    .canvas-mode-tabs {
        justify-content: center;
    }

    .mode-tab {
        flex: 1;
        text-align: center;
    }
}