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

body { font-family: 'Segoe UI', sans-serif; background: #1a1a2e; color: #eee; overflow: hidden; height: 100vh; }

/* ── Toolbar ── */
#toolbar {
    position: fixed; top: 0; left: 0; right: 0; height: 60px;
    background: #16213e; border-bottom: 1px solid #0f3460;
    display: flex; align-items: center; gap: 12px; padding: 0 18px;
    z-index: 1000; box-shadow: 0 2px 8px #0006;
}
#toolbar h1 { font-size: 1.2rem; color: #e94560; letter-spacing: 1px; margin-right: 10px; }
.btn {
    padding: 8px 18px; border: 1px solid #0f3460; border-radius: 5px;
    background: #0f3460; color: #cdd; cursor: pointer; font-size: 0.95rem;
    transition: background .15s;
}
.btn:hover { background: #1a4a80; }
.btn.danger { border-color: #c0392b; background: #7b241c; }
.btn.danger:hover { background: #c0392b; }
.btn.success { border-color: #1e8449; background: #1a5c35; }
.btn.success:hover { background: #27ae60; }
#zoom-info { font-size: 0.78rem; color: #8af; min-width: 50px; }

/* ── Canvas ── */
#canvas-wrap {
    position: fixed; top: 60px; left: 0; right: 0; bottom: 0;
    overflow: hidden; cursor: default;
}
#canvas {
    position: absolute; top: 0; left: 0;
    width: 20000px; height: 16000px;
    transform-origin: 0 0;
}
#svg-layer {
    position: fixed; top: 60px; left: 0; right: 0; bottom: 0;
    pointer-events: none; z-index: 100; overflow: hidden;
}

/* ── Act blocks ── */
.act-block {
    position: absolute;
    background: #ffffff;
    border: 1.5px solid #c8d6e5;
    border-radius: 6px;
    display: flex; flex-direction: column;
    box-shadow: 0 2px 12px #0002, 0 1px 3px #0001;
    min-width: 300px;
}
.act-block.dragging { opacity: .90; box-shadow: 0 8px 32px #0003; z-index: 200; }
.act-block-header {
    padding: 8px 12px;
    background: #f0f4f8;
    border-bottom: 1.5px solid #c8d6e5;
    border-radius: 4px 4px 0 0;
    display: flex; align-items: center; gap: 8px;
    cursor: grab; user-select: none;
}
.act-block-header:active { cursor: grabbing; }
.act-block-title { font-size: 0.82rem; font-weight: 600; color: #1e3a5f; flex: 1; }
.act-block-type { font-size: 0.7rem; color: #6b7a8d; }
.btn-sm { padding: 2px 7px; font-size: 0.72rem; }
.act-block-header .btn-sm {
    background: #dde6f0; border-color: #b0c4d8; color: #1e3a5f;
}
.act-block-header .btn-sm:hover { background: #c5d5e8; }
.act-block-header .btn-sm.danger { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
.act-block-header .btn-sm.danger:hover { background: #fca5a5; }
.act-block-body { padding: 6px; background: #fff; }

/* ── Section rows ── */
.section-row {
    padding: 4px 6px; border-bottom: 1px solid #e8eef4;
    font-size: 0.76rem; line-height: 1.4;
    position: relative;
}
.section-row:last-child { border-bottom: none; }
.section-index {
    font-size: 0.68rem; color: #8a9ab0; margin-bottom: 2px;
}
.section-content { color: #1a2a3a; }

/* F7 — odsyłacz highlight (stary, zachowany dla kompatybilności) */
.ref-highlight {
    background: #dbeafe;
    border: 1px solid #2563eb;
    border-radius: 2px;
    padding: 0 2px;
    cursor: pointer;
    color: #1d4ed8;
}
.ref-highlight:hover { background: #bfdbfe; }

/* Inline reference text — ramka wokół tekstu odsyłacza */
.ref-inline {
    background: rgba(234,88,12,0.12);
    border: 1.5px solid #ea580c;
    border-radius: 2px;
    padding: 0 2px;
    color: #c2410c;
    cursor: pointer;
    font-weight: 500;
}
.ref-inline:hover { background: rgba(234,88,12,0.25); }

/* F8 — target highlight */
.section-row.target-highlight {
    background: rgba(234,88,12,0.07);
    border-left: 2.5px solid #ea580c;
    border-right: 2.5px solid #ea580c;
    border-top: 1px solid rgba(234,88,12,0.4);
    border-bottom: 1px solid rgba(234,88,12,0.4);
    border-radius: 2px;
}

/* ── Modal ── */
#modal-overlay {
    display: none; position: fixed; inset: 0;
    background: #000a; z-index: 2000;
    align-items: center; justify-content: center;
}
#modal-overlay.open { display: flex; }
#modal {
    background: #16213e; border: 1px solid #0f3460;
    border-radius: 8px; padding: 24px; min-width: 420px; max-width: 90vw;
}
#modal h2 { color: #e94560; margin-bottom: 16px; font-size: 1rem; }
#modal label { display: block; font-size: 0.82rem; color: #aac; margin-bottom: 4px; }
#modal input, #modal select, #modal textarea {
    width: 100%; padding: 6px 10px; background: #0d1b2e;
    border: 1px solid #0f3460; border-radius: 4px; color: #eee;
    font-size: 0.82rem; margin-bottom: 12px;
}
#modal .modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ── SVG lines ── */
.conn-line { stroke: #4a7fd8; stroke-width: 1.5; fill: none; opacity: .75; }
.conn-line.manual { stroke: #e67e22; }
.conn-line.cross-act { stroke: #27ae60; stroke-width: 2; stroke-dasharray: none; opacity: .8; }
.conn-line.cross-act.manual { stroke: #e67e22; }
.conn-line:hover { opacity: 1; stroke-width: 3; }

/* ── Resize handle ── */
.resize-handle {
    position: absolute; bottom: 0; right: 0;
    width: 16px; height: 16px; cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, #0f3460 50%);
    border-radius: 0 0 4px 0;
}

/* ── Sidebar ── */
#sidebar {
    position: fixed; right: 0; top: 60px; bottom: 0; width: 280px;
    background: #16213e; border-left: 1px solid #0f3460;
    padding: 12px; overflow-y: auto; z-index: 500;
    transform: translateX(100%); transition: transform .2s;
}
#sidebar.open { transform: translateX(0); }
#sidebar h3 { font-size: 0.85rem; color: #e94560; margin-bottom: 10px; }
.sidebar-section { margin-bottom: 12px; }
.ref-item {
    font-size: 0.75rem; padding: 4px 6px; background: #0d1b2e;
    border-radius: 3px; margin-bottom: 3px; cursor: pointer;
    border: 1px solid #1a3a6a; display: flex; justify-content: space-between;
}
.ref-item:hover { border-color: #3a6fd8; }
.ref-item .del { color: #e94560; font-size: 0.7rem; }

/* ── Toggle switch ── */
.mgr-toggle { position:relative; display:inline-block; width:34px; height:18px; cursor:pointer; }
.mgr-toggle input { opacity:0; width:0; height:0; }
.mgr-toggle-slider {
    position:absolute; inset:0; background:#1a2a40; border-radius:18px;
    transition:.2s; border:1px solid #0f3460;
}
.mgr-toggle-slider::before {
    content:''; position:absolute; width:12px; height:12px;
    left:2px; bottom:2px; background:#556; border-radius:50%; transition:.2s;
}
.mgr-toggle input:checked + .mgr-toggle-slider { background:#1a5c35; border-color:#27ae60; }
.mgr-toggle input:checked + .mgr-toggle-slider::before { transform:translateX(16px); background:#27ae60; }
.mgr-row-hidden td { opacity:.4; }

/* ── Manager overlay ── */
#mgr-overlay {
    display: none; position: fixed; inset: 0;
    background: #000c; z-index: 3000;
    align-items: flex-start; justify-content: center;
    padding-top: 60px;
    overflow-y: auto;
}
#mgr-overlay.open { display: flex; }
#mgr-modal {
    background: #16213e; border: 1px solid #0f3460;
    border-radius: 10px; width: 820px; max-width: 96vw;
    margin-bottom: 40px;
    box-shadow: 0 8px 40px #000c;
}
#mgr-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid #0f3460;
}
#mgr-header h2 { font-size: 1rem; color: #e94560; }
.mgr-section { padding: 16px 20px; border-bottom: 1px solid #0f3460; }
.mgr-section:last-child { border-bottom: none; }
.mgr-label { display: block; font-size: 0.8rem; color: #aac; margin-bottom: 8px; }
.mgr-status { font-size: 0.75rem; color: #668; min-height: 18px; margin: 6px 0; }
.mgr-no-results { font-size: 0.8rem; color: #556; padding: 8px 0; }

/* Results list */
#mgr-results { max-height: 220px; overflow-y: auto; margin-top: 6px; }
.mgr-result-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 4px; cursor: pointer;
    border-bottom: 1px solid #0f2040; font-size: 0.78rem;
}
.mgr-result-row:hover { background: #1a2a4a; }
.mgr-result-row input[type=checkbox] { width: 14px; height: 14px; cursor: pointer; flex-shrink:0; }
.mgr-result-title { flex: 1; color: #ccd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mgr-isap-tag { font-size: 0.67rem; color: #556; background: #0d1b2e; border-radius: 3px; padding: 1px 5px; white-space: nowrap; }
.mgr-isap-tag.empty { color: #c0392b; }

.mgr-badge {
    font-size: 0.67rem; padding: 2px 6px; border-radius: 3px;
    white-space: nowrap; flex-shrink: 0;
}
.mgr-badge.ustawa         { background: #1a3a6a; color: #7eb8ff; }
.mgr-badge.rozporzadzenie { background: #2a1a4a; color: #bf7fff; }

#mgr-import-bar { display: flex; align-items: center; gap: 10px; }

/* Log */
#mgr-log {
    max-height: 120px; overflow-y: auto; margin-top: 8px;
    background: #0a1020; border-radius: 4px; padding: 6px 10px;
    font-size: 0.75rem; color: #8af; font-family: monospace;
    display: none;
}
#mgr-log:not(:empty) { display: block; }
.mgr-log-line { padding: 2px 0; border-bottom: 1px solid #0f2040; }
.mgr-log-line:last-child { border-bottom: none; }

/* Imported table */
#mgr-imported-wrap { overflow-x: auto; }
#mgr-imported-table {
    width: 100%; border-collapse: collapse; font-size: 0.78rem;
}
#mgr-imported-table th {
    text-align: left; padding: 6px 8px;
    border-bottom: 2px solid #0f3460; color: #668; font-weight: 600;
}
#mgr-imported-table td { padding: 6px 8px; border-bottom: 1px solid #0f2040; vertical-align: middle; }
#mgr-imported-table tr:hover td { background: #1a2a4a; }
.mgr-act-name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #ccd; }
.mgr-act-name.editing { overflow: visible; white-space: normal; min-width: 280px; }

/* Modal input overrides for mgr */
#mgr-modal input[type=text] {
    padding: 7px 10px; background: #0d1b2e; border: 1px solid #0f3460;
    border-radius: 4px; color: #eee; font-size: 0.85rem; width: 100%;
}

/* ── Toast notifications ── */
#toast-wrap {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 9999; display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 10px 18px; border-radius: 6px; font-size: 0.82rem;
    color: #eee; box-shadow: 0 4px 16px #0008;
    opacity: 0; transform: translateX(40px);
    transition: opacity .2s, transform .2s;
    pointer-events: auto; max-width: 340px; line-height: 1.4;
    border-left: 4px solid #3a6fd8;
    background: #1a2740;
}
.toast.show   { opacity: 1; transform: translateX(0); }
.toast.success { border-color: #27ae60; }
.toast.error   { border-color: #e74c3c; background: #2a1010; }
.toast.warn    { border-color: #f39c12; }

/* ── Confirm dialog ── */
#confirm-overlay {
    display: none; position: fixed; inset: 0;
    background: #000a; z-index: 8000;
    align-items: center; justify-content: center;
}
#confirm-overlay.open { display: flex; }
#confirm-box {
    background: #16213e; border: 1px solid #0f3460;
    border-radius: 8px; padding: 24px 28px;
    min-width: 300px; max-width: 460px;
    box-shadow: 0 8px 40px #000c;
}
#confirm-msg { font-size: 0.88rem; color: #ccd; margin-bottom: 20px; line-height: 1.5; }
#confirm-btns { display: flex; gap: 10px; justify-content: flex-end; }

@media print {
    #toolbar, #sidebar, #svg-layer, .resize-handle, .btn, .btn-sm { display: none !important; }
    #svg-print { display: block !important; }
    body { background: white; overflow: visible; margin: 0; }
    #canvas-wrap { position: static; overflow: visible; top: 0; left: 0; }
    #canvas {
        transform: none !important;
        position: relative !important;
        background: white;
    }
    .act-block { border-color: #333; background: white; color: #000; break-inside: avoid; }
    .act-block-header { background: #1a2332; color: #fff; }
    .section-content { color: #000; }
    .ref-inline { background: rgba(234,88,12,.15); border: 1px solid #ea580c; }
}
