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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: grid;
    grid-template-areas:
        "toolbar toolbar"
        "main sidebar";
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr 280px;
    height: 100vh;
}

/* Toolbar */
.toolbar {
    grid-area: toolbar;
    background: white;
    border-bottom: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.toolbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 60px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.toolbar h1 {
    font-size: 20px;
    color: #333;
    margin: 0;
}

.settings-toggle {
    background: #f8f9fa !important;
    border: 1px solid #dee2e6 !important;
    color: #495057 !important;
    font-size: 14px !important;
    padding: 8px 12px !important;
}

.settings-toggle:hover {
    background: #e9ecef !important;
}

.settings-toggle.active {
    background: #007AFF !important;
    color: white !important;
    border-color: #007AFF !important;
}

.settings-panel {
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    padding: 15px 20px;
    display: none;
}

.settings-panel.show {
    display: block;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

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

.settings-group h4 {
    font-size: 14px;
    color: #495057;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.settings-row label {
    font-size: 12px;
    color: #6c757d;
    min-width: 80px;
}

.settings-row input[type="range"] {
    flex: 1;
    min-width: 100px;
}

.settings-row span {
    font-size: 12px;
    color: #6c757d;
    min-width: 50px;
}

.diagram-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.mode-controls {
    display: flex;
    gap: 5px;
}

.category-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "toolbar"
            "main";
    }

    .toolbar-main {
        padding: 0 10px;
        flex-wrap: wrap;
        gap: 10px;
        min-height: 60px;
        height: auto;
    }

    .toolbar-left {
        gap: 10px;
        flex-wrap: wrap;
    }

    .toolbar-right {
        gap: 10px;
        flex-wrap: wrap;
    }

    .diagram-controls {
        gap: 5px;
        flex-wrap: wrap;
    }

    .mode-controls {
        gap: 3px;
    }

    .user-controls {
        gap: 5px;
        flex-wrap: wrap;
    }

    .settings-panel {
        padding: 10px;
    }

    .settings-group {
        margin-bottom: 15px;
    }

    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .settings-row label {
        min-width: auto;
    }

    .settings-row input[type="range"] {
        width: 100%;
        min-width: auto;
    }

    button {
        padding: 6px 12px;
        font-size: 11px;
    }

    select {
        padding: 4px 8px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .toolbar h1 {
        font-size: 16px;
    }

    .toolbar-main {
        flex-direction: column;
        align-items: stretch;
        height: auto;
        padding: 10px;
        gap: 10px;
    }

    .toolbar-left, .toolbar-right {
        justify-content: center;
    }

    .diagram-controls, .mode-controls, .user-controls {
        justify-content: center;
        flex-wrap: wrap;
    }
}

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

button:hover {
    background: #f0f0f0;
}

button.active {
    background: #007AFF;
    color: white;
    border-color: #007AFF;
}

select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 12px;
}

/* Main Graph Area */
.graph-container {
    grid-area: main;
    background: white;
    position: relative;
    overflow: hidden;
}

#graph-svg {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

#graph-svg.select-mode {
    cursor: grab;
}

#graph-svg.select-mode:active {
    cursor: grabbing;
}

#graph-svg.connect-mode {
    cursor: crosshair;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 100;
    align-items: center;
}

.zoom-controls button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.zoom-controls button:hover {
    background: #f0f0f0;
}

#zoom-reset {
    width: auto;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: normal;
}

#zoom-level {
    font-size: 12px;
    color: #666;
    background: white;
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: #f8f9fa;
    border-left: 1px solid #ddd;
    overflow-y: auto;
    padding: 20px;
}

.panel {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid #e9ecef;
}

.panel h3 {
    font-size: 14px;
    color: #333;
    margin-bottom: 12px;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.properties-panel {
    min-height: 100px;
    font-size: 13px;
    color: #666;
}

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

.property-group label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

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

/* Legend */
.legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #333;
}

.legend-color.default {
    background-color: #6c757d;
}

.legend-color.important {
    background-color: #dc3545;
}

.legend-color.process {
    background-color: #007bff;
}

.legend-color.data {
    background-color: #28a745;
}

