:root {
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --node-bg: #fff;
    --border-color: #dee2e6;
    --accent: #0d6efd;
    --accent-hover: #0b5ed7;
    --success: #198754;
    --success-hover: #157347;
    --danger: #dc3545;
    --danger-hover: #bb2d3b;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    --card-shadow-hover: 0 4px 8px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.08);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    line-height: 1.6;
    overflow: hidden;
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
    }
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 100;
}

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

header h1 { 
    margin: 0; 
    font-size: 1.5rem; 
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-tabs {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    cursor: pointer;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 14px;
    box-shadow: none;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: none;
    box-shadow: none;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    font-weight: 600;
}

.header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.gemini-api-key-container {
    display: flex;
    align-items: center;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

#gemini-api-key-input-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

#gemini-api-key-input-section input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#gemini-api-key-input-section input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.15);
}

#gemini-model-selector select {
    transition: all 0.2s;
}

#gemini-model-selector select:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.15);
}

#gemini-model-selector select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.2);
}

#gemini-model-selector select option {
    background: #667eea;
    color: white;
}

#container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left Sidebar for Saved Plans and AI Analysis */
#left-sidebar {
    width: 280px;
    min-width: 200px;
    max-width: 1000px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

#left-sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s;
}

#left-sidebar-resize-handle:hover {
    background: rgba(13, 110, 253, 0.2);
}

#left-sidebar-resize-handle:hover::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: var(--accent);
    border-radius: 2px;
}

#left-sidebar-resize-handle:active {
    background: rgba(13, 110, 253, 0.3);
}

.tab-content {
    display: none;
    flex-direction: column;
    gap: 15px;
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.tab-content.active {
    display: flex;
}

.tab-content h2 {
    margin: 0 0 15px 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #495057;
    border-bottom: 3px solid var(--accent);
    padding-bottom: 10px;
}

.saved-plan-item {
    padding: 14px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: var(--card-shadow);
}

.saved-plan-item:hover {
    background: #f8f9fa;
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.saved-plan-item.active {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.saved-plan-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: #212529;
}

.saved-plan-meta {
    font-size: 0.8rem;
    color: #6c757d;
    font-weight: 500;
}

.saved-plan-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    max-width: 24px;
    max-height: 24px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    transition: all 0.2s;
    font-weight: bold;
    line-height: 1;
    box-sizing: border-box;
    flex-shrink: 0;
}

.saved-plan-delete:hover {
    background: var(--danger-hover);
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.4);
}

#saved-plans-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    text-align: center;
    color: #adb5bd;
    font-size: 0.9rem;
    padding: 40px 20px;
    font-style: italic;
}

/* Graph Area */
#graph-pane {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: white;
}

/* Input section in summary pane */
#input-pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
    padding-top: 24px;
    border-top: 2px solid var(--border-color);
}

textarea {
    width: 100%;
    height: 150px;
    min-height: 100px;
    max-height: 250px;
    resize: vertical;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 13px;
    box-sizing: border-box;
    transition: all 0.2s;
    background: white;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

#input-pane label {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 8px;
    display: block;
    font-weight: 500;
}

button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 600;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.2);
}

button:hover { 
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.3);
}

button:active {
    transform: translateY(0);
}

button.copy-btn {
    background: var(--success);
    padding: 8px 16px;
    font-size: 13px;
    box-shadow: 0 2px 4px rgba(25, 135, 84, 0.2);
}

button.copy-btn:hover { 
    background: var(--success-hover);
    box-shadow: 0 4px 8px rgba(25, 135, 84, 0.3);
}

button.copy-btn.copied {
    background: var(--success-hover);
}

/* Summary Panel */
#summary-pane {
    width: 320px;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    box-shadow: -2px 0 8px rgba(0,0,0,0.05);
}

#summary-pane h2 {
    margin: 0 0 15px 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #495057;
    border-bottom: 3px solid var(--accent);
    padding-bottom: 10px;
}

.summary-item {
    padding: 16px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    margin-bottom: 15px;
}

