body {
  font-family: system-ui, sans-serif;
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh; /* Set body height to the full viewport height */
  overflow: hidden; /* Prevent body from scrolling */
}

/* START CHANGES FOR REQUEST #3: Header and Menu Styling */
header {
  background: #0044cc;
  color: white;
  padding: 1rem;
  /* UPDATED: Use flexbox to align title left and menu right */
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}



#menu-container {
    position: relative; /* Container for absolute positioning of the dropdown */
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

#welcome-message {
    font-size: 1em;
    margin-right: 1rem;
    white-space: nowrap;
}

/* Hamburger Menu Icon */
#menu-toggle-btn {
    cursor: pointer;
    font-size: 1.8rem; /* Make the 3-line symbol large */
    background: none;
    border: none;
    color: white;
    padding: 0.25rem 0.5rem;
    line-height: 1; /* Keep icon vertically centered */
    display: block;
    transition: color 0.2s;
}

#menu-toggle-btn:hover {
    color: #f4f7ff;
}

/* Dropdown Menu Styling */
#dropdown-menu {
    position: absolute;
    top: 100%; /* Position right below the menu icon */
    right: 0;
    background-color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
    min-width: 150px;
    z-index: 50; /* Above the main content */
    display: none; /* Hidden by default, toggled by JS */
    padding: 0;
    margin-top: 5px; /* Small gap from button */
    list-style: none; /* Remove bullet points */
}

#dropdown-menu.visible {
    display: block;
}

#dropdown-menu button {
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: #333;
    transition: background-color 0.2s;
}

#dropdown-menu button:hover {
    background-color: #f4f7ff;
    color: #0044cc;
}
/* END CHANGES FOR REQUEST #3 */


main {
  display: flex;
  flex: 1; /* This makes main take up all remaining vertical space */
  overflow: hidden; /* Prevents scrollbars from appearing on 'main' itself */
}

.sidebar {
  width: 280px;
  background: #f4f7ff;
  border-right: 2px solid #ddd;
  padding: 1rem;
  
  /* NEW: Use flexbox for the sidebar itself to manage its contents */
  display: flex;
  flex-direction: column;
  height: 100%; /* Must take up 100% of the 'main' height */
}

.viewer {
  flex: 1;
  padding: 1rem;
  background: #fff;
  overflow-y: auto; /* Keeps the main chart/info area independently scrollable */
  height: 100%; /* Must take up 100% of the 'main' height */
}

/* --- Control Panel Styling (Revised) --- */
#controls-container {
    padding-bottom: 1rem;
    flex-shrink: 0; /* Prevent controls from scrolling away */
}

/* Date Picker: Stack label on top of select box */
#date-picker-container {
    display: flex;
    flex-direction: column; /* CRITICAL CHANGE: Stacks items vertically */
    margin-bottom: 0.75rem;
}
#date-picker-container .control-label {
    margin-bottom: 0.25rem; /* Space between label and select box */
    font-weight: bold; /* Make the label stand out a bit */
}
#date-select {
    flex-grow: 1; 
}


/* Search Box: Label, Input, Button on one line */
#search-container {
    margin-bottom: 0.75rem; /* Spacing between control groups */
}
#search-container .control-label {
    margin-right: 0.5rem;
    white-space: nowrap;
    font-weight: bold;
}

#search-button,
#analysis-button {
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

/* --- External Analysis Styling --- */
#analysis-container {
    padding: 0.5rem 0;
    border-top: 1px solid #ccc;
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
}
#analysis-container .control-label {
    margin-bottom: 0.25rem;
    font-weight: bold;
}

#analysis-status-message {
    padding-top: 0.25rem;
    font-size: 0.85em;
    font-style: italic;
    display: none; /* Controlled by JavaScript */
}

/* --- FIX FOR SIZING AND INLINE BUTTONS (Only this part was changed) --- */
/* 1. Ensure the input and button are on the same line and spaced correctly */
#search-input-group,
#analysis-input-group {
    display: flex;
    align-items: center; /* Vertically align input and button */
    gap: 0.5rem; /* Spacing between the input field and the button */
    width: 100%; /* Ensure the flex container takes full width */
}

/* 2. Key change: Input takes up available space, ensuring both inputs have equal width */
#search-input,
#analysis-symbol-input {
    flex-grow: 1; 
}
/* Styling to attempt to reduce the font size of datalist suggestions. */
/* Note: Direct styling of datalist options is often blocked by browsers. */
#search-input {
    /* Example: reducing from the standard size to 0.9em */
    font-size: 0.9em; 
    /* You can adjust 0.9em to a smaller value if needed, e.g., 0.8em */
}

/* --- END FIX --- */

/* --- File List & Viewer Styling (Restored/Maintained) --- */

#file-list {
    flex: 1; /* Allows the file list to take up remaining vertical space */
    overflow-y: auto; /* Allows the list to be independently scrollable */
    padding-top: 0.5rem;
}

.sector-header {
    cursor: pointer;
    padding: 0.4rem 0.5rem;
    margin-top: 0.5rem;
    background: #e0e6f7;
    border: 1px solid #c0c8e0;
    border-radius: 4px;
    transition: background 0.2s;
    font-size: 0.95em;
}

.sector-header:hover {
    background: #d4e0ff;
}

.sector-header.active {
    background: #c0c8e0;
}

.company-list {
    margin: 0;
    padding: 0.5rem 0 0.5rem 0.5rem; /* Padding for list items */
    list-style: none; /* Remove list bullets */
}

.company-list.hidden {
    display: none;
}

.file-item {
    font-size: 0.9em;
    padding: 0.25rem 0;
    cursor: pointer;
    transition: background-color 0.1s;
}

