/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #22c55e;
    --success-hover: #16a34a;

    --premise-color: #3b82f6;
    --premise-bg: #eff6ff;
    --premise-border: #93c5fd;

    --conclusion-color: #8b5cf6;
    --conclusion-bg: #f5f3ff;
    --conclusion-border: #c4b5fd;

    --connection-color: #64748b;

    --bg-color: #f8fafc;
    --canvas-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem 1rem;
    text-align: center;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
}

.logo-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 0.95rem;
    opacity: 0.9;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--canvas-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 1rem;
}

.toolbar-section {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-icon {
    font-size: 1rem;
}

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

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

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

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

.btn-outline {
    background-color: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-color);
}

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

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

.btn-danger {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.btn-danger:hover {
    background-color: var(--danger-color);
    color: white;
}

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

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

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

/* Mode Indicator */
.mode-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--canvas-bg);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.mode-text {
    font-size: 0.875rem;
    color: var(--text-color);
}

.mode-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Canvas */
.canvas-container {
    background: var(--canvas-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 1rem;
}

.canvas {
    position: relative;
    width: 100%;
    height: 500px;
    background-image:
        radial-gradient(circle, var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden;
}

.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.canvas-placeholder.hidden {
    display: none;
}

.placeholder-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
}

.placeholder-content h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.placeholder-content p {
    font-size: 0.9rem;
}

/* Nodes */
.node {
    position: absolute;
    min-width: 150px;
    max-width: 250px;
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: grab;
    transition: box-shadow 0.2s ease, transform 0.1s ease;
    user-select: none;
    z-index: 10;
}

.node:hover {
    box-shadow: var(--shadow-lg);
}

.node.dragging {
    cursor: grabbing;
    z-index: 100;
    transform: scale(1.02);
}

.node.selected {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

.node.premise {
    background-color: var(--premise-bg);
    border: 2px solid var(--premise-border);
}

.node.conclusion {
    background-color: var(--conclusion-bg);
    border: 2px solid var(--conclusion-border);
}

.node-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    opacity: 0.7;
}

.node.premise .node-label {
    color: var(--premise-color);
}

.node.conclusion .node-label {
    color: var(--conclusion-color);
}

.node-text {
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.node-id {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}

.node.premise .node-id {
    background-color: var(--premise-color);
}

.node.conclusion .node-id {
    background-color: var(--conclusion-color);
}

/* Connection Lines */
.connection {
    stroke: var(--connection-color);
    stroke-width: 2;
    fill: none;
    marker-end: url(#arrowhead);
}

.connection:hover {
    stroke-width: 3;
    stroke: var(--primary-color);
}

/* Legend */
.legend {
    background: var(--canvas-bg);
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.legend h4 {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
}

.premise-color {
    background-color: var(--premise-bg);
    border: 2px solid var(--premise-border);
}

.conclusion-color {
    background-color: var(--conclusion-bg);
    border: 2px solid var(--conclusion-border);
}

.legend-line {
    width: 30px;
    height: 2px;
    background-color: var(--connection-color);
    position: relative;
}

.legend-line::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid var(--connection-color);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
}

/* Footer */
.footer {
    background-color: var(--text-color);
    color: white;
    padding: 1rem;
    text-align: center;
    font-size: 0.875rem;
}

.footer a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--canvas-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
}

.modal-small {
    max-width: 400px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.modal-body textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    transition: var(--transition);
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-body p {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .toolbar {
        padding: 0.75rem;
    }

    .toolbar-section {
        width: 100%;
        justify-content: center;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .canvas {
        height: 400px;
    }

    .mode-indicator {
        flex-direction: column;
        gap: 0.25rem;
    }

    .node {
        min-width: 120px;
        max-width: 180px;
        padding: 0.75rem;
    }

    .node-text {
        font-size: 0.8rem;
    }

    .legend-items {
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.5rem;
    }

    .toolbar {
        gap: 0.5rem;
    }

    .btn {
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .btn-icon {
        display: none;
    }

    .canvas {
        height: 350px;
    }

    .modal-content {
        width: 95%;
        margin: 1rem;
    }
}

/* Print / Export styles */
@media print {
    .header,
    .toolbar,
    .mode-indicator,
    .legend,
    .footer {
        display: none !important;
    }

    .canvas-container {
        box-shadow: none;
    }

    .canvas {
        background-image: none;
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        padding: 0.75rem 1rem;
    }

    .node {
        padding: 1rem;
    }
}
