/* ============================================================================
   REALonline Rauminventar-Analyse - Stylesheet
   Based on DESIGN.md Specification
   ============================================================================ */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Graustufen-Basis */
    --gray-900: #1a1a1a;
    --gray-600: #666666;
    --gray-400: #999999;
    --gray-100: #e5e5e5;
    --gray-50: #fafafa;

    /* Akzentfarbe */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-active: #1e40af;

    /* Semantische Farben */
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;

    /* Schatten-System (Elevation) */
    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.16);
    --shadow-3: 0 4px 12px rgba(0, 0, 0, 0.20);

    /* Spacing (8px Grid) */
    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;

    /* Border-Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* Typography */
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
}

body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    color: var(--gray-900);
    background: var(--gray-50);
    min-height: 100vh;
    margin: 0;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================================
   HEADER
   ============================================================================ */
header {
    background: var(--primary);
    color: white;
    padding: var(--space-3) var(--space-4);
    text-align: center;
    box-shadow: var(--shadow-1);
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 var(--space-1) 0;
}

.subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
}

/* ============================================================================
   LOADING STATE
   ============================================================================ */
.loading {
    text-align: center;
    padding: var(--space-4) var(--space-3);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-100);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto var(--space-2);
    animation: spin 1s linear infinite;
}

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

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    margin: var(--space-2) auto;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease-out;
}

/* ============================================================================
   CONTEXT BAR (Persistent)
   ============================================================================ */
.context-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: white;
    border-bottom: 1px solid var(--gray-100);
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    box-shadow: var(--shadow-1);
}

.context-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 14px;
    color: var(--gray-600);
    font-weight: 500;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
}

.breadcrumb-item::after {
    content: '›';
    margin-left: var(--space-1);
    color: var(--gray-400);
}

.breadcrumb-item:last-child {
    color: var(--gray-900);
}

.breadcrumb-item:last-child::after {
    display: none;
}

.context-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

#context-search {
    width: 100%;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}

#context-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-100);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    box-shadow: var(--shadow-2);
    z-index: 1000;
}

.search-suggestions.active {
    display: block;
}

.search-suggestion {
    padding: var(--space-1) var(--space-2);
    cursor: pointer;
    transition: background 150ms ease-out;
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.search-suggestion:hover,
.search-suggestion.highlighted {
    background: var(--gray-50);
}

.search-suggestion-type {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    min-width: 60px;
}

.search-suggestion-value {
    flex: 1;
    font-size: 14px;
    color: var(--gray-900);
}

.filter-badges {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
}

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 4px var(--space-2);
    background: var(--primary);
    color: white;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.filter-badge-label {
    opacity: 0.9;
}

.filter-badge-value {
    font-weight: 600;
}

.filter-badge-remove {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    margin-left: 2px;
    opacity: 0.8;
    transition: opacity 150ms ease-out;
}

.filter-badge-remove:hover {
    opacity: 1;
}

.data-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    white-space: nowrap;
}

#data-count {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    font-family: var(--font-mono);
}

/* ============================================================================
   THREE-COLUMN LAYOUT
   ============================================================================ */
.layout-three-column {
    display: grid;
    grid-template-columns: 240px 1fr 320px;
    gap: 0;
    flex: 1;
    min-height: 0;
}

/* Left Sidebar - Context & Filters */
.sidebar-left {
    background: var(--gray-50);
    border-right: 1px solid var(--gray-100);
    padding: var(--space-3);
    overflow-y: auto;
}

/* Main Content Area */
.content-main {
    padding: var(--space-3);
    overflow-y: auto;
}

/* Right Sidebar - Details */
.sidebar-right {
    background: var(--gray-50);
    border-left: 1px solid var(--gray-100);
    padding: var(--space-3);
    overflow-y: auto;
}

/* ============================================================================
   STATS GRID
   ============================================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.stat-card {
    background: white;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-100);
    text-align: center;
}

.stat-card h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--primary);
    margin: 0 0 4px 0;
    font-family: var(--font-mono);
}

.stat-card p {
    font-size: 12px;
    color: var(--gray-600);
    margin: 0;
}

/* ============================================================================
   FILTERS
   ============================================================================ */
