/* HOI4 Division Designer Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Screen Reader Only - for SEO and accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    overflow: hidden;
    height: 100vh;
}

.hoi4-window {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #2a2a2a;
}

/* Title Bar */
.hoi4-title-bar {
    background: linear-gradient(to bottom, #3a3a3a, #2a2a2a);
    border-bottom: 2px solid #4a4a4a;
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 40px;
    flex-wrap: wrap;
    gap: 10px;
}

.title-bar-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.hoi4-title {
    font-size: 14px;
    font-weight: bold;
    color: #e0e0e0;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hoi4-title .title-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.title-bar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.hoi4-close-btn:hover {
    background: #4a4a4a;
}

/* Main Content */
.hoi4-main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left Panel */
.hoi4-left-panel {
    width: 60%;
    background: #2a2a2a;
    border-right: 2px solid #4a4a4a;
    display: flex;
    flex-direction: column;
    padding: 15px;
    overflow-y: auto;
}

/* Right Panel - Stats */
.hoi4-right-panel {
    width: 40%;
    background: #1a1a1a;
    overflow-y: auto;
    padding: 15px;
}

.hoi4-division-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.division-header-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.division-icon-selector {
    width: 40px;
    height: 40px;
    background: #353535;
    border: 2px solid #4a4a4a;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.division-icon-selector:hover {
    border-color: #6a6a6a;
    background: #404040;
}

.division-icon-display {
    font-size: 24px;
    line-height: 1;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.division-icon-image {
    width: 125%;
    height: 125%;
    object-fit: contain;
    image-rendering: crisp-edges;
}

.division-icon-fallback {
    font-size: 24px;
    line-height: 1;
}

.division-icon-picker-image {
    width: 64px;
    height: 64px;
    object-fit: contain;
    image-rendering: crisp-edges;
}

.division-name-input {
    flex: 1;
    min-width: 150px;
}

.division-name-input input {
    background: #353535;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 6px 10px;
    border-radius: 3px;
    font-size: 13px;
    width: 100%;
}

.year-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.year-selector label {
    color: #a0a0a0;
    font-size: 12px;
}

.year-select {
    background: #353535;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 6px 10px;
    border-radius: 3px;
    font-size: 13px;
    cursor: pointer;
}

.year-select:hover {
    border-color: #6a6a6a;
}

.year-select:focus {
    outline: none;
    border-color: #7a9fff;
}

/* Section Header */
.section-header {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    justify-content: flex-start;
    align-items: center;
}

.section-label {
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 15px;
}

/* Ensure h1 doesn't break layout */
h1.sr-only {
    margin: 0;
    padding: 0;
}

/* Support and Combat Container */
.support-combat-container {
    display: flex;
    gap: 10px;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 0 3px 3px 3px;
    padding: 15px;
    min-height: 400px;
}

.support-column {
    width: 70px;
    flex-shrink: 0;
}

.combat-column {
    flex: 1;
    min-width: 0;
}

/* Slot Grid */
.slot-grid {
    display: grid;
    gap: 8px;
}

.support-slots {
    grid-template-columns: repeat(1, 1fr);
}

.combat-slots {
    grid-template-columns: repeat(5, 1fr);
}

.slot {
    width: 100%;
    height: 60px;
    background: #353535;
    border: 2px dashed #4a4a4a;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    aspect-ratio: 1;
}

.support-slots .slot {
    height: 60px;
    width: 60px;
}

.slot:hover {
    border-color: #6a6a6a;
    background: #404040;
}

.slot.filled {
    border: 2px solid #5a8a5a;
    background: #2a4a2a;
}

.slot.add-slot {
    border-style: solid;
    border-color: #4a4a4a;
}

.slot.add-slot .slot-icon {
    font-size: 48px;
    font-weight: bold;
    color: #8a8a8a;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot.locked {
    background: #1a1a1a;
    border-color: #2a2a2a;
    cursor: not-allowed;
    opacity: 0.5;
}

.slot.locked .slot-icon {
    font-size: 32px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot.large-slot {
    grid-column: 1 / -1;
    height: 80px;
    margin-top: 8px;
    aspect-ratio: auto;
}

.slot-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.slot-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 32px;
}

.unit-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

/* Make combat unit icons slightly smaller to reduce pixelation */
.combat-slots .unit-image {
    padding: 8px;
}

.unit-image-modal {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.slot-icon-fallback {
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Actions */
/* Terrain Effects Section */
.terrain-effects-section {
    margin-top: 15px;
    padding: 15px;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
}

.terrain-effects-section .section-label {
    font-size: 13px;
    font-weight: bold;
    color: #c0c0c0;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.terrain-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.terrain-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: #353535;
    border: 1px solid #4a4a4a;
    border-radius: 2px;
    font-size: 12px;
    gap: 0px;
}

.terrain-name {
    color: #e0e0e0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}

.terrain-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    image-rendering: crisp-edges;
    flex-shrink: 0;
}

.terrain-values-container {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.terrain-modifier {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 50px;
}

.terrain-mod-label {
    font-size: 10px;
    color: #a0a0a0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.terrain-mod-value-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.terrain-mod-value {
    font-weight: bold;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.terrain-mod-value.positive {
    color: #90ee90;
}

.terrain-mod-value.negative {
    color: #ff6b6b;
}

.terrain-mod-value.neutral {
    color: #e0e0e0;
}

.hoi4-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #4a4a4a;
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}


.saved-templates-section {
    display: flex;
    gap: 5px;
    align-items: center;
    flex: 1;
    min-width: 180px;
}

/* Custom Dropdown for Templates */
.custom-dropdown {
    position: relative;
    min-width: 180px;
}

.dropdown-header {
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 5px 8px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.dropdown-header:hover {
    border-color: #6a6a6a;
    background: #353535;
}

.dropdown-arrow {
    font-size: 10px;
    margin-left: 8px;
    opacity: 0.7;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    margin-top: 2px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.dropdown-option {
    padding: 8px 10px;
    color: #e0e0e0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    border-bottom: 1px solid #3a3a3a;
}

.dropdown-option:last-child {
    border-bottom: none;
}

.dropdown-option:hover {
    background: #353535;
}

.dropdown-option.load-template {
    font-style: italic;
    opacity: 0.7;
}

.dropdown-section-header {
    font-weight: bold;
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 10px 4px 10px;
    cursor: default;
    pointer-events: none;
    border-top: 1px solid #4a4a4a;
    margin-top: 4px;
}

.dropdown-section-header:first-of-type {
    border-top: none;
    margin-top: 0;
}

.dropdown-option.preset-template {
    opacity: 0.95;
}

.dropdown-option-name {
    flex: 1;
}

.dropdown-option-delete {
    margin-left: 10px;
    padding: 2px 6px;
    background: transparent;
    border: none;
    color: #ff6b6b;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.7;
    border-radius: 2px;
}

.dropdown-option-delete:hover {
    opacity: 1;
    background: #5a2a2a;
}

.dropdown-template-counter {
    padding: 8px 10px;
    font-size: 11px;
    color: #a0a0a0;
    text-align: center;
    border-top: 1px solid #3a3a3a;
    background: #1a1a1a;
    font-style: italic;
}

.dropdown-template-counter.caution {
    color: #ffa500;
}

.dropdown-template-counter.warning {
    color: #ff6b6b;
    font-weight: 600;
}

.saved-templates-dropdown {
    display: none; /* Hide old select, keeping for backwards compatibility */
}

.hoi4-btn.delete-btn {
    padding: 5px 8px;
    font-size: 14px;
    min-width: auto;
}

.hoi4-btn.delete-btn:hover {
    background: #5a2a2a;
    border-color: #7a3a3a;
}

.hoi4-btn {
    background: #353535;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 5px 12px;
    cursor: pointer;
    font-size: 12px;
    border-radius: 3px;
    white-space: nowrap;
}

.hoi4-btn:hover {
    background: #404040;
}

/* Comparison Grid button - better contrast for icon */
#compare-all-btn {
    background: #2a3a2a;
    border-color: #4a6a4a;
    color: #c0d0c0;
}

#compare-all-btn:hover {
    background: #3a4a3a;
    border-color: #5a8a5a;
}

#compare-all-btn img {
    filter: brightness(1.2) contrast(1.1);
}

.hoi4-btn.primary {
    background: #4a6a4a;
    border-color: #5a8a5a;
}

.hoi4-btn.primary:hover {
    background: #5a8a5a;
}

/* Share button styling */
#share-template-btn {
    background: #4a4a6a;
    border-color: #5a5a8a;
}

#share-template-btn:hover {
    background: #5a5a8a;
}

#share-template-btn.copied {
    background: #4a6a4a;
    border-color: #5a8a5a;
    animation: pulse 0.3s ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Comparison Template Selector */
.comparison-selector-section {
    padding: 10px 15px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stats-controls-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.stats-control-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
}

.stats-control-full {
    width: 100%;
    flex: 1 1 100%;
    display: flex;
    justify-content: center;
}

.stats-control-full .hoi4-btn {
    width: 100%;
    max-width: 100%;
}

.stats-control-item label {
    display: inline-block;
    font-size: 12px;
    color: #4a3a2a;
    margin-bottom: 0;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.stats-control-item .year-select,
.stats-control-item .comparison-template-select {
    flex: 1 1 0;
    min-width: 100px;
    max-width: 100%;
    padding: 5px 8px;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    color: #e0e0e0;
    width: 0; /* Allows flex to work properly */
}

.stats-control-item .hoi4-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.comparison-template-select {
    flex: 1;
    padding: 5px 8px;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    color: #e0e0e0;
    font-size: 12px;
    cursor: pointer;
}

.comparison-template-select:hover {
    border-color: #6a6a6a;
    background: #353535;
}

.comparison-template-select:focus {
    outline: none;
    border-color: #6a6a6a;
    background: #353535;
}

/* Baseline Comparison Indicators */
.baseline-comparison {
    font-size: 10px;
    font-weight: normal;
    line-height: 1.2;
    text-align: right;
    margin-top: 2px;
    display: inline-block;
}

/* Baseline comparisons for terrain section (dark background) */
.terrain-mod-value-container .baseline-comparison.positive {
    color: #7acc7a;
    opacity: 0.9;
}

.terrain-mod-value-container .baseline-comparison.negative {
    color: #cc6666;
    opacity: 0.9;
}

/* Baseline comparisons for stats section (light parchment background) */
.stats-parchment .baseline-comparison.positive {
    color: #2d7a2d;
    opacity: 1;
    font-weight: 500;
}

.stats-parchment .baseline-comparison.negative {
    color: #8b2d2d;
    opacity: 1;
    font-weight: 500;
}

.production-cost {
    margin-left: auto;
    font-size: 12px;
    color: #a0a0a0;
}

.production-cost #cost-min,
.production-cost #cost-max {
    color: #c4a86f;
    font-weight: bold;
}

/* Baseline comparison for production cost (left panel, dark background) */
.production-cost .baseline-comparison {
    margin-left: 8px;
}

.production-cost .baseline-comparison.positive {
    color: #7acc7a;
    opacity: 0.9;
}

.production-cost .baseline-comparison.negative {
    color: #cc6666;
    opacity: 0.9;
}

/* Right Panel - Stats */
.hoi4-right-panel {
    width: 40%;
    background: #1a1a1a;
    overflow-y: auto;
    padding: 15px;
}

.stats-parchment {
    background: linear-gradient(to bottom, #d4c5a0, #c4b590);
    border: 2px solid #8b7a5a;
    border-radius: 5px;
    padding: 20px;
    color: #2a2a2a;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
}

.stats-section {
    margin-bottom: 25px;
}

.stats-section:last-child {
    margin-bottom: 0;
}

.stats-section-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 12px;
    color: #1a1a1a;
    border-bottom: 1px solid #8b7a5a;
    padding-bottom: 5px;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
}

.stat-row .baseline-comparison {
    order: 1;
    min-width: 65px;
    text-align: right;
}

.stat-row .stat-value {
    order: 2;
}

.stat-row .stat-unit {
    order: 3;
}

.stat-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.stat-label {
    flex: 1;
    color: #4a4a4a;
    order: 0;
}

.stat-value {
    font-weight: bold;
    color: #1a1a1a;
    min-width: 60px;
    text-align: right;
}

.stat-unit {
    font-size: 11px;
    color: #6a6a6a;
}

/* Modal */
.hoi4-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.hoi4-modal.active {
    display: flex;
}

.modal-content {
    background: #2a2a2a;
    border: 2px solid #4a4a4a;
    border-radius: 5px;
    width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.comparison-modal-content {
    width: 95vw;
    max-width: 1400px;
    max-height: 90vh;
}

.comparison-modal-body {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.comparison-loading {
    padding: 40px;
    text-align: center;
    color: #a0a0a0;
    font-size: 14px;
}

.comparison-table-container {
    flex: 1;
    overflow: auto;
    /* padding: 15px; */
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: #1a1a1a;
}

/* Transposed table styles */
.comparison-table.transposed {
    width: auto;
    min-width: 100%;
}

.comparison-table thead tr {
    position: sticky;
    top: -18px;
    z-index: 10;
    background: #353535;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.comparison-table thead tr::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #4a4a4a;
    z-index: 1;
}

.comparison-table th {
    background: #353535;
    color: #e0e0e0;
    padding: 8px 10px;
    text-align: center;
    font-weight: 600;
    border: 1px solid #4a4a4a;
    white-space: nowrap;
    position: relative;
}

.comparison-table thead th {
    background: #353535 !important;
}

.comparison-table th.template-name-header {
    position: sticky;
    left: 0;
    z-index: 11;
    background: #353535;
    min-width: 150px;
    max-width: 150px;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}

.comparison-table td {
    padding: 6px;
    border: 1px solid #3a3a3a;
    text-align: right;
    color: #e0e0e0;
}

.comparison-table td.template-name {
    position: sticky;
    left: 0;
    z-index: 5;
    background: #2a2a2a;
    text-align: left;
    font-weight: 600;
    min-width: 150px;
    max-width: 150px;
    color: #e0e0e0;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}

.comparison-table tr.current-template {
    background: #2a3a2a;
}

.comparison-table tr.current-template td.template-name {
    background: #2a3a2a;
    border-left: 3px solid #5a8a5a;
}

.comparison-table tr.separator {
    height: 3px;
    background: #4a4a4a;
}

.comparison-table tr.separator td {
    padding: 0;
    border: none;
}

.comparison-table tr:hover {
    background: #353535;
}

.comparison-table tr.current-template:hover {
    background: #2a4a2a;
}

/* Heatmap cell colors */
.comparison-table td.heatmap-cell {
    font-weight: 500;
}

/* Green shades - better than baseline (3 shades) */
.comparison-table td.heatmap-good-light {
    background: #2a5a2a;
    color: #a0ffa0;
}

.comparison-table td.heatmap-good {
    background: #1a5a1a;
    color: #90ee90;
}

.comparison-table td.heatmap-excellent {
    background: #0a5a0a;
    color: #7acc7a;
}

/* Red shades - worse than baseline (3 shades) */
.comparison-table td.heatmap-poor {
    background: #4a2a2a;
    color: #ffa0a0;
}

.comparison-table td.heatmap-bad {
    background: #5a1a1a;
    color: #ff6b6b;
}

.comparison-table td.heatmap-bad-dark {
    background: #6a0a0a;
    color: #ff4a4a;
}

.comparison-table td.heatmap-average {
    background: #3a3a2a;
    color: #e0e0e0;
}

.comparison-table td.heatmap-neutral {
    background: #2a2a2a;
    color: #a0a0a0;
}

.comparison-table th.stat-group-header {
    background: #2a2a2a;
    font-weight: bold;
    color: #c0c0c0;
    text-align: center;
    border-bottom: 2px solid #4a4a4a;
}

/* Transposed table - template headers */
.comparison-table .template-header {
    min-width: 100px;
    max-width: 140px;
    vertical-align: bottom;
    padding: 12px 8px;
    text-align: center;
    background: #353535 !important;
}

.comparison-table .template-header.current-template {
    background: #2a3a2a !important;
    border-top: 3px solid #5a8a5a;
    position: sticky;
    left: 120px; /* Position after stat label column */
    z-index: 11;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    border-left: none;
}

.comparison-table thead .template-header.current-template {
    background: #2a3a2a !important;
}

.comparison-table .template-header-icon {
    font-size: 24px;
    margin-bottom: 6px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.comparison-table .template-icon-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.comparison-table .template-header-name {
    font-size: 11px;
    font-weight: 600;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
}

.comparison-table .current-badge {
    display: block;
    font-size: 9px;
    color: #7acc7a;
    font-weight: normal;
    margin-top: 2px;
}

.comparison-table .baseline-badge {
    display: block;
    font-size: 9px;
    color: #c4a86f;
    font-weight: normal;
    margin-top: 2px;
}

.comparison-table .template-header.selected-baseline {
    background: #3a4a3a !important;
    border: 2px solid #5a8a5a;
    box-shadow: 0 0 8px rgba(90, 138, 90, 0.5);
}

.comparison-table .template-header.baseline-header {
    background: #353535;
}

.comparison-table .template-header.baseline-header.selected-baseline {
    background: #3a4a3a !important;
    border: 2px solid #5a8a5a;
    box-shadow: 0 0 8px rgba(90, 138, 90, 0.5);
}

.comparison-table .template-header[style*="cursor: pointer"]:hover {
    background: #4a4a4a !important;
    transition: background 0.2s;
}

.comparison-table .empty-cell {
    background: #1a1a1a;
    border: 1px solid #3a3a3a;
}

.comparison-table .baseline-template-cell {
    background: #2a3a2a;
    border: 1px solid #3a3a3a;
}

.comparison-table .stat-label-header {
    min-width: 120px;
    background: #353535 !important; /* Match table header background */
    position: sticky;
    left: 0;
    z-index: 12;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    border-right: none;
}

.comparison-table thead .stat-label-header {
    background: #353535 !important;
}

/* Stat group row */
.comparison-table .stat-group-row {
    background: #252525;
}

.comparison-table .stat-group-label {
    font-weight: bold;
    color: #c4a86f;
    padding: 10px 12px;
    text-align: left;
    border-top: 2px solid #4a4a4a;
    border-bottom: 1px solid #3a3a3a;
    position: sticky;
    left: 0;
    z-index: 7;
    background: #252525;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}

/* Stat label cell */
.comparison-table .stat-label-cell {
    text-align: left;
    font-weight: 500;
    color: #b0b0b0;
    padding: 6px 12px;
    background: #252525 !important;
    white-space: nowrap;
    position: sticky;
    left: 0;
    z-index: 6;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    border-right: none;
}

/* Current template column highlight */
.comparison-table td.current-template-cell {
    position: sticky;
    left: 120px; /* Position after stat label column */
    z-index: 5;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    border-left: none;
}

/* Solid background for sticky current template cells when not in heatmap mode */
.comparison-table td.current-template-cell:not(.heatmap-cell) {
    background: #2a3a2a !important;
}

/* Heatmap colors should override the background - Green shades */
.comparison-table td.current-template-cell.heatmap-good-light {
    background: #2a5a2a !important;
    color: #a0ffa0 !important;
}

.comparison-table td.current-template-cell.heatmap-good {
    background: #1a5a1a !important;
    color: #90ee90 !important;
}

.comparison-table td.current-template-cell.heatmap-excellent {
    background: #0a5a0a !important;
    color: #7acc7a !important;
}

/* Heatmap colors should override the background - Red shades */
.comparison-table td.current-template-cell.heatmap-poor {
    background: #4a2a2a !important;
    color: #ffa0a0 !important;
}

.comparison-table td.current-template-cell.heatmap-bad {
    background: #5a1a1a !important;
    color: #ff6b6b !important;
}

.comparison-table td.current-template-cell.heatmap-bad-dark {
    background: #6a0a0a !important;
    color: #ff4a4a !important;
}

.comparison-table td.current-template-cell.heatmap-average {
    background: #3a3a2a !important;
    color: #e0e0e0 !important;
}

.comparison-table td.current-template-cell.heatmap-neutral {
    background: #2a2a2a !important;
    color: #a0a0a0 !important;
}

.comparison-selector-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.comparison-selector-section button {
    margin-left: auto;
}

.modal-header {
    background: #353535;
    padding: 15px;
    border-bottom: 1px solid #4a4a4a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 16px;
    color: #e0e0e0;
}

.modal-close {
    background: transparent;
    border: none;
    color: #e0e0e0;
    font-size: 24px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    line-height: 1;
}

.modal-search {
    padding: 10px 15px;
    background: #2a2a2a;
    border-bottom: 1px solid #4a4a4a;
}

.modal-search input {
    width: 100%;
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    color: #e0e0e0;
    font-size: 14px;
}

.modal-search input:focus {
    outline: none;
    border-color: #5a8a8a;
}

.modal-search input::placeholder {
    color: #888;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-category-header {
    font-size: 13px;
    font-weight: bold;
    color: #c0c0c0;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 0;
    border-bottom: 1px solid #4a4a4a;
    margin-bottom: 5px;
}

.modal-category-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.modal-option {
    background: #353535;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-option:hover {
    background: #404040;
    border-color: #6a6a6a;
}

.modal-option.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.modal-option-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.modal-option-name {
    font-size: 12px;
    color: #e0e0e0;
}

/* Icon Picker Styles */
.icon-option {
    background: #353535;
    border: 1px solid #4a4a4a;
    border-radius: 3px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 90px;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-option:hover {
    background: #404040;
    border-color: #6a6a6a;
    transform: scale(1.1);
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 15px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #6a6a6a;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .hoi4-window {
        height: 100vh;
        overflow-y: auto;
    }
    
    .hoi4-main-content {
        flex-direction: column;
        overflow: visible;
        height: auto;
        position: relative;
    }
    
    .hoi4-left-panel {
        width: 100%;
        border-right: none;
        padding: 10px;
        overflow: visible;
        position: relative;
        /* Ensure sticky children can stick relative to viewport */
        min-height: 0;
    }
    
    .hoi4-division-header {
        position: relative;
        z-index: 30;
        padding: 10px 0;
        margin-bottom: 10px;
    }
    
    .custom-dropdown {
        position: relative;
        z-index: 1001;
    }
    
    .dropdown-menu {
        z-index: 1001;
    }
    
    /* Make the grid section truly sticky on mobile - stick to viewport top */
    .hoi4-section {
        position: -webkit-sticky; /* Safari support */
        position: sticky;
        top: 0;
        background: #2a2a2a;
        z-index: 20;
        padding: 10px;
        margin: 0 -10px 10px -10px;
        border-bottom: 2px solid #4a4a4a;
        /* Ensure it stays sticky across the entire scroll area */
        align-self: flex-start;
        width: calc(100% + 20px); /* Account for negative margin */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        /* Ensure it stays sticky even when scrolling past parent */
        will-change: transform;
    }
    
    .hoi4-right-panel {
        position: relative;
        z-index: 1;
        /* Ensure it scrolls behind the sticky section */
        background: #1a1a1a;
    }
    
    .stats-parchment {
        position: relative;
        z-index: 1;
    }
    
    .section-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .terrain-effects-section {
        margin-top: 15px;
        margin-bottom: 15px;
    }
    
    /* Make terrain grid single column on mobile */
    .terrain-grid {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    
    /* Adjust terrain row for mobile - more compact horizontal layout */
    .terrain-row {
        flex-direction: row;
        align-items: flex-start;
        padding: 4px 6px;
        gap: 6px;
    }
    
    .terrain-name {
        flex: 0 0 70px;
        font-size: 11px;
        min-width: 120px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .terrain-icon {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }
    
    .terrain-values-container {
        flex: 1;
        display: flex;
        justify-content: flex-end;
        gap: 8px; /* Reduced spacing for mobile */
        align-items: flex-start;
        min-width: 0;
    }
    
    .terrain-modifier {
        flex: 0 0 65px;
        width: 65px;
        min-width: 65px;
        max-width: 65px;
        gap: 1px;
        align-items: center;
        display: flex;
        flex-direction: column;
    }
    
    .terrain-mod-label {
        font-size: 9px;
        letter-spacing: 0.3px;
        text-align: center;
        width: 100%;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .terrain-mod-value-container {
        gap: 2px;
        align-items: center;
        width: 100%;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
    }
    
    .terrain-mod-value {
        font-size: 11px;
        text-align: center;
        width: 100%;
        white-space: nowrap;
    }
    
    .terrain-mod-value-container .baseline-comparison {
        font-size: 9px;
        white-space: nowrap;
    }
    
    .hoi4-right-panel {
        width: 100%;
        padding: 10px;
        overflow: visible;
    }
    
    .hoi4-title-bar {
        padding: 8px 10px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .title-bar-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    
    .hoi4-title {
        font-size: 12px;
    }
    
    .hoi4-title .title-icon {
        width: 20px;
        height: 20px;
    }
    
    
    /* Keep side-by-side layout on mobile, just scale down */
    .support-combat-container {
        flex-direction: row;
        gap: 6px;
        padding: 8px;
        min-height: auto;
    }
    
    .support-column {
        width: 50px;
        flex-shrink: 0;
    }
    
    .combat-column {
        flex: 1;
        min-width: 0;
    }
    
    /* Keep 5-column grid, reduce gap */
    .combat-slots {
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
    }
    
    /* Scale down slot sizes - but make icons bigger */
    .slot {
        height: 50px;
    }
    
    .support-slots .slot {
        height: 50px;
        width: 50px;
    }
    
    .support-slots {
        gap: 4px;
    }
    
    .slot.large-slot {
        height: 60px;
        margin-top: 4px;
    }
    
    .slot-icon {
        font-size: 32px;
    }
    
    .slot.add-slot .slot-icon {
        font-size: 40px;
    }
    
    .slot.locked .slot-icon {
        font-size: 28px;
    }
    
    /* Make unit images bigger on mobile by reducing padding */
    .unit-image {
        padding: 2px;
    }
    
    .combat-slots .unit-image {
        padding: 4px;
    }
    
    .support-slots .unit-image {
        padding: 2px;
    }
    
    .stats-parchment {
        padding: 15px;
    }
    
    .comparison-selector-section {
        padding: 8px 10px;
        gap: 8px;
    }
    
    .stats-controls-row {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    .stats-control-item {
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
    }
    
    .stats-control-item label {
        min-width: 70px;
        width: 70px;
    }
    
    .stats-control-item .year-select,
    .stats-control-item .comparison-template-select {
        flex: 1 1 0;
        min-width: 80px;
        width: 0;
    }
    
    .stats-control-full .hoi4-btn {
        width: 100%;
    }
    
    .hoi4-division-header {
        gap: 10px;
    }
    
    .division-header-row {
        gap: 8px;
    }
    
    /* First row: Icon, Name Input, Load Template */
    .division-header-row:first-child {
        flex-wrap: wrap;
    }
    
    .division-icon-selector {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }
    
    .division-name-input {
        flex: 1;
        min-width: 120px;
    }
    
    .saved-templates-section {
        width: 100%;
        flex: 1 1 100%;
        min-width: 0;
        order: -1; /* Move above name input on mobile */
    }
    
    .division-icon-selector {
        order: 0; /* Keep icon on the left */
    }
    
    .division-name-input {
        order: 1; /* Name input after icon */
    }
    
    .custom-dropdown {
        width: 100%;
        min-width: 0;
    }
    
    .dropdown-header {
        width: 100%;
    }
    
    /* Second row: Reset and Save buttons */
    .division-header-row:last-child {
        width: 100%;
    }
    
    .year-selector {
        flex: 1;
        min-width: 50px;
    }
    
    .division-header-row .hoi4-btn {
        flex: 1;
        min-width: 80px;
        font-size: 11px;
        padding: 6px 10px;
    }
}
