#grid-container {
    padding: 0 8px 16px 8px;
    min-width: 0;
    position: relative;
}

#stats-bar {
    position: relative;
    margin: 0 auto 12px auto;
    max-width: 80vw;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 0.95rem;
    color: #2c3e50;
}
#stats-bar .stat strong { margin-right: 6px; }

/* Gesamtkosten optisch hervorheben und Items ohne Kommas trennen */
#costs-line { font-size: 1.05rem; }
#costs-line .costs-items { display: inline-flex; gap: 12px; align-items: center; }
/* Make cost icons larger relative to text and remove extra spacing */
#costs-line img {
    width: 1.3em !important;
    height: 1.3em !important;
    margin: 0 !important;
    vertical-align: -0.15em; /* slight baseline nudge without layout shifts */
    position: static;
}

/* Slight vertical nudge for header action icons */
.title-actions img,
#btn-abriss img,
#btn-undo img,
#btn-redo img {
    position: static;
    vertical-align: middle;
}

/* Ensure icon-only buttons align nicely in text lines */
#btn-abriss,
#btn-undo,
#btn-redo {
    line-height: 0;
    height: 28px; /* matches icon size */
    vertical-align: middle;
}

#layout-grid {
    position: relative; /* anchor for absolute overlays */
    left: 50%;
    transform: translateX(-50%);
}

#layout-grid {
    margin-right: 80px;
}

#layout-grid {
    display: grid;
    grid-template-columns: repeat(15, 24px);
    grid-template-rows: repeat(15, 24px);
    grid-auto-rows: 24px;
    grid-auto-columns: 24px;
    gap: 0;
    background: #e8e8e8;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    width: fit-content;
}

.grid-cell {
    width: 24px;
    height: 24px;
    background: #fff;
    /* Hide internal borders by default; edges will be drawn via b-* classes */
    border: 1px solid transparent;
    box-sizing: border-box;
    border-radius: 0;
    transition: background 0.2s;
}
/* Show faint grid lines on empty cells only */
.grid-cell:not(.occupied) {
    border-color: #e0e0e0;
}
.grid-cell:hover {
    background: #d0e6ff;
    }
/* Preview while placing */
.grid-cell.preview-ok { background: #cfead1 !important; }
.grid-cell.preview-bad { background: #f5c9c9 !important; }
/* Placed building overlay */
/* We now render a single absolutely positioned .building-overlay per placed building
    that spans its full footprint and shows the icon centered. (Legacy .placed-building
    implementation removed) */
.placed-building { display: none; } /* legacy hook – kept empty for backwards compatibility */
/* Selected building in menu */
.building-item.selected {
    background: #9bc5ff;
    border-radius: 4px;
}

/* Per-type cell colors */
.grid-cell.cell-utility        { background: rgba(158,158,158,0.45); }
.grid-cell.cell-baumaterial    { background: rgba(244,67,54,0.35); }
.grid-cell.cell-beduerfnis     { background: rgba(255,235,59,0.45); }
.grid-cell.cell-landwirtschaft { background: rgba(76,175,80,0.35); }
.grid-cell.cell-zwischen       { background: rgba(33,150,243,0.35); }
.grid-cell.cell-unknown        { background: rgba(120,120,120,0.25); }
/* Removed unused classes: .cell-sekundaer & .cell-dual-agrar-bau (single-color system now) */

/* Sidebar Styles */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: #f4f4f4;
    box-shadow: 2px 0 8px rgba(0,0,0,0.07);
    padding-top: 12px;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    z-index: 10;
}
/* Right Sidebar Styles */
#rightbar {
    position: fixed;
    top: 0;
    right: 0;
    width: 260px;
    height: 100vh;
    background: #f4f4f4;
    box-shadow: -2px 0 8px rgba(0,0,0,0.07);
    padding-top: 12px;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    z-index: 10;
}
#sidebar .sidebar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
    margin: 0 16px 12px 16px;
}
/* Actions under the Baumenü heading */
.title-actions { display:inline-flex; gap:8px; align-items:center; }
.title-actions.under-title { margin: 4px 16px 8px 16px; }
#btn-undo:disabled, #btn-redo:disabled { opacity:0.35; cursor:default; }
/* Search field under Baumenü */
.search-wrapper { margin: 0 16px 12px 16px; }
#building-search {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #bbb;
    border-radius: 4px;
    background: #fff;
    font-size: 0.9rem;
}
#building-search:focus { outline: 2px solid #2c7be5; }
.empty-search {
    padding: 6px 16px;
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
}
/* Search results list */
#search-results {
    list-style: none;
    margin: 6px 0 0 0;
    padding: 4px 0;
    max-height: 220px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
