/* War Database - Main Styles */

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

:root {
    /* Colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;

    /* Conflict colors */
    --color-ongoing: #ff4444;
    --color-war: #ff8c00;
    --color-colonization: #9b59b6;
    --color-genocide: #e74c3c;
    --color-conquest: #3498db;

    /* Spacing */
    --header-height: 60px;
    --timeline-height: 140px;
    --sidebar-width: 320px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* Header */
.header {
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.header__title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header__title .red-w {
    color: #ff4444;
}

.header__subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-left: 16px;
}

.header__nav {
    display: flex;
    gap: 8px;
}

.nav-btn {
    padding: 8px 16px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background-color: var(--border-color);
}

.nav-btn.active {
    background-color: var(--color-ongoing);
    border-color: var(--color-ongoing);
}

/* Main Layout */
.main {
    display: flex;
    height: calc(100vh - var(--header-height) - var(--timeline-height));
    margin-top: var(--header-height);
    position: relative;
}

/* Filter Panel */
.filters-panel {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1001;
}

.filters-panel.open {
    transform: translateX(0);
}

.filters-panel h2 {
    font-size: 1.125rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.filter-group {
    margin-bottom: 24px;
}

.filter-group h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.filter-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-ongoing);
}

.filter-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.filter-group input[type="text"]:focus {
    outline: none;
    border-color: var(--color-ongoing);
}

.reset-filters-btn {
    width: 100%;
    padding: 10px 16px;
    margin-top: 16px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-filters-btn:hover {
    background-color: var(--color-ongoing);
    border-color: var(--color-ongoing);
}

/* Detail Panel */
.detail-panel {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1001;
}

.detail-panel.open {
    transform: translateX(0);
}

/* Rankings Panel */
.rankings-panel {
    width: 400px;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1002;
}

.rankings-panel.open {
    transform: translateX(0);
}

.rankings-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
    padding-right: 30px;
}

.rankings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.rankings-tab {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rankings-tab:hover {
    background: var(--border-color);
}

.rankings-tab.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.rankings-filters {
    margin-bottom: 16px;
}

.rankings-filter-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.filter-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 50px;
    padding-top: 6px;
}

.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}

