/* main-style.css - Styles for the overall page */

@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;700&display=swap');

body {
    background-color: #004aad;
    color: white;
    font-family: 'Fira Sans', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

h1 {
    text-align: center;
    margin: 20px 0 5px 0; /* Reduced bottom margin */
    font-weight: 700;
}

/* --- View Switcher Button --- */
#view-switcher {
    text-align: center;
    margin-bottom: 15px;
}

#switch-view-btn {
    padding: 6px 15px;
    font-size: 0.95em;
    font-weight: bold;
    color: white;
    background-color: #6f42c1; /* Purple-ish */
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
#switch-view-btn:hover {
    background-color: #5a32a3;
}


/* --- Authentication Section Styles --- */
#auth-container {
    width: 95%;
    max-width: 1000px;
    margin: 0 auto 15px auto; /* Reduced top margin */
    padding: 10px 15px;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-wrap: wrap; /* Allow items to wrap */
    justify-content: space-between; /* Space out login/logout sections */
    align-items: center; /* Vertically align items */
    gap: 10px; /* Gap between flex items */
    box-sizing: border-box;
}
#login-form { display: flex; align-items: center; gap: 8px; flex-grow: 1; min-width: 250px; order: 1; } /* Let login form grow */
#logout-section { display: flex; align-items: center; gap: 10px; flex-shrink: 0; order: 2; } /* Initially hidden via inline style */

#auth-container input[type="email"],
#auth-container input[type="password"] {
    padding: 6px 10px; border: 1px solid rgba(255, 255, 255, 0.4); background-color: rgba(0, 0, 0, 0.2);
    color: white; border-radius: 4px; font-family: inherit; flex: 1 1 auto; min-width: 100px;
}
#auth-container input::placeholder { color: rgba(255, 255, 255, 0.6); }
#auth-container button {
    padding: 6px 12px; background-color: #007bff; color: white; border: none; border-radius: 4px;
    cursor: pointer; font-family: inherit; font-weight: bold; transition: background-color 0.2s ease; flex-shrink: 0;
}
#auth-container button:hover:not(:disabled) { background-color: #0056b3; }
#auth-container button:disabled { background-color: #6c757d; opacity: 0.7; cursor: not-allowed; }
#user-email { font-style: italic; opacity: 0.9; font-size: 0.9em; }

/* Base transition styles for auth-status */
#auth-status {
    /* Default takes full width for errors or initial state */
    /* Properties are set by .error or .success states */
    font-size: 0.9em;
    margin: 0;
    padding: 0;
    border-radius: 3px;
    box-sizing: border-box;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    /* Make transition slightly faster */
    transition: opacity 0.2s ease, max-height 0.2s ease, padding 0.2s ease, margin 0.2s ease, width 0.2s ease;
    /* Add flex properties for alignment when successful */
    order: 3; /* Ensure it comes after login/logout sections visually */
    margin-left: 0; /* Default margin */
}

/* Error state (Keep full width, below other items on its row) */
#auth-status.error {
    padding: 3px 5px;
    margin-top: 5px; /* Space below login form if it wraps */
    opacity: 1;
    max-height: 5em;
    width: 100%; /* Explicitly full width */
    color: #f8d7da;
    background-color: rgba(220, 53, 69, 0.3);
    font-weight: bold;
    text-align: center; /* Center error message */
}

/* Success state (Inline, next to logout) */
#auth-status.success {
    padding: 3px 10px; /* Slightly more padding */
    margin-top: 0; /* Remove top margin */
    margin-left: auto; /* Push to the right within the flex container */
    opacity: 1;
    max-height: 5em; /* Or adjust if needed */
    width: auto; /* Allow it to shrink to content */
    color: #d4edda;
    background-color: rgba(40, 167, 69, 0.3);
    font-weight: bold;
    text-align: left; /* Align text to the left within its own box */
    /* align-self: center; */ /* Uncomment if vertical alignment with logout button is off */
}


/* Container for Map and Legend */
#map-legend-container {
    display: flex; /* Default display */
    flex-direction: row; justify-content: center; align-items: flex-start;
    width: 95%; max-width: 1800px; gap: 20px; margin-bottom: 20px;
}

/* Hiding class for containers */
.hidden-view {
    display: none !important;
}


