/* Universal Box-Sizing */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Helper class for hiding elements via JavaScript */
.hidden {
  display: none !important;
}

/* Base HTML & Body Styles */
html {
  height: 100%;
}

body {
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f4f7f6; /* Light grey background for the entire page */
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center; /* Center the app container horizontally */
  align-items: flex-start; /* Align the app container to the top */
}

/* Main Application Container - Acts as the primary content card */
#due-diligence-app {
  background-color: #ffffff;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  padding: 30px;
  margin: 20px; /* Margin from viewport edges */
  max-width: 960px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center; /* Center content horizontally within the app */
}

/* Headings */
h1 {
  color: #2c3e50;
  text-align: center;
  margin-top: 0;
  margin-bottom: 30px;
  font-size: 2.8em;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  color: #2c3e50;
  font-size: 2em;
  margin-top: 20px;
  margin-bottom: 20px;
  text-align: center;
}

h3 {
  color: #34495e;
  font-size: 1.5em;
  margin-top: 15px;
  margin-bottom: 10px;
}

p {
  font-size: 1.1em;
  line-height: 1.6;
  color: #555;
  margin-bottom: 15px;
}

/* Query Form Section */
#query-form {
  background-color: #f9fbfb;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 25px;
  margin-bottom: 30px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#query-form label {
  font-size: 1.2em;
  color: #444;
  margin-bottom: 15px;
  font-weight: 600;
  text-align: center;
}

#query-form input[type="text"] {
  width: 100%;
  max-width: 600px;
  padding: 12px 15px;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 1em;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#query-form input[type="text"]:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

#query-form button {
  background-color: #3498db;
  color: white;
  padding: 12px 25px;
  border: none;
  border-radius: 5px;
  font-size: 1.1em;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  font-weight: 600;
  letter-spacing: 0.03em;
}

#query-form button:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
}

#query-form button:active {
  transform: translateY(0);
}

/* Loading Indicator */
#loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.1em;
  color: #3498db;
  margin-bottom: 20px;
  padding: 10px 0;
  font-weight: 500;
}

/* Simple spinner animation */
#loading-indicator::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 3px solid #3498db;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Status Messages */
.status-message {
  padding: 10px 20px;
  border-radius: 5px;
  margin-bottom: 20px;
  font-size: 1em;
  text-align: center;
  width: 100%;
  max-width: 600px;
  opacity: 0; /* Hidden by default */
  transition: opacity 0.3s ease, visibility 0.3s ease;
  visibility: hidden; /* Ensure it doesn't take up space when hidden */
}

/* Show status message when it has content (script.js populates textContent) */
.status-message:not(:empty) {
  opacity: 1;
  visibility: visible;
}

.status-info {
  background-color: #eaf6fa;
  color: #2c3e50;
  border: 1px solid #aed6f1;
}

.status-loading {
  background-color: #fefce8;
  color: #8a6d3b;
  border: 1px solid #faebcc;
}

.status-success {
  background-color: #e6fae6;
  color: #28a745;
  border: 1px solid #c3e6cb;
}

.status-error {
  background-color: #fbe6e6;
  color: #dc3545;
  border: 1px solid #f5c6cb;
}

/* Results Dashboard */
#results-dashboard {
  background-color: #f9fbfb;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 25px;
  min-height: 300px; /* Ensure some height even with no results */
  width: 100%;
  display: none; /* Hidden by default, script shows it */
  flex-direction: column;
  gap: 20px;
}

/* Show results dashboard when it has content (script.js populates innerHTML) */
#results-dashboard:not(:empty) {
    display: flex; /* Override initial display: none */
}

/* Results Controls (Filter & Sort) */
#results-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px; /* Increased gap for select boxes */
  margin-bottom: 25px; /* Adjust margin */
  padding: 15px 0; /* Adjust padding */
  border-bottom: 1px solid #eee;
  border-top: 1px solid #eee;
  width: 100%;
  align-items: center;
}

#results-controls label {
  font-weight: 600;
  color: #555;
  font-size: 1em;
  white-space: nowrap;
}

#results-controls select {
  padding: 10px 15px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background-color: #fefefe;
  font-size: 1em;
  color: #333;
  cursor: pointer;
  appearance: none; /* Remove default browser styling */
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333333%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13%205.7L146.2%20202.7%2018.8%2075.1a17.6%2017.6%200%200%200-25.3%2024.5l137.9%20145.9a17.6%2017.6%200%200%200%2025.3%200l137.9-145.9a17.6%2017.6%200%200%200-12.9-30.2z%22%2F%3E%3C%2Fsvg%3E');
  background-repeat: no-repeat;
  background-position: right 10px top 50%;
  background-size: 12px auto;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  min-width: 150px; /* Ensure a decent width */
}

