/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --card: #21262d;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --danger: #f85149;
    --warning: #d29922;
    --success: #3fb950;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-dim: #484f58;
    --integration: #bc8cff;
    --api-color: #f0883e;
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* === LOGIN GATE === */
#login-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

#login-gate.hidden { display: none; }

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    width: 360px;
}

.login-box h1 {
    font-size: 1.8em;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--accent);
}

.login-box p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-password {
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1em;
    text-align: center;
    outline: none;
}

#login-password:focus {
    border-color: var(--accent);
}

.error-msg {
    color: var(--danger);
    font-size: 0.85em;
    margin-top: 8px;
}

/* === HIDDEN === */
.hidden { display: none !important; }

/* === TOOLBAR === */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar-left h1 {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--accent);
}

.toolbar-right {
    display: flex;
    gap: 8px;
}

/* === BUTTONS === */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

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

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

.btn-secondary {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}
.btn-secondary:hover { background: rgba(88,166,255,0.1); }

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

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(248,81,73,0.1); }

.btn-small {
    padding: 4px 10px;
    font-size: 0.75em;
}

/* === CONNECTION MODE BAR === */
#connection-mode-bar {
    background: rgba(88,166,255,0.1);
    border-bottom: 2px solid var(--accent);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9em;
    color: var(--accent);
}

/* === MAP === */
#map-container {
    position: relative;
    padding: 24px;
    min-height: calc(100vh - 60px);
}

#map-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#map-svg line, #map-svg path {
    pointer-events: stroke;
}

#map-content {
    position: relative;
    z-index: 5;
}

/* === PROJECT BOX (was branch-box) === */
.project-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    overflow: visible;
    transition: opacity 0.2s, border-color 0.2s;
}

.project-box[draggable="true"] { cursor: grab; }
.project-box[draggable="true"]:active { cursor: grabbing; }
.project-dragging { opacity: 0.4; }
.project-drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
}

.project-planned {
    border-style: dashed;
    border-color: var(--border);
}

.project-future {
    border-style: dotted;
    border-color: var(--border);
    opacity: 0.7;
}

.project-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.project-header:hover { background: rgba(255,255,255,0.02); }

.project-collapsed .project-header {
    border-bottom: none;
}

.project-collapse-icon {
    font-size: 0.7em;
    color: var(--text-dim);
    width: 14px;
    text-align: center;
}

.project-count {
    font-size: 0.7em;
    font-weight: 400;
    color: var(--text-dim);
    margin-left: 4px;
}

.project-name {
    font-size: 1.1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.project-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.project-actions {
    display: flex;
    gap: 6px;
}

.project-content {
    padding: 16px 20px;
}

/* === MODULES GRID === */
.modules-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
}

/* === MODULE BOX === */
.module-box {
    padding: 14px 18px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    max-width: 200px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.module-box:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.module-box.status-active {
    border-color: var(--success);
}

.module-box.status-planned {
    border-style: dashed;
    border-color: var(--text-dim);
    background: rgba(33,38,45,0.5);
    opacity: 0.55;
}
.module-box.status-planned .module-name,
.module-box.status-planned .module-meta {
    color: var(--text-muted);
}
.module-box.status-planned:hover {
    opacity: 0.8;
    border-color: var(--text-muted);
}

.module-box.status-future {
    border-style: dotted;
    border-color: var(--text-dim);
    opacity: 0.35;
    background: repeating-linear-gradient(
        -45deg,
        rgba(33,38,45,0.4),
        rgba(33,38,45,0.4) 4px,
        rgba(255,255,255,0.02) 4px,
        rgba(255,255,255,0.02) 8px
    );
}
.module-box.status-future .module-name,
.module-box.status-future .module-meta {
    color: var(--text-dim);
}
.module-box.status-future:hover {
    opacity: 0.6;
}

/* Integration accent */
.module-box.type-integration {
    border-color: var(--integration);
}
.module-box.type-integration.status-planned {
    border-color: rgba(188,140,255,0.35);
    border-style: dashed;
}
.module-box.type-integration.status-future {
    border-color: rgba(188,140,255,0.2);
    border-style: dotted;
}

/* API accent */
.module-box.type-api {
    border-color: var(--api-color);
}
.module-box.type-api.status-planned {
    border-color: rgba(240,136,62,0.35);
    border-style: dashed;
}
.module-box.type-api.status-future {
    border-color: rgba(240,136,62,0.2);
    border-style: dotted;
}

/* Connection mode highlights */
.module-box.connection-source {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(88,166,255,0.3);
}

.module-box.connection-target-hover {
    border-color: var(--success) !important;
    box-shadow: 0 0 0 3px rgba(63,185,80,0.3);
}

.module-name {
    font-weight: 600;
    font-size: 0.88em;
    margin-bottom: 4px;
}

.module-info {
    font-size: 0.72em;
    color: var(--text-muted);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.module-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.version-badge {
    font-size: 0.68em;
    background: rgba(255,255,255,0.08);
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    font-family: monospace;
}

.type-badge {
    font-size: 0.62em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--integration);
    font-weight: 600;
}

.type-badge-api {
    color: var(--api-color);
}

.managed-badge {
    font-size: 0.62em;
    color: var(--text-dim);
}

/* === SUBMODULE CARDS === */
.module-with-subs {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.submodules-below {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    justify-content: center;
}

.submodule-card {
    padding: 10px 14px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 6px rgba(0,0,0,0.2);
}

.submodule-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.submodule-card.status-active { border-color: var(--success); }
.submodule-card.status-planned { border-style: dashed; border-color: var(--text-dim); opacity: 0.55; }
.submodule-card.status-future { border-style: dotted; border-color: var(--text-dim); opacity: 0.35; }

.submodule-card-name {
    font-weight: 600;
    font-size: 0.72em;
    color: var(--text-muted);
    text-align: center;
    word-break: break-word;
    line-height: 1.3;
}

/* Add module button */
.btn-add-inline {
    padding: 6px 12px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-add-inline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* === SVG CONNECTIONS === */
#map-svg .connection-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    opacity: 0.6;
}

#map-svg .connection-line.type-depends_on { stroke: var(--warning); }
#map-svg .connection-line.type-provides { stroke: var(--success); }
#map-svg .connection-line.type-uses { stroke: var(--accent); }

#map-svg .connection-line:hover {
    stroke-width: 3;
    opacity: 1;
    cursor: pointer;
}

#map-svg .connection-label {
    font-size: 11px;
    fill: var(--text-muted);
    font-family: var(--font);
}