/* Map */
#map {
    flex-grow: 1; height: 750px; border: 2px solid #eee;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); min-width: 0;
}

/* Legend/Panel Container */
#legend {
    width: 320px;
    max-width: 30%; flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    height: 750px; display: flex; flex-direction: column;
    box-sizing: border-box; overflow: hidden;
}

/* Panel Navigation Bar */
.panel-nav {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 15px; border-bottom: 1px solid rgba(255, 255, 255, 0.2); flex-shrink: 0;
}
.panel-nav button {
    background: rgba(0, 0, 0, 0.2); color: white; border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%; width: 30px; height: 30px; font-size: 1.2em; line-height: 1;
    cursor: pointer; transition: background-color 0.2s ease, opacity 0.2s ease; padding: 0;
}
.panel-nav button:hover:not(:disabled) { background: rgba(0, 0, 0, 0.4); }
.panel-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
#panel-title { font-weight: bold; font-size: 1.1em; }

/* Panel Container (holds the screens) */
#panel-container { flex-grow: 1; position: relative; overflow: hidden; }

/* Individual Panel Screens */
.panel-screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    padding: 0; /* Padding now applied to inner elements */
    box-sizing: border-box; transition: transform 0.35s ease-in-out;
    display: flex; flex-direction: column; background-color: transparent;
}
.panel-screen.active { transform: translateX(0); opacity: 1; z-index: 1; }
.panel-screen:not(.active) { transform: translateX(100%); opacity: 0; pointer-events: none; z-index: 0; }

/* --- Screen 1: Legend Specific Styles --- */
#legend-screen > input[type="text"],
#legend-screen > button { /* Includes Delete and Add Person buttons */
    margin: 15px 20px 10px 20px; flex-shrink: 0; width: calc(100% - 40px); box-sizing: border-box;
    padding: 8px 12px; border-radius: 5px; color: white; font-family: 'Fira Sans', sans-serif;
    font-size: 0.95em; cursor: pointer; transition: background-color 0.2s ease, opacity 0.2s ease;
}

#legendSearchInput {
    border: 1px solid rgba(255, 255, 255, 0.4); background-color: rgba(0, 0, 0, 0.2);
}
#legendSearchInput::placeholder { color: rgba(255, 255, 255, 0.6); }
#legendSearchInput:focus { outline: none; border-color: rgba(255, 255, 255, 0.7); background-color: rgba(0, 0, 0, 0.3); }

/* Add Person Button */
#addPersonFromLegendBtn {
    margin-top: 0; margin-bottom: 10px; background-color: #28a745; /* Green */ border: none; font-weight: bold;
}
#addPersonFromLegendBtn:hover:not(:disabled) { background-color: #218838; }

/* Delete Button */
#deleteSelectedBtn {
    margin-top: 0; margin-bottom: 15px; background-color: #dc3545; /* Red */ border: none; font-weight: bold;
}
#deleteSelectedBtn:hover:not(:disabled) { background-color: #c82333; }
#deleteSelectedBtn:disabled, #addPersonFromLegendBtn:disabled { background-color: #6c757d; opacity: 0.6; cursor: not-allowed; }


/* Scrollable Legend Content Area */
#legendContent {
     flex-grow: 1; overflow-y: auto; min-height: 0; padding: 0 20px;
}
#legendContent ul { list-style: none; padding: 0; margin: 0; }
#legendContent li {
    display: flex; align-items: flex-start; flex-wrap: nowrap; gap: 10px; padding: 8px 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1); cursor: pointer;
    transition: background-color 0.2s ease, border-left 0.2s ease, opacity 0.2s ease;
    border-left: 4px solid transparent;
}
#legendContent li:last-child { border-bottom: none; }
#legendContent li:hover { background-color: rgba(255, 255, 255, 0.15); }
#legendContent li.legend-item-selected { background-color: rgba(0, 80, 180, 0.5); border-left: 4px solid #007bff; padding-left: 1px; }
#legendContent li.legend-item-selected:hover { background-color: rgba(0, 80, 180, 0.6); }