/* Graph Elements */
.node {
    cursor: pointer;
    stroke-width: 2px;
}

.node:hover {
    stroke-width: 3px;
    filter: brightness(1.1);
}

.node.selected {
    stroke-width: 4px;
    stroke: #ffc107;
}

.node.connecting {
    stroke: #007AFF;
    stroke-width: 4px;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.node-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    fill: white;
    font-weight: 600;
    paint-order: stroke fill;
    stroke: rgba(0, 0, 0, 0.8);
    stroke-width: 2px;
    stroke-linejoin: round;
}

.node-label tspan {
    text-anchor: middle;
    dominant-baseline: central;
}

.link {
    stroke: #999;
    stroke-width: 2px;
    fill: none;
    cursor: pointer;
    /* Add invisible wider stroke for easier clicking */
    stroke-linecap: round;
}

.link.directed {
    marker-end: url(#arrowhead);
}

.link:hover {
    stroke: #666;
    stroke-width: 4px;
}

.link.selected {
    stroke: #ffc107;
    stroke-width: 4px;
}

/* Invisible wider stroke for better click detection */
.link-hitarea {
    stroke: transparent;
    stroke-width: 12px;
    fill: none;
    cursor: pointer;
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 120px;
}

.context-menu.hidden {
    display: none;
}

.menu-item {
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

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

.menu-item:hover {
    background: #f0f0f0;
}

/* Share Modal Specific Styles */
.share-url-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.share-url-container input {
    flex: 1;
    font-family: monospace;
    font-size: 12px;
}

.help-text {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

/* User Controls */
.user-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#user-info {
    color: #333;
    font-size: 14px;
}

/* Form Improvements */
.form-group small {
    display: block;
    font-size: 11px;
    color: #666;
    margin-top: 2px;
}

.form-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Help Modal Styles */
.help-modal-content {
    max-width: 800px;
    width: 90vw;
    max-height: 80vh;
}

.help-modal-body {
    display: flex;
    gap: 0;
    padding: 0;
    max-height: 60vh;
}

.help-navigation {
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    min-width: 200px;
    padding: 0;
}

.help-nav-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    font-size: 14px;
    color: #495057;
    transition: background-color 0.2s;
}

.help-nav-btn:hover {
    background: #e9ecef;
}

.help-nav-btn.active {
    background: #007bff;
    color: white;
}

.help-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.help-section {
    display: none;
}

.help-section.active {
    display: block;
}

.help-section h4 {
    margin: 0 0 20px 0;
    color: #333;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
}

.help-section h5 {
    margin: 20px 0 10px 0;
    color: #495057;
    font-size: 16px;
}

.help-section ul, .help-section ol {
    margin: 0 0 20px 20px;
    line-height: 1.6;
}

.help-section li {
    margin-bottom: 8px;
}

.help-section p {
    margin: 5px 0;
    color: #666;
    font-size: 14px;
}

.shortcuts-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}

.shortcuts-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #dee2e6;
    vertical-align: top;
}

.shortcuts-table td:first-child {
    width: 200px;
    font-weight: bold;
}

kbd {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 12px;
    color: #495057;
}

/* Temporary connection line */
.temp-line {
    stroke: #007AFF;
    stroke-width: 2px;
    stroke-dasharray: 5,5;
    fill: none;
    pointer-events: none;
}

/* Modal Styles */
.modal {
    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: 2000;
}

.modal.hidden {
    display: none;
}

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

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

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.modal-header button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: #333;
}

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

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

.form-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.add-category {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.add-category input[type="text"] {
    flex: 1;
}

.add-category input[type="color"] {
    width: 40px;
    height: 32px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

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

.category-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-color-box {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.category-actions {
    display: flex;
    gap: 5px;
    align-items: center;
}

.category-actions button {
    padding: 4px 8px;
    font-size: 11px;
}

.category-actions input[type="color"] {
    width: 32px;
    height: 24px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr 240px;
    }
    
    .toolbar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 15px;
    }
    
    .toolbar-section {
        gap: 10px;
    }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-areas: 
            "toolbar"
            "main";
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    
    .sidebar {
        display: none;
    }
    
    .toolbar {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .toolbar-section {
        justify-content: center;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
}