#map-svg marker path {
    fill: var(--accent);
}

/* === MODALS === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 420px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content.modal-wide { width: 560px; }

.modal-content h2 {
    font-size: 1.2em;
    margin-bottom: 20px;
}

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

.form-group label {
    display: block;
    font-size: 0.82em;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9em;
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group input[type="color"] {
    width: 50px;
    height: 36px;
    padding: 2px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group { flex: 1; }
.form-group-small { max-width: 120px; }

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.modal-actions .btn-danger { margin-left: auto; }

/* === MARKDOWN PREVIEW === */
.md-preview {
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 8px;
    font-size: 0.9em;
    line-height: 1.6;
}

.md-preview h1, .md-preview h2, .md-preview h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.md-preview h1 { font-size: 1.3em; }
.md-preview h2 { font-size: 1.1em; }
.md-preview h3 { font-size: 1em; }

.md-preview p { margin-bottom: 8px; }
.md-preview ul, .md-preview ol { padding-left: 20px; margin-bottom: 8px; }
.md-preview code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.md-preview pre {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 8px;
}

.md-preview a {
    color: var(--accent);
}

/* === DETAIL MODAL === */
#detail-content {
    line-height: 1.6;
}

#detail-content .detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

#detail-content .detail-header h2 {
    margin: 0;
    font-size: 1.3em;
}

#detail-content .detail-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

#detail-content .detail-tag {
    font-size: 0.75em;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
}

#detail-content .detail-body {
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    #toolbar {
        flex-direction: column;
        gap: 8px;
    }
    .toolbar-right { width: 100%; justify-content: flex-end; }
    .modules-grid { flex-direction: column; }
    .modal-content { width: 95%; padding: 20px; }
    .form-row { flex-direction: column; }
}

/* === EMPTY STATE === */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.empty-state h2 {
    font-size: 1.2em;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.9em;
    margin-bottom: 20px;
}

/* === TREE VIEW === */
.tree-view {
    padding: 8px 0;
}

.tree-project-group {
    margin-bottom: 8px;
}

.tree-children {
    margin-left: 28px;
    border-left: 2px solid var(--border);
    padding-left: 0;
}

.tree-node {
    position: relative;
    padding: 8px 16px;
    margin: 2px 0;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tree-children > .tree-module,
.tree-children > .tree-node {
    position: relative;
    padding-left: 20px;
}

.tree-children > .tree-module::before,
.tree-children > .tree-node::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 18px;
    width: 20px;
    height: 0;
    border-top: 2px solid var(--border);
}

.tree-node-project {
    font-size: 1.05em;
    font-weight: 700;
    color: var(--text);
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.tree-node-project:hover { border-color: var(--text-muted); }

.tree-node-module {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text);
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
}
.tree-node-module:hover { border-color: var(--accent); }
.tree-node-module.status-active { border-color: var(--success); }
.tree-node-module.status-planned { border-style: dashed; border-color: var(--text-dim); opacity: 0.6; }
.tree-node-module.status-future { border-style: dotted; border-color: var(--text-dim); opacity: 0.4; }
.tree-node-module.tree-integration { border-color: var(--integration); }
.tree-node-module.tree-api { border-color: var(--api-color); }

.tree-type-badge {
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--integration);
    margin-left: 4px;
}

.tree-type-badge.tree-type-int {
    color: var(--integration);
}

.tree-node-sub {
    font-size: 0.78em;
    color: var(--text-muted);
    padding: 4px 12px;
    background: rgba(33,38,45,0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.tree-node-sub:hover { border-color: var(--accent); }
.tree-node-sub.status-active { border-color: var(--success); }
.tree-node-sub.status-planned { border-style: dashed; opacity: 0.6; }
.tree-node-sub.status-future { border-style: dotted; opacity: 0.4; }

.tree-node-add {
    font-size: 0.78em;
    color: var(--text-dim);
    border: 1px dashed var(--border);
    padding: 4px 12px;
}
.tree-node-add:hover { color: var(--accent); border-color: var(--accent); }

.tree-version {
    font-size: 0.75em;
    color: var(--text-dim);
    font-family: monospace;
}
