/* Core Design Tokens & Styles */
:root {
    --bg-main: #090d16;
    --bg-glass: rgba(17, 24, 39, 0.7);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --color-primary: #8b5cf6;
    --color-primary-light: #a78bfa;
    --color-secondary: #6366f1;
    --color-accent: #f472b6;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    
    --gradient-hero: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --gradient-accent: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.25);
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.08) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    padding: 1.5rem;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
}
::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.6);
}

/* Typography */
h1 {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #ffffff;
    margin-bottom: 0;
    line-height: 1.25;
}

h1 .title-brand-accent {
    color: #818cf8;
    font-weight: 800;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.65rem;
    font-weight: 700;
    font-family: var(--font-sans);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #818cf8;
    background: rgba(129, 140, 248, 0.1);
    border: 1px solid rgba(129, 140, 248, 0.25);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    line-height: 1;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Layout */
.app-container {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.header-icon-box {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
    transition: var(--transition-smooth);
    flex-shrink: 0;
}

.header-icon-box:hover {
    transform: scale(1.05);
    box-shadow: 0 0 22px rgba(139, 92, 246, 0.4);
}

.header-icon-box svg {
    width: 100%;
    height: 100%;
    display: block;
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.header-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.15rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Buttons */
.btn-github {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
    padding: 0.55rem 1.1rem;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-github:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(255, 255, 255, 0.08);
    transform: translateY(-1px);
}

.btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    transition: var(--transition-smooth);
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--gradient-accent);
    border: none;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #a78bfa 0%, #818cf8 100%);
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.45);
}

/* Glassmorphism Card Base */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    box-shadow: var(--shadow-premium);
    padding: 1.25rem;
    transition: var(--transition-smooth);
}

/* File Drop Zone */
.dropzone {
    border: 2px dashed rgba(139, 92, 246, 0.4);
    background: rgba(139, 92, 246, 0.02);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.dropzone::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(139, 92, 246, 0.05), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease-in-out;
}

.dropzone:hover::before {
    transform: translateX(100%);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--color-primary-light);
    background: rgba(139, 92, 246, 0.06);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.dropzone-icon {
    width: 48px;
    height: 48px;
    stroke: var(--color-primary-light);
    margin-bottom: 1rem;
    transition: var(--transition-smooth);
}

.dropzone:hover .dropzone-icon {
    transform: scale(1.1);
}

.dropzone-text {
    font-size: 1.05rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.dropzone-subtext {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* KPI Summary Dashboard */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.kpi-card {
    position: relative;
    overflow: hidden;
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-color, var(--color-primary));
}

.kpi-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.kpi-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Main Display Panels */
.dashboard-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* Settings & Controls Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.settings-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.settings-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

input[type="text"], input[type="number"], select {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-glass);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    width: 100%;
    transition: var(--transition-smooth);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--color-primary-light);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

/* Budget Progress Meter */
.budget-meter {
    margin-top: 0.5rem;
}

.budget-text-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 0.35rem;
}

.budget-bar-bg {
    background: rgba(255, 255, 255, 0.05);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255,255,255,0.03);
}

.budget-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--color-success);
    border-radius: 5px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

.budget-bar-fill.warning {
    background: var(--color-warning);
}

.budget-bar-fill.danger {
    background: var(--color-danger);
}

/* Main Content Panel (Treemap & Table) */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0; /* Prevents flex children from breaking parent layout widths */
}

.chart-card {
    position: relative;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-container {
    height: 520px;
    width: 100%;
    border-radius: 8px;
    background: rgba(10, 15, 26, 0.3);
}

/* Data Table and Search */
.table-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.table-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    max-width: 320px;
}

.search-input-wrapper input {
    padding-left: 2.25rem;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    stroke: var(--text-muted);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    text-align: left;
}

th {
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    user-select: none;
    cursor: pointer;
}

th:hover {
    color: var(--text-primary);
}

th.sort-active {
    color: var(--color-primary-light);
}

th.sort-active::after {
    content: ' ▾';
    font-size: 0.7rem;
}
th.sort-active.sort-asc::after {
    content: ' ▴';
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    white-space: nowrap;
}

tr {
    transition: var(--transition-smooth);
}

tr:hover {
    background: rgba(139, 92, 246, 0.04);
    cursor: pointer;
}