#search-results .search-result-item {
    padding: 4px 10px;
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 1.3;
}
#search-results .search-result-item:hover {
    background: #e9f2ff;
}
#search-results .search-result-empty {
    padding: 6px 10px;
    font-size: 0.85rem;
    color: #777;
}
#sidebar .sidebar-subtitle {
    font-size: 0.95rem;
    font-weight: 600;
    color: #333;
    margin: 16px 16px 8px 16px;
}
#building-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}
#building-menu > li {
    margin-bottom: 8px;
}
.menu-type {
    font-weight: bold;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 6px;
    background: #e0e0e0;
    transition: background 0.2s;
}
.menu-type:hover {
    background: #d0d0d0;
}
.building-list {
    display: none;
    margin-left: 16px;
    margin-top: 4px;
}
.building-list.open {
    display: block;
}
.building-item {
    padding: 4px 0 4px 12px;
    font-size: 1rem;
    color: #333;
    cursor: pointer;
}
#grid-controls {
    padding: 8px 16px 16px 16px;
    border-top: 1px solid #e0e0e0;
}
/* Layout controls */
#layout-controls {
    padding: 8px 16px 8px 16px;
}
#layout-controls .status-line {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: #fafafa;
    border: 1px solid #ddd;
    padding: 4px 6px;
    border-radius: 4px;
}
#save-feedback.visible { opacity:1 !important; }
#layout-controls .layout-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
#layout-controls .layout-row.compact {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}
#layout-controls input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}
#layout-controls .icon-actions { display: flex; gap: 6px; }
.icon-button {
    padding: 4px 8px;
    background: #2c7be5;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
}
.icon-button:hover { background: #1f66c1; }

/* Make Abriss/Undo/Redo icon-only (no border/background) */
#btn-abriss,
#btn-undo,
#btn-redo {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
#btn-abriss:hover,
#btn-undo:hover,
#btn-redo:hover {
    background: transparent !important;
}
#btn-abriss img,
#btn-undo img,
#btn-redo img {
    width: 32px;
    height: 32px;
    display: block;
}
/* Package panel styling */
#package-panel {
    margin-top: 8px;
}
#package-panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 4px;
}
#package-panel .layout-row.compact { margin-bottom: 6px; }
#package-list {
    margin-left: 0;
}
#package-list li { padding: 4px 6px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#package-list li.selected {
    background: #e9f2ff;
    border-radius: 4px;
}
#package-list li.dragover { outline: 2px dashed #2c7be5; }
#package-list li.dragging { opacity: 0.5; }
#package-list li .name { flex: 1; }
#package-list li .row-actions { display: inline-flex; gap: 4px; }
#package-list li .row-actions .icon-button { padding: 2px 6px; }
#grid-size-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#grid-size-form label {
    font-size: 0.9rem;
    color: #555;
}
#grid-size-form input[type="number"] {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}
#grid-size-form button[type="submit"] {
    margin-top: 8px;
    padding: 8px 12px;
    background: #2c7be5;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
#grid-size-form button[type="submit"]:hover {
    background: #1f66c1;
}
main {
    margin-left: 260px;
    margin-right: 260px; /* make room for right sidebar */
    padding: 24px;
}
/* Legal footer */
#legal-footer {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    padding: 6px 12px;
    background: rgba(0,0,0,0.35);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    color: #eee;
    font-size: 0.9rem;
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
#legal-footer a { color: #f0f0f0; text-decoration: none; }
#legal-footer a:hover { text-decoration: underline; }
#legal-footer .sep { opacity: .7; }
#legal-footer .attribution { font-size: 0.75rem; opacity: 0.85; white-space: nowrap; }
#legal-footer .attribution:hover { opacity: 1; }

/* Legal pages container helper (used inline too) */
.legal-page { max-width: 900px; margin: 120px auto 80px; padding: 0 16px; color: #eee; }
.legal-page h1 { margin-bottom: 8px; }
.legal-page h2 { margin-top: 24px; }
/* moved #headtitle styling above with header */
body {
    margin: 0;
    /* Subtle page background with a light overlay for readability */
    background-image: linear-gradient(rgba(255,255,255,0.60), rgba(255,255,255,0.60)), url('assets/background.webp');
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
}

/* Header wallpaper integration */
:root { --header-height: 100px; }

header {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-image: url('assets/header.webp');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Responsives Header-Höhen-Tuning */
@media (max-width: 1200px) {
    :root { --header-height: 140px; }
}
@media (max-width: 768px) {
    :root { --header-height: 120px; }
}
/* subtle dark overlay for readability */
header::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.25), rgba(0,0,0,0.25));
    pointer-events: none;
}

#headtitle {
    position: relative; /* above overlay */
    margin: 0;
    padding: 8px 20px;
    font-size: 2rem;
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #fff;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    text-align: center;
    text-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

/* Top-left Anno logo */
#header-logo {
    position: absolute;
    top: 10px;
    left: 12px;
    height: calc(var(--header-height) * 0.68);
    width: auto;
    object-fit: contain;
    z-index: 1; /* above overlay */
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}

/* Ensure the collapse/expand always wins over other rules */
.building-list { display: none !important; }
.building-list.open { display: block !important; }

/* No additional offset needed under header */

/* Black outline around buildings: draw on edges between different ids or to empty */
.grid-cell.b-top { border-top-color: #000; }
.grid-cell.b-right { border-right-color: #000; }
.grid-cell.b-bottom { border-bottom-color: #000; }
.grid-cell.b-left { border-left-color: #000; }

/* Grid-spanning overlay for building icons */
.building-overlay { pointer-events: none; z-index: 2; }
/* Abriss Button Aktivzustand: highlight icon subtly */
#btn-abriss.active img { filter: drop-shadow(0 0 4px rgba(183,28,28,0.7)); }