#results-controls select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* No Results Message */
#no-results-message {
  text-align: center;
  padding: 30px;
  color: #666;
  font-style: italic;
  background-color: #f0f0f0;
  border-radius: 8px;
  margin-top: 20px;
}
#no-results-message p {
  margin-bottom: 0; /* Remove default paragraph margin */
}

/* Summary Card */
.summary-card {
  background-color: #ffffff;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.summary-card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.6em;
    color: #34495e;
}

.summary-card p {
    font-size: 1em;
    color: #666;
    margin-bottom: 0;
}

/* Risk Levels */
.risk-level {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9em;
  margin-left: 10px;
}

.risk-low {
  background-color: #e6fae6;
  color: #28a745; /* Green */
}

.risk-medium {
  background-color: #fff3e6;
  color: #f39c12; /* Orange */
}

.risk-high {
  background-color: #fbe6e6;
  color: #dc3545; /* Red */
}

/* Findings List */
.findings-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Responsive grid */
  gap: 20px;
}

/* Individual Finding Card */
.finding-card {
  background-color: #ffffff;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.finding-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.finding-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.9em;
  color: #777;
}

.finding-category {
  background-color: #ecf0f1;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 500;
  color: #444;
}

.finding-date {
  font-style: italic;
}

.finding-card h3 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 1.3em;
  line-height: 1.4;
}

.finding-card h3 a {
  color: #3498db;
  text-decoration: none;
  transition: color 0.2s ease;
}

.finding-card h3 a:hover {
  color: #2980b9;
  text-decoration: underline;
}

.finding-card p {
  font-size: 0.95em;
  color: #666;
  flex-grow: 1; /* Allow description to take available space */
  margin-bottom: 15px;
}

.finding-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85em;
  color: #777;
  margin-top: auto; /* Push meta to the bottom of the card */
}

.finding-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Sentiment Colors */
.sentiment {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
  font-size: 0.85em;
}

.sentiment-positive {
  background-color: #e6fae6;
  color: #28a745; /* Green */
}

.sentiment-neutral {
  background-color: #e0e6e9;
  color: #555; /* Grey */
}

.sentiment-negative {
  background-color: #fff3e6;
  color: #f39c12; /* Orange */
}

.sentiment-critical {
  background-color: #fbe6e6;
  color: #dc3545; /* Red */
}

/* Responsive Design */
@media (max-width: 768px) {
  #due-diligence-app {
    padding: 20px;
    margin: 15px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  }
  h1 {
    font-size: 2.2em;
    margin-bottom: 25px;
  }
  h2 {
    font-size: 1.8em;
  }
  p {
    font-size: 1em;
    margin-bottom: 20px;
  }
  #query-form, #results-dashboard {
    padding: 20px;
  }
  #query-form button {
    padding: 10px 20px;
    font-size: 1em;
  }
  #results-controls {
    justify-content: flex-start; /* Align filters left on smaller screens */
    overflow-x: auto; /* Allow horizontal scrolling if many filters */
    padding-bottom: 5px; /* Space for scrollbar */
  }
  #results-controls label, #results-controls select {
    flex-shrink: 0; /* Prevent items from shrinking */
  }
  .findings-list {
    grid-template-columns: 1fr; /* Single column on smaller screens */
  }
}

@media (max-width: 480px) {
  #due-diligence-app {
    padding: 15px;
    margin: 10px;
    border-radius: 5px;
  }
  h1 {
    font-size: 1.8em;
    margin-bottom: 15px;
  }
  h2 {
    font-size: 1.5em;
  }
  p {
    font-size: 0.95em;
    margin-bottom: 15px;
  }
  #query-form, #results-dashboard {
    padding: 15px;
  }
  #query-form label {
    font-size: 1.1em;
    margin-bottom: 10px;
  }
  #query-form input[type="text"] {
    padding: 10px;
    margin-bottom: 15px;
  }
  #query-form button {
    padding: 8px 18px;
    font-size: 0.95em;
  }
  .summary-card h3 {
    font-size: 1.4em;
  }
  .risk-level, .sentiment {
    font-size: 0.8em;
    padding: 3px 6px;
  }
  .finding-meta {
    flex-direction: column; /* Stack meta items vertically */
    gap: 5px;
  }
}