.col-mono {
    font-family: 'SFMono-Regular', Consolas, "Liberation Mono", Menlo, monospace;
}

.badge {
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--color-primary-light);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Library specific badge colors dynamically assigned */
.badge-library {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: #818cf8;
}

/* Overlay / Placeholder States */
.no-data-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 0.75rem;
    padding: 3rem;
}

.no-data-icon {
    width: 48px;
    height: 48px;
    stroke: var(--text-muted);
}

.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Responsive fixes */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    h1 {
        font-size: 1.5rem;
    }
    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }
    .table-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .search-input-wrapper {
        max-width: 100%;
    }
}

/* Segmented Control Switcher */
.segmented-control {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 3px;
    display: inline-flex;
    gap: 3px;
}

.segmented-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition-smooth);
}

.segmented-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.segmented-btn.active {
    background: var(--color-primary);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

/* Loaded Files Badges */
.file-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: 'SFMono-Regular', Consolas, monospace;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-badge.loaded {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
}

/* Multi ROM Area Cards Grid */
.rom-area-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.rom-area-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rom-area-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.rom-area-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-primary-light);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rom-area-size {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-accent);
    background: rgba(244, 114, 182, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid rgba(244, 114, 182, 0.2);
}

.rom-area-chart {
    height: 400px;
    width: 100%;
    border-radius: 6px;
    background: rgba(10, 15, 26, 0.3);
}

/* Feature Highlights & Overview Section Styles */
.features-overview {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-top: 1rem;
}

.feature-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 1.5rem;
    transition: var(--transition-smooth);
}

.feature-card:hover {
    border-color: rgba(139, 92, 246, 0.3);
    transform: translateY(-2px);
}

.feature-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(139, 92, 246, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    color: var(--color-primary-light);
}

.feature-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.feature-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.faq-container {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-top: 1rem;
}

.faq-item {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 1.25rem;
}

.faq-question {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.faq-answer {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.65;
}

/* App Footer */
.app-footer {
    margin-top: 3rem;
    padding: 1.5rem 0 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-copyright a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.footer-copyright a:hover {
    color: var(--text-primary);
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.825rem;
    transition: var(--transition-smooth);
}

.footer-link:hover {
    color: #818cf8;
}

/* ==========================================================================
   RAM Address Placement Grid Styles
   ========================================================================== */

.ram-grid-wrapper {
    background: rgba(15, 23, 42, 0.5);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1rem;
    min-width: 650px;
}

.ram-grid-ruler {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-family: 'SFMono-Regular', Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ruler-addr-label {
    width: 140px;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--text-secondary);
}

.ruler-bar-ticks {
    position: relative;
    flex: 1;
    height: 18px;
}

.ruler-bar-ticks span {
    position: absolute;
    top: 0;
    font-weight: 500;
    color: var(--text-secondary);
}

.ram-grid-rows-container {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.ram-grid-row {
    display: flex;
    align-items: center;
    height: 38px;
    background: rgba(30, 41, 59, 0.4);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    transition: var(--transition-smooth);
}

.ram-grid-row:hover {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(16, 185, 129, 0.3);
}

.ram-grid-row-label {
    width: 140px;
    flex-shrink: 0;
    padding: 0 0.75rem;
    font-family: 'SFMono-Regular', Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-success);
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.ram-grid-track {
    position: relative;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 0 6px 6px 0;
    overflow: hidden;
    padding: 3px;
    gap: 1px;
}

.ram-grid-block {
    height: 100%;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.ram-grid-block:hover {
    filter: brightness(1.25);
    transform: scaleY(1.08);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.ram-grid-block.unused {
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.02),
        rgba(255, 255, 255, 0.02) 8px,
        rgba(255, 255, 255, 0.04) 8px,
        rgba(255, 255, 255, 0.04) 16px
    );
    color: rgba(255, 255, 255, 0.25);
    font-weight: 400;
    cursor: default;
    border: 1px dashed rgba(255, 255, 255, 0.05);
}

.ram-grid-block.unused:hover {
    filter: none;
    transform: none;
    box-shadow: none;
}

/* Custom Floating Tooltip for RAM Grid */
.ram-grid-tooltip-popup {
    position: fixed;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--color-success);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    pointer-events: none;
    font-family: Inter, sans-serif;
    color: #f8fafc;
    font-size: 0.8rem;
    display: none;
}




