:root {
    --primary-color: #004d40; /* Teal dark */
    --secondary-color: #00796b;
    --bg-color: #f4f4f9;
    --text-color: #333;
    --border-color: #ddd;
    --hover-bg: #e0f2f1;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
header {
    background-color: #fff;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    flex-wrap: wrap;
    gap: 1rem;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--primary-color);
}

.header-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: white;
    background-color: var(--secondary-color);
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.2s;
    white-space: nowrap;
}

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

/* Main Layout */
.main-content {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Map & Stats Dashboard Top */
.dashboard-top {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    min-height: 400px;
}

#map {
    flex: 3; /* Map takes 75% */
    height: 450px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid #ddd;
    z-index: 1;
}

.stats-sidebar {
    flex: 1; /* Stats takes 25% */
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-card {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    text-align: left;
    border-left: 4px solid var(--secondary-color);
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.1rem;
}

.stat-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Legend */
.info.legend {
    padding: 10px;
    font: 12px/14px Arial, Helvetica, sans-serif;
    background: white;
    background: rgba(255,255,255,0.9);
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    border-radius: 5px;
    line-height: 18px;
    color: #555;
}

.info.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 8px;
    opacity: 0.7;
}

/* Filters */
.filters-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filters-container {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    flex: 1;
}

.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 150px;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 0.3rem;
}

.filter-group select {
    padding: 0.6rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: white;
    font-size: 0.95rem;
}

/* Search Bar */
.search-bar {
    width: 100%;
    max-width: 400px;
}

.search-bar input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(0, 121, 107, 0.2);
}

/* View Toggle */
.view-toggle {
    display: flex;
    background: #e0e0e0;
    border-radius: 4px;
    padding: 2px;
}

.view-btn {
    border: none;
    background: transparent;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

.view-btn.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Content Area (Table/Grid) */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Table Styles */
.table-scroll {
    overflow: auto;
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    font-weight: 600;
    color: var(--primary-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    z-index: 5;
}

tbody tr {
    transition: background-color 0.1s;
}

tbody tr:hover, tbody tr:focus {
    background-color: var(--hover-bg);
    cursor: pointer;
    outline: none;
}

/* Grid/Card View Styles */
.grid-view {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    overflow-y: auto;
    height: 100%;
}

.tribe-card {
    background: white;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tribe-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border-color: var(--secondary-color);
}

.tribe-card h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary-color);
    line-height: 1.3;
}

.tribe-location {
    color: #666;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tribe-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.5rem;
}

.badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-federal {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.badge-state {
    background-color: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
}

/* Pagination */
.pagination {
    padding: 1rem;
    background-color: #fff;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 6;
}

.page-info {
    font-size: 0.9rem;
    color: #666;
}

.page-size-selector {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-size-selector select {
    padding: 0.3rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.page-controls button {
    background: white;
    border: 1px solid #ccc;
    padding: 0.5rem 1rem;
    margin-left: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-color);
}

.page-controls button:hover:not(:disabled) {
    background-color: #f1f1f1;
    border-color: #bbb;
}

.page-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Status Messages */
.status-msg {
    text-align: center;
    padding: 3rem;
    color: #666;
    font-size: 1.1rem;
    font-style: italic;
    width: 100%;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000; /* Ensure above map */
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.modal-overlay.active {
    opacity: 1;
}

.modal {
    background: white;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    position: relative;
    transform: translateY(20px);
    transition: transform 0.2s;
    overflow: hidden;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.5rem 2rem;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: start;
}

.modal h2 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.5rem;
}

.modal-content {
    padding: 2rem;
    overflow-y: auto;
}

.close-btn {
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: #999;
    border: none;
    background: none;
    padding: 0;
    margin-left: 1rem;
}

.close-btn:hover {
    color: #333;
}

.modal-section {
    margin-bottom: 2rem;
}

.modal-section-title {
    font-size: 1.1rem;
    color: var(--primary-color);
    border-bottom: 2px solid var(--hover-bg);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.detail-label {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 0.95rem;
    word-break: break-word;
    color: #222;
    line-height: 1.4;
}

.detail-value a {
    color: #007bff;
    text-decoration: none;
}

.detail-value a:hover {
    text-decoration: underline;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .dashboard-top {
        flex-direction: column;
        gap: 1rem;
        min-height: auto;
    }

    #map {
        height: 300px;
        flex: none;
    }

    .stats-sidebar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        flex: none;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .filters-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filters-container {
        flex-direction: column;
    }
    
    .view-toggle {
        align-self: flex-start;
    }

    /* Force Grid view on mobile regardless of toggle? Or hide table? */
    /* Let's keep the user choice but make table responsive like before if chosen */
    
    thead {
        display: none;
    }
    
    table, tbody, tr, td {
        display: block;
        width: 100%;
    }
    
    td {
        display: grid;
        grid-template-columns: 120px 1fr;
    }
    
    td::before {
        font-weight: bold;
        color: #666;
    }
    
    td:nth-of-type(1)::before { content: "Tribe:"; }
    td:nth-of-type(2)::before { content: "State:"; }
    td:nth-of-type(3)::before { content: "City:"; }
    td:nth-of-type(4)::before { content: "Recognition:"; }
}