/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

/* Login Form */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.login-form {
  background: white;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 400px;
}

.login-form h2 {
  margin-bottom: 25px;
  color: #2c5282;
  text-align: center;
}

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

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 12px 15px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #2c5282;
}

#login-button {
  width: 100%;
  padding: 15px;
  font-size: 1.1rem;
  font-weight: 600;
  background-color: #2c5282;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#login-button:hover {
  background-color: #1a365d;
}

#login-button:disabled {
  background-color: #a0aec0;
  cursor: not-allowed;
}

.login-error {
  margin-top: 15px;
  padding: 10px;
  background-color: #fed7d7;
  color: #c53030;
  border-radius: 6px;
  text-align: center;
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  background-color: #f5f5f5;
  padding: 10px 0 15px 0;
  z-index: 100;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 15px;
}

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.header-bar h1 {
  font-size: 1.3rem;
  color: #2c5282;
  margin: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

#user-display {
  color: #666;
  font-size: 0.9rem;
}

#logout-button {
  padding: 6px 14px;
  font-size: 0.85rem;
  background-color: #e2e8f0;
  color: #4a5568;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#logout-button:hover {
  background-color: #cbd5e0;
}

/* Search box */
.search-box {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

#reset-button {
  padding: 15px 20px;
  font-size: 1rem;
  background-color: #e2e8f0;
  color: #4a5568;
  border: 2px solid #cbd5e0;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#reset-button:hover {
  background-color: #cbd5e0;
}

#search-input {
  flex: 1;
  padding: 15px 20px;
  font-size: 1.2rem;
  border: 2px solid #2c5282;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
  border-color: #1a365d;
  box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.2);
}

#search-input::placeholder {
  color: #a0aec0;
}

#strictness-select {
  padding: 15px 12px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  background-color: white;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 36px;
}

#strictness-select:focus {
  border-color: #2c5282;
}

#search-button {
  padding: 15px 40px;
  font-size: 1.2rem;
  font-weight: 600;
  background-color: #2c5282;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  min-width: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#search-button:hover {
  background-color: #1a365d;
}

#search-button:disabled {
  background-color: #a0aec0;
  cursor: not-allowed;
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #ffffff40;
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.hidden {
  display: none !important;
}

/* Instructions */
.instructions {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px 25px;
  margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.instructions-main {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: #333;
}

.instructions-detail {
  font-size: 0.95rem;
  margin-bottom: 15px;
  color: #666;
  font-style: italic;
}

.examples {
  color: #666;
}

.examples p {
  margin-bottom: 10px;
  font-size: 1rem;
}

.examples ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.examples li {
  display: inline;
}

.example-query {
  color: #2c5282;
  text-decoration: none;
  padding: 8px 16px;
  background-color: #e2e8f0;
  border-radius: 20px;
  font-size: 1rem;
  transition: background-color 0.2s;
  display: inline-block;
}

.example-query:hover {
  background-color: #cbd5e0;
}

/* Search tip */
.search-tip {
  text-align: center;
  margin-top: 15px;
  padding: 12px 20px;
  background-color: #fefcbf;
  border-radius: 8px;
  color: #744210;
  font-size: 1rem;
}

/* Results container */
.results-container {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  padding: 20px;
  margin-top: 20px;
}

.results {
  overflow-x: auto;
}

/* Summary */
.summary {
  padding: 15px;
  background-color: #f7fafc;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 1.05rem;
  line-height: 1.6;
}

.summary:empty {
  display: none;
}

/* Stats */
.stats {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-item {
  background: #edf2f7;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.95rem;
}

.stat-item strong {
  color: #2c5282;
}

/* Results table */
.results-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.results-table th,
.results-table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.results-table th {
  background-color: #f7fafc;
  font-weight: 600;
  color: #2c5282;
  position: sticky;
  top: 0;
}

.results-table tr:hover {
  background-color: #f7fafc;
}

.results-table td {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Expandable rows with related records */
.results-table tr.has-related {
  cursor: pointer;
}

.results-table tr.has-related:hover {
  background-color: #edf2f7;
}

.results-table tr.has-related.expanded {
  background-color: #e2e8f0;
}

.expand-col {
  width: 60px;
  min-width: 60px;
}

.expand-cell {
  width: 60px;
  min-width: 60px;
  text-align: center;
  white-space: nowrap;
}

.expand-arrow {
  color: #2c5282;
  font-size: 0.9rem;
  transition: transform 0.2s;
}

.related-count {
  color: #2c5282;
  font-weight: 600;
  font-size: 0.85rem;
  background-color: #e2e8f0;
  padding: 2px 6px;
  border-radius: 10px;
}

.related-row {
  background-color: #f0f7ff;
  border-left: 3px solid #2c5282;
}

.related-row td {
  font-size: 0.9rem;
  color: #555;
}

/* Source badge */
.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  text-decoration: none;
  transition: opacity 0.2s, transform 0.1s;
}

a.source-badge {
  cursor: pointer;
}

a.source-badge:hover {
  opacity: 0.8;
  transform: scale(1.05);
}

.source-badge.invoices {
  background-color: #c6f6d5;
  color: #276749;
}

.source-badge.forms {
  background-color: #bee3f8;
  color: #2b6cb0;
}

.source-badge.financial_help {
  background-color: #fed7d7;
  color: #c53030;
}

/* Invoice link */
.invoice-link {
  color: #2c5282;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.invoice-link:hover {
  color: #1a365d;
  text-decoration: underline;
}

/* No results */
.no-results {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

/* Error container */
.error-container {
  background-color: #fed7d7;
  border: 1px solid #fc8181;
  border-radius: 8px;
  padding: 15px 20px;
  margin-top: 20px;
  color: #c53030;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 40px;
  padding: 20px;
  color: #666;
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  .header-bar {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .header-bar h1 {
    font-size: 1.1rem;
  }

  .user-info {
    width: 100%;
    justify-content: space-between;
  }

  .search-box {
    flex-direction: column;
  }

  #search-button {
    width: 100%;
  }

  #reset-button {
    width: 100%;
  }

  #strictness-select {
    width: 100%;
  }

  .examples ul {
    flex-direction: column;
    align-items: stretch;
  }

  .example-query {
    text-align: center;
  }

  .stats {
    flex-direction: column;
  }

  .results-table {
    display: block;
    overflow-x: auto;
  }
}

/* Card view for mobile */
@media (max-width: 600px) {
  .results-cards {
    display: flex;
    flex-direction: column;
    gap: 15px;
  }

  .result-card {
    background: #f7fafc;
    border-radius: 8px;
    padding: 15px;
  }

  .result-card .field {
    margin-bottom: 8px;
  }

  .result-card .field-label {
    font-weight: 600;
    color: #2c5282;
    font-size: 0.85rem;
  }

  .result-card .field-value {
    color: #333;
  }

  .related-toggle {
    margin-top: 10px;
    padding: 8px 12px;
    background-color: #e2e8f0;
    border-radius: 6px;
    color: #2c5282;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
  }

  .related-cards {
    margin-top: 10px;
    padding-left: 10px;
    border-left: 3px solid #2c5282;
  }

  .related-card {
    background-color: #f0f7ff;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
  }

  .related-card .field-label {
    color: #4a5568;
  }
}