.summary-item label {
    display: block;
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 8px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

svg {
    width: 100%;
    height: 100%;
    display: block;
}

#svg-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* D3/Dagre Styling - Enhanced */
.node rect {
    stroke: #4a5568;
    fill: #ffffff;
    stroke-width: 2px;
    rx: 8px;
    ry: 8px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    transition: all 0.2s ease;
}

.node rect:hover {
    stroke-width: 3px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
    transform: translateY(-1px);
}

.node text {
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
    fill: #2d3748;
    pointer-events: none;
}

/* Edge/Arrow Styling */
.edgePath path {
    stroke: #718096;
    stroke-width: 2.5px;
    fill: none;
    marker-end: url(#arrowhead);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
    transition: stroke-width 0.2s ease;
}

.edgePath path:hover {
    stroke: #4a5568;
    stroke-width: 3px;
}

.edgeLabel {
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    color: #4a5568;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Arrow marker definition */
.marker {
    fill: #718096;
    stroke: #718096;
}

.marker:hover {
    fill: #4a5568;
    stroke: #4a5568;
}

/* Tooltip */
#tooltip {
    position: absolute;
    opacity: 0;
    background: white;
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 8px;
    pointer-events: none;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.1);
    font-size: 13px;
    max-width: 320px;
    z-index: 100;
    transition: opacity 0.2s;
}

.stat-bad { color: #e74c3c; font-weight: bold; }
.stat-good { color: #27ae60; font-weight: bold; }

/* AI Analysis tab content */
#ai-analysis-tab #gemini-response-container {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.gemini-response-box {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    min-height: 150px;
    box-shadow: var(--card-shadow);
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-color);
    max-width: 100%;
}

.gemini-response-box.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-style: italic;
}

.gemini-response-box.error {
    color: var(--danger);
    background: #fff5f5;
    border-color: var(--danger);
}

.gemini-response-box .response-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.gemini-response-box .response-content h3,
.gemini-response-box .response-content h4 {
    margin-top: 20px;
    margin-bottom: 12px;
    color: var(--accent);
    font-weight: 600;
}

.gemini-response-box .response-content h3:first-child,
.gemini-response-box .response-content h4:first-child {
    margin-top: 0;
}

.gemini-response-box .response-content h3 {
    font-size: 1.3em;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 8px;
}

.gemini-response-box .response-content h4 {
    font-size: 1.1em;
}

.gemini-response-box .response-content ul,
.gemini-response-box .response-content ol {
    margin: 12px 0;
    padding-left: 28px;
}

.gemini-response-box .response-content li {
    margin: 6px 0;
}

.gemini-response-box .response-content p {
    margin: 12px 0;
}

.gemini-response-box .response-content code {
    background: #f8f9fa;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.gemini-response-box .response-content pre {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 16px 0;
    border-left: 4px solid var(--accent);
}

.gemini-response-box .response-content pre code {
    background: none;
    padding: 0;
    color: var(--text-color);
}

/* API Key section in summary pane */
#gemini-api-key-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border-color);
}

#gemini-api-key-section input {
    transition: all 0.2s;
}

#gemini-api-key-section input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

/* Responsive Design for Mobile */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 12px;
    }

    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        width: 100%;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .header-tabs {
        width: 100%;
        gap: 6px;
    }

    .tab-btn {
        flex: 1;
        padding: 10px 12px;
        font-size: 13px;
    }

    .header-buttons {
        flex-wrap: wrap;
        width: 100%;
        gap: 6px;
    }

    .header-buttons button {
        flex: 1;
        min-width: 120px;
        padding: 10px 12px;
        font-size: 12px;
    }

    .gemini-api-key-container {
        flex-wrap: wrap;
        width: 100%;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        padding-top: 12px;
        margin-top: 12px;
    }

    #gemini-api-key-input-section {
        flex-wrap: wrap;
        width: 100%;
    }

    #gemini-api-key-input-section input {
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
    }

    #container {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }

    #left-sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 50vh;
        overflow-y: auto;
    }

    #left-sidebar-resize-handle {
        display: none;
    }

    .tab-content {
        padding: 1rem;
    }

    .tab-content h2 {
        font-size: 1.1rem;
    }

    #graph-pane {
        min-height: 400px;
        height: 400px;
        order: 2;
    }

    #summary-pane {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        order: 3;
        max-height: none;
    }

    #summary-pane h2 {
        font-size: 1.1rem;
    }

    .summary-item {
        padding: 12px;
    }

    .summary-item .value {
        font-size: 1.25rem;
    }

    #input-pane {
        padding-top: 16px;
    }

    textarea {
        font-size: 14px;
        padding: 10px;
    }

    button {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px; /* Touch target size */
    }

    .saved-plan-item {
        padding: 12px;
    }

    .gemini-response-box {
        padding: 16px;
        font-size: 14px;
    }

    #tooltip {
        max-width: 280px;
        font-size: 12px;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .header-buttons button {
        font-size: 11px;
        padding: 8px 10px;
    }

    #graph-pane {
        min-height: 300px;
        height: 300px;
    }

    .tab-content {
        padding: 0.75rem;
    }

    #summary-pane {
        padding: 0.75rem;
    }

    .summary-item {
        padding: 10px;
    }

    .summary-item .value {
        font-size: 1.1rem;
    }

    #gemini-api-key-input-section input {
        font-size: 14px;
    }
}

