/* CSS Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --grid-color: #e2e8f0;
    --axis-color: #94a3b8;
    --component-color: #3b82f6;
    --component-hover: #2563eb;
    --connection-color: #64748b;
    --header-height: 56px;
    --footer-height: 40px;
    --tutorial-width: 320px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    background: var(--bg-color);
}

/* Layout */
body {
    display: flex;
    flex-direction: column;
}

.app-header {
    height: var(--header-height);
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
    flex-shrink: 0;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-center {
    flex: 1;
    max-width: 300px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

#map-title {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    background: transparent;
    transition: all 0.2s;
}

#map-title:hover {
    border-color: var(--border-color);
}

#map-title:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--surface-color);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-color);
    border-color: var(--text-muted);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    cursor: pointer;
}

.btn-small:hover {
    background: var(--bg-color);
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 4px;
}

.btn-icon:hover {
    background: var(--bg-color);
    color: var(--text-color);
}

/* Main Content */
.app-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Tutorial Panel */
.tutorial-panel {
    width: var(--tutorial-width);
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
}

.tutorial-panel.collapsed {
    margin-left: calc(-1 * var(--tutorial-width));
}

.tutorial-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.tutorial-header h2 {
    font-size: 16px;
    font-weight: 600;
}

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

.tutorial-progress {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

#tutorial-progress-text {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.progress-bar {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.tutorial-steps {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tutorial-step {
    display: none;
}

.tutorial-step.active {
    display: block;
}

.tutorial-step h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-color);
}

.tutorial-step p {
    margin-bottom: 12px;
    color: var(--text-color);
}

.tutorial-step ul {
    margin: 12px 0;
    padding-left: 20px;
}

.tutorial-step li {
    margin-bottom: 8px;
}

.tutorial-step .tip {
    background: #f0f9ff;
    border-left: 3px solid var(--primary-color);
    padding: 12px;
    margin: 16px 0;
    border-radius: 0 6px 6px 0;
}

.tutorial-step .exercise {
    background: #f0fdf4;
    border-left: 3px solid #22c55e;
    padding: 12px;
    margin: 16px 0;
    border-radius: 0 6px 6px 0;
}

.tutorial-nav {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.tutorial-nav .btn {
    flex: 1;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.toolbar-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.toolbar-hint a {
    color: var(--primary-color);
    text-decoration: none;
}

.toolbar-hint a:hover {
    text-decoration: underline;
}

.toolbar-controls {
    display: flex;
    gap: 16px;
}

.toolbar-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #fff;
}

.wardley-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    background: #fff;
}

/* Grid - Wardley map standard style */
.axis-line {
    stroke: #333;
    stroke-width: 1.5;
}

.grid-line-dashed {
    stroke: #999;
    stroke-width: 1;
    stroke-dasharray: 5 5;
}

/* Axis Labels - Wardley map standard style */
.axis-labels text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.axis-label-title {
    font-size: 14px;
    font-weight: 500;
    fill: #333;
}

.evolution-label {
    font-size: 13px;
    fill: #333;
}

/* Components - Wardley map standard style */
.component {
    cursor: move;
}

.component circle {
    fill: white;
    stroke: #333;
    stroke-width: 2;
    transition: all 0.15s;
}

.component:hover circle {
    stroke: #000;
    stroke-width: 2.5;
}

.component.selected circle {
    fill: #e3f2fd;
    stroke: var(--primary-color);
    stroke-width: 2.5;
}

.component.connecting circle {
    fill: #e8f5e9;
    stroke: #2e7d32;
    stroke-width: 2.5;
}

.component text {
    font-size: 13px;
    fill: #333;
    pointer-events: none;
    user-select: none;
}

.component.dragging {
    opacity: 0.7;
}

/* Connections - Wardley map standard style */
.connection {
    stroke: #666;
    stroke-width: 1.5;
    fill: none;
    cursor: pointer;
}

.connection:hover {
    stroke: #333;
    stroke-width: 2;
}

.connection.selected {
    stroke: var(--danger-color);
    stroke-width: 2.5;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
    min-width: 150px;
}

.context-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.context-item:hover {
    background: var(--bg-color);
}

.context-item-danger {
    color: var(--danger-color);
}

.context-item-danger:hover {
    background: #fef2f2;
}

/* Connection Mode Overlay */
.connection-mode-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    padding: 12px;
    background: #fef3c7;
    border-bottom: 1px solid #fbbf24;
    text-align: center;
    font-size: 14px;
    color: #92400e;
    z-index: 100;
}

