/* =========================================================
   Database Lineage Explorer – Styles
   ========================================================= */

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

/* Dark theme (default) */
:root {
    --bg: #0f1117;
    --sidebar-bg: #181a20;
    --card-bg: #1e2028;
    --border: #2a2d38;
    --text: #e0e0e6;
    --text-dim: #8a8d98;
    --accent: #4f8cff;
    --accent-hover: #6ba0ff;

    --color-table: #4fc3f7;
    --color-view: #81c784;
    --color-function: #ffb74d;
    --color-procedure: #ce93d8;

    --color-direct: #4fc3f7;
    --color-expression: #ffb74d;
    --color-rename: #ef5350;
}

/* Light theme */
[data-theme="light"] {
    --bg: #f5f6fa;
    --sidebar-bg: #ffffff;
    --card-bg: #eef0f4;
    --border: #d5d8e0;
    --text: #1a1d27;
    --text-dim: #6b6f7e;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --color-table: #1565c0;
    --color-view: #2e7d32;
    --color-function: #e65100;
    --color-procedure: #6a1b9a;

    --color-direct: #1565c0;
    --color-expression: #e65100;
    --color-rename: #c62828;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

body {
    display: flex;
}

/* ---- Sidebar ---- */
#sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 14px;
    gap: 10px;
}

/* ---- Header with logo ---- */
#sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#logo {
    height: 28px;
    width: auto;
    object-fit: contain;
}

/* White logo in dark mode */
:root #logo { filter: brightness(0) invert(1); }
[data-theme="light"] #logo { filter: none; }

#header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ---- Search row ---- */
#search-row {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

#search-container { flex: 1; position: relative; }

#search {
    width: 100%;
    padding: 7px 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

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

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    flex-shrink: 0;
    transition: all .15s;
}

.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.active { background: rgba(79,140,255,.2); border-color: var(--accent); color: var(--accent); }

/* ---- Filter panel (collapsible) ---- */
#filter-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow-y: auto;
    max-height: 320px;
}

#filter-panel.hidden { display: none; }

.filter-label {
    font-size: 12px;
    color: var(--text-dim);
    display: block;
    margin-bottom: 4px;
}

/* Filters */
#filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#filters label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}

#filters input[type="checkbox"] {
    accent-color: var(--accent);
}

.badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-table      { background: rgba(79,195,247,.2); color: var(--color-table); }
.badge-view       { background: rgba(129,199,132,.2); color: var(--color-view); }
.badge-function   { background: rgba(255,183,77,.2);  color: var(--color-function); }
.badge-procedure  { background: rgba(206,147,216,.2); color: var(--color-procedure); }

/* Schema filters */
#schema-filters-section { /* inherits from filter-panel gap */ }

/* Focused mode */
#focused-control {
    display: flex;
    align-items: center;
    gap: 8px;
}
#focused-control label {
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}
#focused-control input[type="checkbox"] { accent-color: var(--accent); }
.control-hint {
    font-size: 10px;
    color: var(--text-dim);
}

/* Direction controls */
#direction-controls { /* inherits from filter-panel gap */ }

.btn-group { display: flex; gap: 4px; }

.btn {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.active { background: rgba(79,140,255,.2); border-color: var(--accent); color: var(--accent); }

/* Depth */
#depth-control label { font-size: 12px; color: var(--text-dim); }
#depth {
    width: 100%;
    accent-color: var(--accent);
    margin-top: 4px;
}

/* View toggle */
#view-toggle { display: flex; gap: 4px; }

/* ---- Object list (fills remaining space) ---- */
#object-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

#object-list-header {
    flex-shrink: 0;
    margin-bottom: 6px;
}

#object-list h3 { font-size: 13px; color: var(--text-dim); }
#object-count { font-size: 11px; }

#object-ul {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

#object-ul li {
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background .1s;
}

#object-ul li:hover { background: rgba(79,140,255,.1); }
#object-ul li.selected { background: rgba(79,140,255,.2); }