.filter-btn {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

.filter-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.rankings-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.rankings-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ranking-item:hover {
    background: var(--border-color);
}

.ranking-position {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 28px;
}

.ranking-info {
    flex: 1;
    min-width: 0;
}

.ranking-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ranking-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ranking-deaths {
    font-weight: 700;
    color: #d93025;
    font-size: 0.9rem;
    text-align: right;
}

@media (max-width: 768px) {
    .rankings-panel {
        width: 100%;
    }
}

/* Aggressor wars view */
.aggressor-wars-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.aggressor-wars-header h3 {
    font-size: 1.1rem;
    margin: 8px 0 4px 0;
}

.aggressor-total {
    color: #d93025;
    font-size: 0.85rem;
    font-weight: 600;
}

.back-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Search Modal */
.search-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3000;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.search-modal.open {
    display: flex;
}

.search-modal-content {
    width: 90%;
    max-width: 600px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.search-modal-input {
    width: 100%;
    padding: 20px 24px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.125rem;
    font-family: inherit;
}

.search-modal-input:focus {
    outline: none;
}

.search-modal-input::placeholder {
    color: var(--text-muted);
}

.search-results {
    max-height: 50vh;
    overflow-y: auto;
    display: none;
}

.search-results.visible {
    display: block;
}

.search-result-item {
    padding: 14px 24px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-tertiary);
}

.search-result-name {
    font-weight: 500;
    font-size: 1rem;
    margin-bottom: 4px;
}

.search-result-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.search-no-results {
    padding: 24px 24px 8px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.search-suggest-new {
    padding: 8px 24px 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
}

.search-suggest-new:hover {
    color: var(--text-primary);
}

.form-hint {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 4px;
}

.close-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.detail-content {
    padding-top: 20px;
}

.placeholder-text {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
}

/* Conflict Detail Styles */
.conflict-detail h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.conflict-type {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.conflict-type.war { background-color: var(--color-war); }
.conflict-type.colonization { background-color: var(--color-colonization); }
.conflict-type.genocide { background-color: var(--color-genocide); }
.conflict-type.ongoing { background-color: var(--color-ongoing); }

.conflict-dates {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.conflict-description {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.conflict-stats {
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.conflict-stats h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.stat-value {
    color: var(--text-primary);
    font-weight: 600;
}

.conflict-parties h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.party-list {
    list-style: none;
}

.party-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.party-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.party-name {
    font-weight: 500;
}

.party-role {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
}

.party-casualties {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    margin-top: 4px;
}

.party-deaths {
    color: #ff6b6b;
}

.party-wounded {
    color: #ffa94d;
}

/* Tooltip */
.tooltip {
    position: fixed;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px 16px;
    max-width: 300px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.tooltip.visible {
    opacity: 1;
}

.tooltip h4 {
    font-size: 0.875rem;
    margin-bottom: 4px;
}

.tooltip p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal h2 {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.modal-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0 20px 0;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-ongoing);
}

.form-group textarea {
    resize: vertical;
}

.submit-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--color-ongoing);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.submit-btn:hover {
    background: #ff2222;
}

/* Report Modal Search */
.report-search-container {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.report-search-results {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 8px;
    border-radius: 6px;
    display: none;
}

.report-search-results.visible {
    display: block;
    border: 1px solid var(--border-color);
}

.report-search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.report-search-result-item:last-child {
    border-bottom: none;
}

.report-search-result-item:hover {
    background: var(--bg-tertiary);
}

.report-search-result-item.selected {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--color-ongoing);
}

.report-search-result-name {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.report-search-result-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.report-search-no-results {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.report-selected-conflict {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    padding: 10px 12px;
    border-radius: 6px;
    margin-top: 8px;
}

.report-selected-conflict-info {
    flex: 1;
}

.report-selected-conflict-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.report-selected-conflict-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.report-clear-selection {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 1.2rem;
    border-radius: 4px;
}

.report-clear-selection:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
    .header__subtitle {
        display: none;
    }

    :root {
        --sidebar-width: 280px;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --timeline-height: 0px;
        --header-height: 50px;
    }

    .header {
        padding: 0 12px;
    }

    .header__title {
        font-size: 1.1rem;
    }

    .header__nav {
        gap: 4px;
    }

    .nav-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    /* Hide text on some buttons, show icons only */
    .nav-btn .btn-text {
        display: none;
    }

    /* Hide timeline on mobile for now */
    .timeline-container {
        display: none;
    }

    /* Detail panel slides from bottom on mobile */
    .detail-panel {
        position: fixed;
        width: 100%;
        height: 75vh;
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        transform: translateY(100%);
        border-radius: 16px 16px 0 0;
        border-top: 1px solid var(--border-color);
        border-left: none;
        z-index: 2000;
    }

    .detail-panel.open {
        transform: translateY(0);
    }

    .detail-content {
        padding: 16px;
        padding-top: 24px;
        padding-bottom: 24px;
    }

    /* Rankings panel full screen on mobile */
    .rankings-panel {
        width: 100%;
        height: calc(100vh - var(--header-height));
        top: var(--header-height);
        border-radius: 0;
    }

    .rankings-filters {
        flex-wrap: wrap;
    }

    .rankings-filter-row {
        width: 100%;
    }

    .filter-buttons {
        flex-wrap: wrap;
    }

    .filter-btn {
        padding: 6px 10px;
        font-size: 0.7rem;
    }

    /* Timeline compact on mobile */
    .timeline-container {
        padding: 8px 12px;
    }

    .era-marker {
        padding: 6px 4px;
        min-width: 50px;
    }

    .era-label {
        font-size: 0.6rem;
    }

    .era-date {
        display: none;
    }

    /* Modal adjustments */
    .modal {
        width: 95%;
        max-height: 85vh;
        margin: 0 auto;
    }

    .report-search-results {
        max-height: 150px;
    }

    /* Larger touch targets for markers */
    .conflict-marker-icon .marker-pin {
        min-width: 16px;
        min-height: 16px;
    }

    /* Search modal closer to top on mobile */
    .search-modal {
        padding-top: 10vh;
    }

    .search-modal-input {
        padding: 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Legend adjustments */
    .legend {
        bottom: calc(var(--timeline-height) + 8px);
        left: 8px;
        padding: 8px 10px;
    }

    .legend-item {
        font-size: 0.7rem;
    }

    /* Close button bigger for touch */
    .close-btn {
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
    }

    /* Detail panel drag handle for mobile */
    .detail-panel::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-color);
        border-radius: 2px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .header__title {
        font-size: 1rem;
    }

    .nav-btn {
        padding: 6px 8px;
    }

    .detail-panel {
        height: 85vh;
    }

    .ranking-item {
        padding: 10px 12px;
    }

    .ranking-name {
        font-size: 0.85rem;
    }
}
