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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: #f4f7f6;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── TOOLBAR ── */
.toolbar {
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
    flex-shrink: 0;
    gap: 10px;
}

.toolbar h1 {
    font-size: 18px;
    color: #1f2937;
    white-space: nowrap;
}

.toolbar-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-tool {
    padding: 7px 13px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background-color: white;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-tool:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.btn-export {
    background-color: #2563eb;
    color: white;
    border-color: #2563eb;
}

.btn-export:hover {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
}

#import-input {
    display: none;
}

/* ── CANVAS (infinite pan+zoom) ── */
.canvas-viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    user-select: none;
    /* dotted grid background */
    background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 28px 28px;
}

.canvas-viewport.panning {
    cursor: grabbing;
}

.canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    /* initial centering is handled by JS */
}

/* ── ZOOM CONTROLS ── */
.zoom-controls {
    position: absolute;
    bottom: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 20;
}

.btn-zoom {
    width: 36px;
    height: 36px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 700;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: background 0.15s;
}

.btn-zoom:hover {
    background: #f3f4f6;
}

.zoom-label {
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-align: center;
    padding: 4px 2px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    cursor: pointer;
    user-select: none;
}

.zoom-label:hover {
    background: #f3f4f6;
}

/* ── TREE ── */
.tree {
    display: inline-block;
    padding: 60px 40px;
}

.tree ul {
    padding-top: 20px;
    position: relative;
    display: flex;
    justify-content: center;
}

.tree li {
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 10px 0 10px;
}

.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 2px solid #cbd5e1;
    width: 50%;
    height: 20px;
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: 2px solid #cbd5e1;
}

.tree li:only-child::after,
.tree li:only-child::before {
    display: none;
}

.tree li:only-child {
    padding-top: 0;
}

.tree li:first-child::before,
.tree li:last-child::after {
    border: 0 none;
}

.tree li:last-child::before {
    border-right: 2px solid #cbd5e1;
    border-radius: 0 5px 0 0;
}

.tree li:first-child::after {
    border-radius: 5px 0 0 0;
}

.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 2px solid #cbd5e1;
    width: 0;
    height: 20px;
    transform: translateX(-50%);
}

/* ── NODE CARDS ── */
.node-container {
    display: inline-block;
    position: relative;
    vertical-align: top;
}

.node-card {
    background: #ffffff;
    border: 2px solid #3b82f6;
    border-radius: 6px;
    padding: 13px;
    width: 155px;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 0 auto;
}

.node-card.condition {
    background: #fffbeb;
    border: 2px solid #d97706;
}

.node-card.branch {
    background: #f0fdf4;
    border: 2px solid #10b981;
    border-style: dashed;
}

.node-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.node-title {
    font-weight: 600;
    font-size: 13px;
    color: #1f2937;
    cursor: pointer;
    word-wrap: break-word;
    width: 100%;
    text-align: center;
}

.node-title:hover { color: #3b82f6; }
.node-card.condition .node-title { color: #92400e; }
.node-card.branch .node-title { color: #065f46; }

.attachment-badge {
    font-size: 11px;
    color: #2563eb;
    margin-top: 5px;
    background: #eff6ff;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 500;
    border: 1px solid #bfdbfe;
}

.actions-wrapper {
    margin-top: 8px;
    display: flex;
    justify-content: center;
    gap: 5px;
}

.btn-action {
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-add    { background-color: #3b82f6; }
.btn-if     { background-color: #f59e0b; color: #1e3a8a; }
.btn-branch { background-color: #10b981; }

/* ── DETAIL PANE ── */
.detail-pane {
    width: min(400px, 100vw);
    background-color: #ffffff;
    box-shadow: -5px 0 25px rgba(0,0,0,0.15);
    border-left: 1px solid #e5e7eb;
    position: fixed;
    right: 0;
    top: 0;
    height: 100%;
    padding: 22px 20px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    overflow-y: auto;
}

.detail-pane.open {
    transform: translateX(0);
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #9ca3af;
    cursor: pointer;
    line-height: 1;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
    margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.file-box {
    border: 1px dashed #cbd5e1;
    padding: 11px;
    border-radius: 4px;
    background-color: #fafafa;
}

.file-input-wrapper { margin-bottom: 10px; }

.files-container-list {
    max-height: 140px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 13px;
}

.file-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    word-break: break-all;
    margin-right: 8px;
}

.file-link:hover { text-decoration: underline; }

.btn-delete-file {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.btn-delete-file:hover { text-decoration: underline; }

.pane-footer {
    margin-top: auto;
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-save {
    width: 100%;
    background-color: #3b82f6;
    color: white;
    border: none;
    padding: 11px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.btn-delete {
    width: 100%;
    background-color: #ef4444;
    color: white;
    border: none;
    padding: 9px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ── RESPONSIVE (mobile) ── */
@media (max-width: 600px) {
    .toolbar { padding: 10px 14px; }
    .toolbar h1 { font-size: 16px; }
    .btn-tool { padding: 6px 10px; font-size: 12px; }
    .node-card { width: 130px; padding: 10px 8px; }
    .node-title { font-size: 12px; }
    .tree { padding: 40px 20px; }
    .zoom-controls { bottom: 12px; right: 12px; }
}