/* Footer */
.app-footer {
    height: var(--footer-height);
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.footer-left {
    font-size: 13px;
    color: var(--text-muted);
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.map-id {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.map-id code {
    font-family: 'Monaco', 'Menlo', monospace;
    background: var(--bg-color);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --tutorial-width: 100%;
    }

    .app-main {
        flex-direction: column;
    }

    .tutorial-panel {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: var(--footer-height);
        z-index: 50;
        border-right: none;
    }

    .tutorial-panel.collapsed {
        margin-left: 0;
        transform: translateX(-100%);
    }

    .header-center {
        display: none;
    }

    .toolbar-hint {
        display: none;
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.2s ease;
}

/* Canvas Hint - subtle prompt for empty canvas */
.canvas-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.canvas-hint.hidden {
    opacity: 0;
    pointer-events: none;
}

.canvas-hint span {
    display: inline-block;
    padding: 12px 24px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px dashed var(--primary-color);
    border-radius: 8px;
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
}

/* Loading spinner */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--text-color);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1001;
    animation: slideUp 0.3s ease;
}

.toast.error {
    background: var(--danger-color);
}

.toast.success {
    background: #16a34a;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Welcome Screen */
.welcome-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #f0fdf4 100%);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-card {
    background: var(--surface-color);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
    padding: 48px;
    max-width: 520px;
    width: 90%;
    text-align: center;
}

.welcome-header {
    margin-bottom: 32px;
}

.welcome-header svg {
    margin-bottom: 16px;
}

.welcome-header h2 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--text-muted);
}

.quick-start {
    text-align: left;
    margin-bottom: 32px;
}

.quick-start h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.quick-start-steps {
    list-style: none;
    padding: 0;
    margin: 0;
}

.quick-start-steps li {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
}

.quick-start-steps li:last-child {
    border-bottom: none;
}

.step-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.step-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.step-content strong {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color);
}

.step-content span {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.btn-large {
    padding: 14px 24px;
    font-size: 15px;
}

.welcome-hint {
    font-size: 13px;
    color: var(--text-muted);
}

.welcome-hint kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
}

@media (max-width: 768px) {
    .welcome-card {
        padding: 32px 24px;
    }

    .welcome-header h2 {
        font-size: 22px;
    }

    .welcome-actions {
        gap: 10px;
    }
}

/* Strategy Panel */
:root {
    --strategy-width: 380px;
}

.strategy-panel {
    width: var(--strategy-width);
    background: var(--surface-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-right 0.3s ease;
    position: relative;
    order: 1;
}

.strategy-panel.collapsed {
    margin-right: calc(-1 * var(--strategy-width));
}

.strategy-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.strategy-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-color);
}

.strategy-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 0;
}

.strategy-domain {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.strategy-domain label {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.strategy-domain select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    background: var(--surface-color);
}

.strategy-analysis {
    padding: 16px;
    flex: 1;
}

.strategy-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.strategy-empty p {
    margin-bottom: 8px;
}

.strategy-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.strategy-section {
    margin-bottom: 24px;
}

.strategy-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.strategy-section p {
    font-size: 13px;
    color: var(--text-color);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* Evolution Breakdown */
.evolution-breakdown {
    margin-top: 12px;
}

.evolution-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
}

.bar-segment.genesis {
    background: #8b5cf6;
}

.bar-segment.custom {
    background: #3b82f6;
}

.bar-segment.product {
    background: #10b981;
}

.bar-segment.commodity {
    background: #6b7280;
}

.evolution-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-item .dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.dot.genesis {
    background: #8b5cf6;
}

.dot.custom {
    background: #3b82f6;
}

.dot.product {
    background: #10b981;
}

.dot.commodity {
    background: #6b7280;
}

/* Patterns */
.patterns-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pattern-card {
    padding: 12px;
    border-radius: 6px;
    border-left: 3px solid;
}

.pattern-card.warning {
    background: #fef3c7;
    border-color: #f59e0b;
}

.pattern-card.info {
    background: #f0f9ff;
    border-color: #3b82f6;
}

.pattern-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}

.pattern-description {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Questions */
.question-group {
    margin-bottom: 16px;
}

.question-group h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.question-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.question-list li {
    font-size: 12px;
    color: var(--text-color);
    padding: 8px 12px;
    background: var(--bg-color);
    border-radius: 4px;
    margin-bottom: 6px;
    line-height: 1.5;
}

.question-list li strong {
    color: var(--primary-color);
}

/* Domain Tips */
.domain-tips {
    list-style: none;
    padding: 0;
    margin: 0;
}

.domain-tips li {
    font-size: 12px;
    color: var(--text-color);
    padding: 8px 12px;
    background: #f0fdf4;
    border-left: 2px solid #22c55e;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* Strategy Notes Section */
.strategy-notes-section {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-color);
}

.strategy-notes-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 12px;
}

.strategy-note-group {
    margin-bottom: 12px;
}

.strategy-note-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.strategy-note-group textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    background: var(--surface-color);
}

.strategy-note-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.strategy-note-group textarea::placeholder {
    color: var(--text-muted);
    font-size: 12px;
}

/* Strategy Panel Responsive */
@media (max-width: 1024px) {
    :root {
        --strategy-width: 320px;
    }
}

@media (max-width: 768px) {
    .strategy-panel {
        position: fixed;
        top: var(--header-height);
        right: 0;
        bottom: var(--footer-height);
        z-index: 50;
        width: 100%;
        border-left: none;
    }

    .strategy-panel.collapsed {
        margin-right: 0;
        transform: translateX(100%);
    }
}