.company-item-container {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.25rem 0;
}

.file-item:hover {
    background-color: #e9eef7;
}

.file-item.highlight {
    background-color: #d4e0ff;
    font-weight: bold;
    border-left: 3px solid #0044cc;
    padding-left: 0.5rem;
}

.company-name-link {
    color: #0044cc;
    text-decoration: none;
    flex-grow: 1;
}
.company-name-link:hover {
    text-decoration: underline;
}

.info-link {
    font-size: 0.8em;
    color: #666;
    margin-left: 0.5rem;
    text-decoration: none;
    flex-shrink: 0;
}
.info-link:hover {
    text-decoration: underline;
    color: #0044cc;
}

/* --- New Navigation Bar for Chart/Info in Viewer --- */
.view-nav-button {
    padding: 8px 15px;
    margin-right: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f0f0f0;
    font-weight: bold;
    transition: background-color 0.2s, color 0.2s;
}
.view-nav-button:hover {
    background-color: #e0e0e0;
}
.view-nav-button.active {
    background-color: #0044cc;
    color: white;
    border-color: #0044cc;
}

/* --- Table Layout Containers --- */

/* Description/Identity section styling */
#company-description {
    max-width: 800px; 
    margin: 0 auto 2rem auto; /* Center it and add vertical spacing */
    padding: 1rem; 
    background: #f4f7ff; 
    border-radius: 6px; 
    border: 1px solid #d0d8e9;
}

/* Container for the single, centered "Signals" table */
#identity-table-container {
    max-width: 600px; 
    margin: 1.5rem auto 3rem auto; /* Center it and add vertical spacing */
    padding: 0 1rem; /* Padding for mobile view */
}

/* Container for the remaining tables in a 2xN grid */
#multi-table-grid {
    display: grid;
    /* Two columns: 1 fractional unit each (equal width) */
    grid-template-columns: 1fr 1fr; 
    gap: 2rem 1.5rem; /* Vertical and horizontal spacing between table wrappers */
    padding: 0 1.5rem; /* Padding from the viewer edges */
}

@media (max-width: 800px) {
    /* Stack tables vertically on smaller screens */
    #multi-table-grid {
        grid-template-columns: 1fr;
        padding: 0 0.5rem;
    }
}

/* Styling for the CSV Table */
.info-table {
  /* Tables should take 100% of their parent container (e.g., table-wrapper or identity-container) */
  width: 100%; 
  border-collapse: collapse;
  font-size: 0.9em;
  table-layout: auto; /* Use auto layout to allow content to dictate column width */
}

.info-table th, .info-table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.info-table th {
  background-color: #e0e6f7;
  color: #333;
  font-weight: bold;
  white-space: nowrap;
}

.info-table tr:nth-child(even) {
  background-color: #f9f9f9;
}


/* --- START NEW CODE FOR REQUEST #1 & #2: Login and Modal Styling --- */

/* Login Centering (Request 1) */
.login-body {
    display: flex;
    justify-content: center; /* Center horizontally */
    align-items: center; /* Center vertically */
    height: 100vh;
    margin: 0;
    background: #e9eef7; /* Light background for contrast */
    overflow: auto; /* Allow scrolling if content is too large (e.g., on small screens) */
}

/* Login box styling (Request 1) */
#login-container {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 350px; 
    text-align: center;
    transform: translateY(0); /* Reset any unintended transformations */
}

#login-container h2 {
    color: #0044cc;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#login-form label {
    align-self: flex-start;
    font-weight: bold;
    color: #333;
    margin-bottom: -0.5rem;
}

#login-form input[type="text"],
#login-form input[type="password"] {
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    transition: border-color 0.2s;
}

#login-form input[type="text"]:focus,
#login-form input[type="password"]:focus {
    border-color: #0044cc;
    outline: none;
}

#login-button {
    background-color: #0044cc;
    color: white;
    padding: 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 1rem;
    transition: background-color 0.2s;
}

#login-button:hover:not(:disabled) {
    background-color: #003399;
}
#login-button:disabled {
    background-color: #a0c0e0;
    cursor: not-allowed;
}

#login-status-message {
    margin-top: 0.5rem;
    font-size: 0.9em;
    min-height: 1.5em; /* Reserve space */
}


/* Modal Styling (Supports Request 2) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top of everything */
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%;
    overflow: auto; 
    background-color: rgba(0,0,0,0.5); /* Black w/ opacity */
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto; /* 10% from the top and centered */
    padding: 2rem;
    border: none;
    width: 90%; 
    max-width: 400px; /* Max width for a clean look */
    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.4);
    position: relative;
    animation-name: animatetop;
    animation-duration: 0.4s
}

/* Add animations */
@keyframes animatetop {
    from {top: -300px; opacity: 0}
    to {top: 10%; opacity: 1}
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 15px;
    top: 5px;
    transition: color 0.2s;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#change-password-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#change-password-form label {
    align-self: flex-start;
    font-weight: bold;
    color: #333;
    margin-bottom: -0.5rem;
    margin-top: 0.5rem;
}

#change-password-form input[type="password"] {
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
}

#submit-change-password {
    background-color: #0044cc;
    color: white;
    padding: 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 1rem;
    transition: background-color 0.2s;
}

#submit-change-password:hover:not(:disabled) {
    background-color: #003399;
}
#submit-change-password:disabled {
    background-color: #a0c0e0;
    cursor: not-allowed;
}

#password-change-status {
    font-size: 0.9em;
    min-height: 1.5em; 
    margin-top: 0.5rem;
}
/* --- END NEW CODE FOR REQUEST #1 & #2 --- */