:root {
    --bg-color: #0c0c0e;
    --panel-bg: #141417;
    --card-bg: #1c1c1f;
    --border-color: rgba(255, 255, 255, 0.06);
    --text-primary: #ffffff;
    --text-secondary: #94949e;
    
    /* Elegant Accent Palette */
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-purple: #8b5cf6;
    --accent-orange: #f59e0b;
    
    --header-height: 80px;
    --sidebar-width: 352px;
    --card-radius: 20px;

    /* Graph (Cytoscape) colors — read by js/graph.js */
    --cy-bg: #131316;
    --node-bg: #2a2a30;
    --node-label: #ffffff;
    --node-border: rgba(255, 255, 255, 0.14);
    --edge-color: rgba(255, 255, 255, 0.13);
    --group-fill: #ffffff;
    --group-border: rgba(255, 255, 255, 0.12);
    --group-label: rgba(255, 255, 255, 0.45);

    /* Canvas atmosphere */
    --grid-dot: rgba(255, 255, 255, 0.045);
    --card-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.25);

    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

/* Light theme — applied when the <body> is NOT .dark-theme */
body:not(.dark-theme) {
    --bg-color: #f4f4f6;
    --panel-bg: #ffffff;
    --card-bg: #ffffff;
    --border-color: rgba(0, 0, 0, 0.08);
    --text-primary: #18181b;
    --text-secondary: #6b6b76;

    --cy-bg: #fbfbfd;
    --node-bg: #d9d9e1;
    --node-label: #18181b;
    --node-border: rgba(0, 0, 0, 0.14);
    --edge-color: rgba(0, 0, 0, 0.22);
    --group-fill: #1e1e28;
    --group-border: rgba(0, 0, 0, 0.14);
    --group-label: rgba(0, 0, 0, 0.5);

    --grid-dot: rgba(0, 0, 0, 0.05);
    --card-shadow: 0 1px 2px rgba(17,17,26,0.06), 0 8px 24px rgba(17,17,26,0.06);
}

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

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    /* Breathing space above the top bar (border-box keeps #app within the viewport) */
    padding-top: 24px;
    overflow: hidden;
    letter-spacing: -0.01em;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    height: var(--header-height);
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 48px;
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

header h1.wordmark {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.wordmark .mark {
    fill: var(--accent-green);
    stroke: var(--accent-green);
    stroke-width: 1.5;
    flex: none;
}
.wordmark .mark path { stroke: var(--accent-green); fill: none; opacity: 0.55; }

.wordmark-sub {
    font-weight: 400;
    color: var(--text-secondary);
    opacity: 0.7;
    margin-left: 8px;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.actions {
    display: flex;
    gap: 16px;
}

button {
    background: var(--text-primary);
    color: var(--bg-color);
    border: 1px solid transparent;
    padding: 9px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

button:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}
button:active { transform: translateY(0); }

button.secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
}

button.secondary:hover {
    background: rgba(127, 127, 127, 0.08);
    color: var(--text-primary);
    border-color: rgba(127, 127, 127, 0.3);
}

main {
    flex: 1;
    /* min-height:0 lets this flex item shrink to the viewport so #controls can scroll
       instead of expanding to its content height and overflowing the page. */
    min-height: 0;
    display: flex;
    position: relative;
    padding: 24px;
    gap: 24px;
}

#cy-container {
    flex: 1;
    background-color: var(--panel-bg);
    background-image: radial-gradient(circle at 1px 1px, var(--grid-dot) 1px, transparent 0);
    background-size: 22px 22px;
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    position: relative;
    overflow: hidden;
}

/* Soft vignette so nodes near the edges recede a touch */
#cy-container::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.18) 100%);
}
body:not(.dark-theme) #cy-container::after {
    background: radial-gradient(ellipse at center, transparent 60%, rgba(17,17,26,0.04) 100%);
}

#cy {
    position: absolute;
    inset: 0;
    z-index: 1;
}

#controls {
    width: var(--sidebar-width);
    flex: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding-right: 8px; /* For custom scrollbar space */
}

/* Custom Scrollbar for Sidebar */
#controls { scrollbar-width: thin; scrollbar-color: rgba(127,127,127,0.35) transparent; }
#controls::-webkit-scrollbar { width: 8px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb {
    background: rgba(127, 127, 127, 0.3);
    border-radius: 10px;
}
#controls::-webkit-scrollbar-thumb:hover { background: rgba(127, 127, 127, 0.5); }