.filters {
    background: white;
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-100);
}

.filters h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 var(--space-3) 0;
}

.filter-group {
    margin-bottom: var(--space-2);
}

.filter-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: var(--space-1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group select,
.filter-group input {
    width: 100%;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--gray-900);
    background: white;
    transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.filter-group select option:disabled {
    color: var(--gray-400);
}

.filter-actions {
    display: flex;
    gap: var(--space-1);
    margin-top: var(--space-3);
}

.filter-results {
    display: block;
    margin-top: var(--space-2);
    font-size: 12px;
    color: var(--gray-600);
    font-weight: 500;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */
.btn {
    padding: var(--space-1) var(--space-2);
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms ease-out, box-shadow 150ms ease-out;
    font-family: var(--font-body);
}

.btn-primary {
    background: var(--primary);
    color: white;
    flex: 1;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:active {
    background: var(--primary-active);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-900);
    flex: 1;
}

.btn-secondary:hover {
    background: var(--gray-400);
    color: white;
}

.btn-small {
    padding: 6px var(--space-2);
    font-size: 12px;
}

/* ============================================================================
   TABS
   ============================================================================ */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--gray-100);
    margin-bottom: var(--space-3);
}

.tab-btn {
    padding: var(--space-2) var(--space-3);
    border: none;
    background: none;
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 150ms ease-out, border-color 150ms ease-out;
}

.tab-btn:hover {
    color: var(--gray-900);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    position: relative;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.tab-pane h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 var(--space-3) 0;
}

/* ============================================================================
   CHARTS
   ============================================================================ */
.chart-container {
    margin-bottom: var(--space-4);
}

.chart-bars {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.chart-bar-group {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: background 150ms ease-out;
}

.chart-bar-group[data-type] {
    cursor: pointer;
}

.chart-bar-group[data-type]:hover {
    background: var(--gray-50);
}

.chart-bar-label {
    font-size: 14px;
    color: var(--gray-900);
    text-align: right;
    font-weight: 500;
}

.chart-bar-container {
    position: relative;
    height: 24px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chart-bar {
    height: 100%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: var(--space-1);
    transition: width 300ms ease-out, background 150ms ease-out;
    min-width: 30px;
}

.chart-bar-group:hover .chart-bar {
    background: var(--primary-hover);
}

.chart-bar-value {
    color: white;
    font-weight: 600;
    font-size: 12px;
    font-family: var(--font-mono);
}

/* ============================================================================
   TABLES
   ============================================================================ */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-100);
}

thead th {
    padding: var(--space-2);
    text-align: left;
    font-weight: 600;
    color: var(--gray-900);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background 150ms ease-out;
}

tbody tr:nth-child(even) {
    background: var(--gray-50);
}

tbody tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

tbody td {
    padding: var(--space-2);
    color: var(--gray-900);
}

/* ============================================================================
   DETAILS PANEL (Right Sidebar)
   ============================================================================ */
.details-panel {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    border: 1px solid var(--gray-100);
}

.details-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 var(--space-3) 0;
}

.details-content {
    font-size: 14px;
    color: var(--gray-600);
}

.details-placeholder {
    color: var(--gray-400);
    font-style: italic;
}

/* ============================================================================
   EXPORT & ACTIONS
   ============================================================================ */
.export-actions {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
}

/* ============================================================================
   RAW DATA DISPLAY
   ============================================================================ */
.raw-data {
    background: var(--gray-50);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 12px;
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
    border: 1px solid var(--gray-100);
}

/* ============================================================================
   HIERARCHY TREE
   ============================================================================ */
#hierarchy-tree {
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.8;
}

.parent-item {
    margin-bottom: var(--space-3);
}

.parent-name {
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: color 150ms ease-out;
}

.parent-name:hover {
    color: var(--primary-hover);
}

.children-list {
    margin-left: var(--space-3);
    margin-top: var(--space-1);
}