#object-ul li .obj-type-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Object name & schema in list */
.obj-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.obj-schema {
    font-size: 10px;
    color: var(--text-dim);
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 4px;
}

/* Exclude button on list items */
.btn-exclude {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .15s, color .15s;
}

#object-ul li:hover .btn-exclude { opacity: 1; }
.btn-exclude:hover { color: #ef5350; }

/* ---- Sidebar bottom (excluded + load) ---- */
#sidebar-bottom {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Excluded objects section */
#excluded-section {
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

#excluded-toggle {
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
}

#excluded-count {
    background: var(--border);
    color: var(--text-dim);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

#excluded-list {
    margin-top: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.excluded-item {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    gap: 6px;
}

.excluded-item:hover { background: rgba(79,140,255,.1); }

/* Re-include button */
.btn-include {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color .15s;
}

.btn-include:hover { color: var(--accent-hover); }

/* Load section */
#load-section { border-top: 1px solid var(--border); padding-top: 8px; }
.btn-file {
    display: block;
    text-align: center;
    padding: 8px;
    cursor: pointer;
}

/* ---- Main ---- */
#main {
    flex: 1;
    position: relative;
    display: flex;
}

#graph {
    flex: 1;
    background: var(--bg);
}

/* Detail panel */
#detail-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 340px;
    height: 100%;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    z-index: 50;
    transition: transform .2s;
}

.hidden { display: none !important; }
#detail-panel.hidden { display: flex !important; transform: translateX(100%); pointer-events: none; }

#detail-close {
    position: absolute;
    top: 12px; right: 12px;
    background: none; border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
}
#detail-close:hover { color: var(--text); }

#detail-title { font-size: 16px; margin-bottom: 8px; word-break: break-all; }
#detail-type-badge { margin-bottom: 16px; }

#detail-columns-section h3,
#detail-lineage-section h3 {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

#detail-columns {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

#detail-columns li {
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    border-left: 3px solid transparent;
    transition: all .1s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#detail-columns li:hover { background: rgba(79,140,255,.1); border-left-color: var(--accent); }
#detail-columns li.selected { background: rgba(79,140,255,.2); border-left-color: var(--accent); }

.col-lineage-indicator {
    font-size: 11px;
    color: var(--accent);
    opacity: 0.6;
    margin-left: auto;
}

#detail-lineage-info {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
}

#detail-lineage-info .lineage-edge {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
}

#detail-lineage-info .lineage-edge .edge-label {
    font-size: 11px;
    color: var(--text-dim);
}

#detail-lineage-info .lineage-edge .edge-value {
    color: var(--text);
    font-weight: 500;
}

#detail-lineage-info .lineage-edge .edge-expr {
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px;
    color: var(--color-expression);
    margin-top: 4px;
    word-break: break-all;
}

.transformation-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
}

.transformation-badge.direct     { background: rgba(79,195,247,.2); color: var(--color-direct); }
.transformation-badge.expression { background: rgba(255,183,77,.2); color: var(--color-expression); }
.transformation-badge.rename     { background: rgba(239,83,80,.2);  color: var(--color-rename); }
.transformation-badge.reference  { background: rgba(206,147,216,.2); color: var(--color-procedure); }

/* Legend */
#legend {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 11px;
    z-index: 30;
}

.dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.dot-table     { background: var(--color-table); }
.dot-view      { background: var(--color-view); }
.dot-function  { background: var(--color-function); }
.dot-procedure { background: var(--color-procedure); }

.line {
    display: inline-block;
    width: 18px; height: 3px;
    margin-right: 4px;
    vertical-align: middle;
    border-radius: 2px;
}

.line-direct     { background: var(--color-direct); }
.line-expression { background: var(--color-expression); }
.line-rename     { background: var(--color-rename); }

.separator {
    width: 1px; height: 14px;
    background: var(--border);
}

/* Theme toggle */
#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: all .15s;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