section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 600;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--card-shadow);
}

/* Dashboard Specifics */
.module-info-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.module-name-lg {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.module-pkg-sm {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.metric-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.metric-sub {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    width: fit-content;
}

/* Colors for metrics */
.blue { color: var(--accent-blue); }
.green { color: var(--accent-green); }
.purple { color: var(--accent-purple); }
.orange { color: var(--accent-orange); }

.toggle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-label {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Grouped configuration card */
.config-card {
    gap: 0;
    padding: 4px 16px;
}
.config-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 0;
}
.config-group + .config-group {
    border-top: 1px solid var(--border-color);
}
.config-group-title {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 0.7;
}
.slider-item { display: flex; flex-direction: column; }
.slider-head { display: flex; justify-content: space-between; }
.slider-val {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.config-card input[type="range"] { margin-top: 8px; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    margin-top: 14px;
    border-radius: 4px;
    background: rgba(127, 127, 127, 0.22);
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 3px solid var(--card-bg);
    box-shadow: 0 0 0 1px var(--border-color);
    transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 3px solid var(--card-bg);
}

/* Accent the checkboxes to match the theme */
input[type="checkbox"] {
    accent-color: var(--accent-green);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

#loader {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: 2px solid var(--text-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* Group Input Styling */
.input-field {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    color: white;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-field:focus {
    border-color: var(--text-secondary);
}

/* Cycle / analysis results */
#analysis-results { margin-top: 12px; font-size: 0.8125rem; }
.cycle-found {
    color: var(--accent-orange);
    font-weight: 600;
}
#analysis-results ul { list-style: none; }
#analysis-results li {
    padding: 6px 10px;
    margin-top: 6px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.08);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
}

/* Smooth theme switching */
body, .card, header, #cy-container, button, .input-field {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

/* Legend */
.legend-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.legend-row code {
    font-size: 0.75rem;
    background: rgba(127, 127, 127, 0.18);
    padding: 1px 5px;
    border-radius: 4px;
    color: var(--text-primary);
}
.legend-line {
    flex: 0 0 28px;
    height: 0;
    border-top-width: 2px;
    border-top-style: solid;
    border-color: var(--text-secondary);
}
.legend-line.solid  { border-top-color: var(--text-secondary); }
.legend-line.dashed { border-top-style: dashed; }
.legend-line.dotted { border-top-style: dotted; }
.legend-line.api    { border-top-color: var(--accent-orange); border-top-width: 3px; }
.legend-line.cycle  { border-top-color: #ef4444; border-top-width: 3px; }
.legend-swatch {
    flex: 0 0 28px;
    height: 10px;
    border-radius: 3px;
    background: linear-gradient(90deg, hsl(210,75%,55%), hsl(120,75%,55%), hsl(0,75%,55%));
}

/* Group action panel */
.group-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}
.group-action-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.75rem;
    padding: 7px 12px;
    border-radius: 9px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.group-action-btn:hover {
    background: rgba(127, 127, 127, 0.08);
    color: var(--text-primary);
    border-color: rgba(127, 127, 127, 0.3);
    transform: translateY(-1px);
}
.group-action-btn.danger:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.08);
}
/* Recolor swatch button wraps a native color input */
.recolor-btn { position: relative; overflow: hidden; }
.recolor-btn input[type="color"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}

/* Instability gauge (efferent / total coupling) */
.instability-bar {
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    background: rgba(127, 127, 127, 0.15);
}
.instability-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-orange), #ef4444);
}

/* Clickable cycle entries */
#analysis-results li { cursor: pointer; transition: background 0.15s ease; }
#analysis-results li:hover { background: rgba(245, 158, 11, 0.16); }

/* Orchestrated page-load reveal */
@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}
#cy-container { animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards; }
#controls section { animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards; }
#controls section:nth-child(1) { animation-delay: 0.06s; }
#controls section:nth-child(2) { animation-delay: 0.12s; }
#controls section:nth-child(3) { animation-delay: 0.18s; }
#controls section:nth-child(4) { animation-delay: 0.24s; }
#controls section:nth-child(5) { animation-delay: 0.30s; }
#controls section:nth-child(6) { animation-delay: 0.36s; }
#controls section:nth-child(7) { animation-delay: 0.42s; }

@media (prefers-reduced-motion: reduce) {
    #cy-container, #controls section { animation: none; }
    body, .card, header, button, .input-field { transition: none; }
}