.legend-column-1 {
    display: flex; align-items: flex-start; gap: 10px;
    flex-shrink: 1; flex-grow: 0; flex-basis: 150px;
    min-width: 0; pointer-events: none;
}
.legend-color-box { width: 20px; height: 20px; border: 1px solid #ccc; flex-shrink: 0; border-radius: 3px; margin-top: 2px; position: relative; background-clip: padding-box; overflow: hidden; }
li.graduated .legend-color-box::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-image: repeating-linear-gradient( 45deg, rgba(80, 80, 80, 0.7), rgba(80, 80, 80, 0.7) 1.5px, transparent 1.5px, transparent 6px ); pointer-events: none; }
.legend-name-hex-container { display: flex; flex-direction: column; min-width: 0; flex-grow: 1; }
.legend-name { font-weight: 700; display: block; color: white; white-space: normal; }
.legend-grad-year { display: block; font-size: 0.9em; opacity: 0.8; color: white; margin-top: 2px; }
.legend-hex-code { display: block; font-size: 0.9em; opacity: 0.8; font-family: monospace; margin-top: 2px; color: white; }
.legend-column-2 { flex-grow: 1; flex-shrink: 1; min-width: 60px; pointer-events: none; text-align: right; }
.legend-countries { font-size: 0.9em; opacity: 0.9; display: block; white-space: normal; color: white; }
li.graduated .legend-name, li.graduated .legend-grad-year, li.graduated .legend-hex-code, li.graduated .legend-countries { color: #aaaaaa; opacity: 0.9; }


/* Legend Bottom Area (Stats, Edit Form, Add Form) */
#legend-bottom-area {
    flex-shrink: 0; border-top: 1px solid rgba(255, 255, 255, 0.2);
    background-color: rgba(0, 0, 0, 0.1); position: relative; overflow: hidden;
}

#legend-stats-area,
#edit-form-area,
#add-form-area {
    padding: 10px 20px; transition: opacity 0.3s ease, max-height 0.3s ease; box-sizing: border-box;
}

/* Default: Show Stats, Hide Edit/Add */
#legend-stats-area { opacity: 1; max-height: 100px; pointer-events: auto; }
#edit-form-area,
#add-form-area { opacity: 0; max-height: 0; padding: 0 20px; pointer-events: none; }

/* Active Edit State: Show Edit, Hide Stats/Add */
#edit-form-area.active { opacity: 1; max-height: 350px; padding: 10px 20px; pointer-events: auto; } /* Increased height */
#legend-stats-area.hidden-by-edit,
#add-form-area.hidden-by-edit { opacity: 0; max-height: 0; padding: 0 20px; pointer-events: none; }

/* Active Add State: Show Add, Hide Stats/Edit */
#add-form-area.active { opacity: 1; max-height: 400px; padding: 10px 20px; pointer-events: auto; } /* Increased height */
#legend-stats-area.hidden-by-add,
#edit-form-area.hidden-by-add { opacity: 0; max-height: 0; padding: 0 20px; pointer-events: none; }

/* Stats Styling */
#legend-stats-area p { margin: 4px 0; font-size: 0.95em; text-align: center; }
#legend-stats-area strong { font-weight: 700; color: #fff; }

/* Shared Form Styling (Edit & Add) */
#edit-form-area h4,
#add-form-area h4 { margin-top: 0; margin-bottom: 10px; text-align: center; }
#edit-form-area label,
#add-form-area label { display: block; margin-top: 8px; margin-bottom: 3px; font-weight: normal; font-size: 0.9em; }
#edit-form-area input[type="text"],
#edit-form-area select,
#add-form-area input[type="text"],
#add-form-area select {
    width: 100%; margin-bottom: 8px; padding: 6px 8px; border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px; background-color: rgba(0, 0, 0, 0.2); color: white;
    font-family: inherit; font-size: 0.95em; box-sizing: border-box;
}
#edit-form-area .color-picker-container,
#add-form-area .color-picker-container { display: flex; align-items: center; gap: 5px; margin-bottom: 8px; }
#edit-form-area input[type="color"],
#add-form-area input[type="color"] { width: 40px; height: 30px; padding: 0; border: 1px solid #ccc; cursor: pointer; border-radius: 4px; }
#edit-form-area input.hex-input,
#add-form-area input.hex-input { width: 70px; font-family: monospace; text-transform: uppercase; flex-grow: 0; }
#edit-form-area select:disabled,
#add-form-area select:disabled { background-color: #555; color: #aaa; cursor: not-allowed; }
#edit-form-area input[type="text"]:read-only,
#add-form-area input[type="text"]:read-only { background-color: #555; color: #aaa; cursor: not-allowed; }
#edit-form-area input[type="color"]:disabled,
#add-form-area input[type="color"]:disabled { cursor: not-allowed; opacity: 0.6; }