.child-item {
    color: var(--gray-600);
    padding-left: var(--space-2);
    border-left: 2px solid var(--gray-100);
    margin-bottom: var(--space-1);
}

/* ============================================================================
   FOOTER
   ============================================================================ */
footer {
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
    padding: var(--space-3);
    text-align: center;
    font-size: 12px;
    color: var(--gray-600);
}

footer a {
    color: var(--primary);
    text-decoration: none;
    transition: color 150ms ease-out;
}

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

/* ============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================ */

/* Tablet (768-1200px) */
@media (max-width: 1200px) {
    .layout-three-column {
        grid-template-columns: 200px 1fr;
    }

    .sidebar-right {
        display: none;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .chart-bar-group {
        grid-template-columns: 120px 1fr;
    }
}

/* Mobile (<768px) */
@media (max-width: 768px) {
    .layout-three-column {
        grid-template-columns: 1fr;
    }

    .sidebar-left {
        border-right: none;
        border-bottom: 1px solid var(--gray-100);
    }

    .context-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .context-actions {
        flex-direction: column;
    }

    .search-box {
        max-width: 100%;
    }

    .chart-bar-group {
        grid-template-columns: 1fr;
    }

    .chart-bar-label {
        text-align: left;
        margin-bottom: 4px;
    }

    /* Touch-optimized targets */
    .btn {
        min-height: 44px;
    }

    .tab-btn {
        min-height: 44px;
    }
}

/* ============================================================================
   TREEMAP VISUALIZATION
   ============================================================================ */
.treemap-wrapper {
    width: 100%;
    height: calc(100vh - 280px); /* Dynamic height based on viewport */
    min-height: 600px;
    background: white;
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.treemap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-100);
    flex-shrink: 0; /* Prevent header from shrinking */
}

/* Treemap Legend */
.treemap-legend {
    padding: var(--space-2) var(--space-3);
    background: white;
    border-bottom: 1px solid var(--gray-100);
    flex-shrink: 0;
}

.treemap-legend h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
    margin: 0 0 var(--space-2) 0;
}

.legend-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-2);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 13px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.legend-label {
    font-weight: 600;
    color: var(--gray-900);
    white-space: nowrap;
}

.legend-description {
    color: var(--gray-600);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.treemap-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 14px;
    color: var(--gray-600);
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.breadcrumb-item {
    color: var(--gray-900);
    font-weight: 600;
}

.breadcrumb-item.clickable {
    color: var(--primary);
    cursor: pointer;
    transition: color 150ms ease-out;
}

.breadcrumb-item.clickable:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.breadcrumb-separator {
    color: var(--gray-400);
    user-select: none;
}

.treemap-zoom-out {
    background: white;
    border: 1px solid var(--gray-100);
    padding: var(--space-1) var(--space-2);
    font-size: 12px;
    transition: all 150ms ease-out;
}

.treemap-zoom-out:hover {
    background: var(--gray-50);
    border-color: var(--primary);
}

.treemap-container {
    flex: 1; /* Take remaining space */
    overflow: hidden;
    position: relative;
}

.treemap-svg {
    display: block;
    background: var(--gray-50);
    width: 100%;
    height: 100%;
}

/* Building containers - nested treemap */
.treemap-building-container {
    transition: opacity 150ms ease-out;
}

.treemap-building-container:hover {
    opacity: 1;
}

/* Room rectangles */
.treemap-room rect {
    transition: all 150ms ease-out;
}

.treemap-room:hover rect {
    filter: brightness(1.1);
}

/* General nodes */
.treemap-node {
    transition: all 150ms ease-out;
    cursor: pointer;
}

.treemap-node:hover rect {
    stroke-width: 3 !important;
    filter: brightness(1.05);
}

/* Text labels */
.treemap-node text,
.treemap-building-container text,
.treemap-room text {
    user-select: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
}

.view-toggle .btn {
    background: white;
    border: 1px solid var(--gray-100);
    color: var(--gray-600);
}

.view-toggle .btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */
.info {
    padding: var(--space-2);
    background: rgba(37, 99, 235, 0.1);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--gray-900);
    margin-bottom: var(--space-3);
}