/* Edit Form Specifics */
.edit-buttons { display: flex; justify-content: space-around; margin-top: 15px; }
.edit-buttons button { padding: 5px 10px; font-size: 0.9em; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }
#saveEditBtn { background-color: #28a745; color: white; }
#saveEditBtn:hover { background-color: #218838; }
#cancelEditBtn { background-color: #6c757d; color: white; }
#cancelEditBtn:hover { background-color: #5a6268; }
#editError { color: #f8d7da; font-size: 0.9em; text-align: center; margin-top: 8px; min-height: 1.1em;}

/* Add Form Specifics */
.add-buttons { display: flex; justify-content: space-around; margin-top: 15px; }
.add-buttons button { padding: 5px 10px; font-size: 0.9em; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }
#saveAddBtn { background-color: #17a2b8; color: white; }
#saveAddBtn:hover { background-color: #138496; }
#cancelAddBtn { background-color: #6c757d; color: white; }
#cancelAddBtn:hover { background-color: #5a6268; }
#addError { color: #f8d7da; font-size: 0.9em; text-align: center; margin-top: 8px; min-height: 1.1em;}

/* Search results styling (shared between popup and legend add form) */
.popup-style-search-results {
    border: 1px solid rgba(255, 255, 255, 0.4); background: rgba(0, 0, 0, 0.3);
    max-height: 80px; overflow-y: auto; margin-top: -5px; margin-bottom: 10px;
    border-radius: 0 0 4px 4px; position: relative; z-index: 5;
}
.popup-style-search-results div { padding: 4px 8px; cursor: pointer; font-size: 0.9em; color: #eee; border-bottom: 1px solid rgba(255, 255, 255, 0.2); }
.popup-style-search-results div:last-child { border-bottom: none; }
.popup-style-search-results div:hover { background-color: rgba(255, 255, 255, 0.15); }


/* --- Screen 2: Data Management Specific Styles --- */
#data-mgmt-screen { justify-content: flex-start; align-items: center; text-align: center; padding: 15px 20px; }
#data-mgmt-screen h3 { margin-top: 10px; margin-bottom: 20px; width: 100%; text-align: center; }
#data-mgmt-screen button {
    padding: 8px 15px; margin: 8px; background-color: #17a2b8; color: white; border: none;
    border-radius: 5px; cursor: pointer; font-family: inherit; font-weight: bold;
    transition: background-color 0.2s ease; display: block; width: 80%; max-width: 200px;
}
#data-mgmt-screen button:hover:not(:disabled) { background-color: #138496; }
#data-mgmt-screen button:disabled { background-color: #6c757d; opacity: 0.6; cursor: not-allowed; }
#importStatus { margin-top: 15px; font-size: 0.9em; min-height: 1.2em; width: 90%; padding: 5px; border-radius: 4px; }
#importStatus.error { color: #dc3545; font-weight: bold; background-color: rgba(220, 53, 69, 0.2); }
#importStatus.success { color: #28a745; font-weight: bold; background-color: rgba(40, 167, 69, 0.2); }
.import-note { font-size: 0.85em; opacity: 0.8; margin-top: 20px; max-width: 90%; }


/* Scrollbar styling */
#legendContent::-webkit-scrollbar { width: 8px; }
#legendContent::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); border-radius: 4px; }
#legendContent::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, 0.3); border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.1); }
#legendContent::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.5); }

/* Loading Indicator */
#loading {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7); color: white; padding: 20px 30px; border-radius: 8px;
    z-index: 10000; font-size: 1.1em;
}

/* Constellation Container Styling (Basic) */
#constellation-container {
    /* Uses styles from constellation/constellation-style.css */
    /* Ensure width/max-width match map-legend-container if needed */
     width: 95%;
     max-width: 1800px;
     height: 750px; /* Match map height */
     margin: 0 auto 20px auto; /* Center it */
}