* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 20px;
  padding: 30px 0;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

h1 {
  font-size: 2.5rem;
  color: #2c3e50;
  margin-bottom: 10px;
}

.subtitle {
  color: #7f8c8d;
  font-size: 1.1rem;
}

.tab-nav {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid #3498db;
  border-radius: 6px;
  background-color: transparent;
  color: #3498db;
  cursor: pointer;
  transition: all 0.3s;
}

.tab-btn:hover {
  background-color: #ebf5fb;
}

.tab-btn.active {
  background-color: #3498db;
  color: #fff;
}

.search-section {
  background-color: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 30px;
}

.search-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 250px;
  padding: 12px 16px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 6px;
  transition: border-color 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: #3498db;
}

.country-select {
  padding: 12px 16px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 6px;
  background-color: #fff;
  cursor: pointer;
  transition: border-color 0.3s;
}

.country-select:focus {
  outline: none;
  border-color: #3498db;
}

.btn {
  padding: 12px 24px;
  font-size: 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
}

.btn-primary {
  background-color: #3498db;
  color: #fff;
}

.btn-primary:hover {
  background-color: #2980b9;
}

.btn-secondary {
  background-color: #27ae60;
  color: #fff;
}

.btn-secondary:hover {
  background-color: #229954;
}

.btn:disabled {
  background-color: #bdc3c7;
  cursor: not-allowed;
  opacity: 0.6;
}

.results-section {
  background-color: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.loading {
  text-align: center;
  padding: 40px;
  font-size: 1.2rem;
  color: #7f8c8d;
}

.results-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 15px;
  background-color: #ecf0f1;
  border-radius: 6px;
  font-weight: 600;
  color: #2c3e50;
}

.last-updated {
  font-weight: normal;
  font-size: 0.9rem;
  color: #7f8c8d;
}

.no-results {
  text-align: center;
  padding: 60px 20px;
  color: #7f8c8d;
  font-size: 1.1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

thead {
  background-color: #34495e;
  color: #fff;
}

th {
  padding: 15px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #2c3e50;
}

th:first-child {
  width: 50px;
  text-align: center;
}

tbody tr {
  border-bottom: 1px solid #ecf0f1;
  transition: background-color 0.2s;
}

tbody tr:hover {
  background-color: #f8f9fa;
}

tbody tr:last-child {
  border-bottom: none;
}

td {
  padding: 15px;
}

td:first-child {
  text-align: center;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.hidden, .login-screen.hidden {
  display: none !important;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid #ecf0f1;
}

.btn-page {
  padding: 10px 20px;
  background-color: #3498db;
  color: #fff;
}

.btn-page:hover:not(:disabled) {
  background-color: #2980b9;
}

.btn-page:disabled {
  background-color: #bdc3c7;
  cursor: not-allowed;
  opacity: 0.6;
}

.page-info {
  font-weight: 600;
  color: #2c3e50;
  min-width: 120px;
  text-align: center;
}

@media (max-width: 768px) {
  .search-controls {
    flex-direction: column;
  }

  .search-input,
  .country-select,
  .btn {
    width: 100%;
  }

  table {
    font-size: 0.9rem;
  }

  th, td {
    padding: 10px;
  }

  h1 {
    font-size: 2rem;
  }
}

/* Sortable columns */
.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s;
}

.sortable:hover {
  background-color: #2c3e50;
}

.sortable.sorted {
  background-color: #2c3e50;
}

.sort-icon {
  font-size: 0.8rem;
  margin-left: 4px;
}

/* Tab description section */
.tab-description {
  background-color: #fff;
  padding: 24px 30px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 20px;
}

.tab-description h2 {
  font-size: 1.4rem;
  color: #2c3e50;
  margin-bottom: 10px;
}

.tab-description p {
  color: #555;
  margin-bottom: 15px;
  line-height: 1.6;
}

.data-sources {
  background-color: #f8f9fa;
  border-radius: 6px;
  padding: 15px;
  margin-bottom: 15px;
}

.source {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #ecf0f1;
}

.source:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.source:first-child {
  padding-top: 0;
}

.source-label {
  font-weight: 600;
  color: #2c3e50;
  min-width: 120px;
}

.source-info {
  color: #666;
}

.tab-description .tip {
  background-color: #ebf5fb;
  border-left: 4px solid #3498db;
  padding: 12px 15px;
  margin-bottom: 0;
  border-radius: 0 6px 6px 0;
}

/* Source links */
.source-info a {
  color: #3498db;
  text-decoration: none;
  font-weight: 500;
}

.source-info a:hover {
  text-decoration: underline;
  color: #2980b9;
}

/* Login Screen */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-container {
  text-align: center;
  padding: 40px;
}

.login-logo {
  max-width: 500px;
  width: 90%;
  height: auto;
  margin-bottom: 50px;
}

#googleSignInBtn {
  display: flex;
  justify-content: center;
}

/* Header with user info */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  margin-bottom: 40px;
  padding: 20px 30px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
  margin-bottom: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background-color: #f8f9fa;
  border-radius: 25px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

#userName {
  font-weight: 500;
  color: #2c3e50;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
  background-color: #e74c3c;
  color: #fff;
}

.btn-small:hover {
  background-color: #c0392b;
}

.tab-nav {
  margin-top: 0;
}

@media (max-width: 768px) {
  header {
    flex-direction: column;
    text-align: center;
    gap: 15px;
  }

  .header-right {
    flex-direction: column;
  }

  .user-info {
    flex-wrap: wrap;
    justify-content: center;
  }

  #userName {
    max-width: 100%;
  }
}

/* Sub-tabs (within Logbook) */
.sub-tab-nav {
  display: flex;
  gap: 0;
  margin: 15px 0;
  border-bottom: 2px solid #e5e7eb;
}

.sub-tab-btn {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  background: none;
  color: #7f8c8d;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.sub-tab-btn:hover {
  color: #3498db;
}

.sub-tab-btn.active {
  color: #3498db;
  border-bottom-color: #3498db;
}

.sub-tab-content {
  margin-top: 10px;
}

.sub-tab-intro {
  color: #555;
  margin-bottom: 10px;
  line-height: 1.6;
}

/* Accordion */
.accordion-item {
  border: 1px solid #ddd;
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header,
.category-header {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 14px 18px;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 1rem;
  text-align: left;
  gap: 12px;
  transition: background-color 0.2s;
}

.accordion-header:hover {
  background-color: #ebf5fb;
}

.category-header {
  padding: 10px 18px 10px 28px;
  font-size: 0.95rem;
  border-top: 1px solid #ecf0f1;
}

.category-header:hover {
  background-color: #f8f9fa;
}

.accordion-header.active {
  background-color: #3498db;
  color: #fff;
}

.accordion-header.active .accordion-meta {
  color: rgba(255, 255, 255, 0.8);
}

.category-header.active {
  background-color: #f0f7fc;
  font-weight: 600;
}

.accordion-title,
.category-title {
  flex: 1;
  font-weight: 600;
}

.category-title {
  font-weight: 500;
}

.accordion-meta {
  font-size: 0.85rem;
  color: #7f8c8d;
  white-space: nowrap;
}

.accordion-chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.accordion-header.active .accordion-chevron,
.category-header.active .accordion-chevron {
  transform: rotate(45deg);
}

.accordion-body,
.operations-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-body.open {
  max-height: 5000px;
}

.operations-list.open {
  max-height: 2000px;
}

.operations-list {
  list-style: disc;
  margin: 0;
  padding: 0 18px 0 56px;
}

.operations-list.open {
  padding-bottom: 12px;
}

.operations-list li {
  padding: 4px 0;
  color: #555;
  font-size: 0.9rem;
  line-height: 1.5;
}

.logbook-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 15px 0 5px;
}

#logbookContent {
  margin-top: 20px;
}

.access-denied {
  margin-top: 30px;
  padding: 20px;
  background-color: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  text-align: center;
}

.access-denied p {
  margin: 0;
}

/* SNOMED Badge (Logbook) */
.snomed-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  margin-left: 8px;
  cursor: pointer;
  vertical-align: middle;
  transition: opacity 0.2s;
}

.snomed-badge:hover {
  opacity: 0.8;
}

.snomed-badge-auto {
  background-color: #dbeafe;
  color: #1e40af;
}

.snomed-badge-confirmed {
  background-color: #d1fae5;
  color: #065f46;
}

.snomed-badge-needs_review {
  background-color: #fef3c7;
  color: #92400e;
}

.snomed-badge-unmatched {
  background-color: #fee2e2;
  color: #991b1b;
}

/* SNOMED Mapping Tab */
.snomed-stats {
  margin: 15px 0;
}

.stat-bar-container {
  background-color: #e5e7eb;
  border-radius: 8px;
  height: 24px;
  overflow: hidden;
  margin-bottom: 10px;
}

.stat-bar {
  display: flex;
  height: 100%;
}

.stat-segment {
  height: 100%;
  transition: width 0.3s ease;
}

.stat-segment.stat-auto { background-color: #3b82f6; }
.stat-segment.stat-confirmed { background-color: #10b981; }
.stat-segment.stat-review { background-color: #f59e0b; }
.stat-segment.stat-unmatched { background-color: #ef4444; }
.stat-segment.stat-unmapped { background-color: #d1d5db; }

.stat-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.9rem;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #555;
}

.stat-label.stat-total {
  font-weight: 700;
  color: #2c3e50;
}

.stat-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.stat-dot.stat-auto { background-color: #3b82f6; }
.stat-dot.stat-confirmed { background-color: #10b981; }
.stat-dot.stat-review { background-color: #f59e0b; }
.stat-dot.stat-unmatched { background-color: #ef4444; }
.stat-dot.stat-unmapped { background-color: #d1d5db; }

/* Auto Match & Clear buttons */
.snomed-actions {
  display: flex;
  gap: 10px;
  margin: 15px 0;
}

.btn-danger {
  background-color: #e74c3c;
  color: #fff;
}

.btn-danger:hover {
  background-color: #c0392b;
}

/* Auto-match progress */
.auto-match-progress {
  margin: 15px 0;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.auto-match-status {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
}

.auto-match-bar {
  height: 100%;
  background-color: #3b82f6;
  border-radius: 8px;
  transition: width 0.3s ease;
}

.auto-match-details {
  margin-top: 8px;
  font-size: 0.9rem;
  color: #555;
}

.snomed-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 15px 0;
}

.snomed-filters .search-input {
  flex: 1;
  min-width: 200px;
}

.snomed-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.snomed-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  background-color: #34495e;
  color: #fff;
  border-bottom: 2px solid #2c3e50;
  white-space: nowrap;
}

.snomed-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #ecf0f1;
  vertical-align: middle;
}

.snomed-table tbody tr:hover {
  background-color: #f8f9fa;
}

/* Status badges */
.status-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.status-auto { background-color: #dbeafe; color: #1e40af; }
.status-confirmed { background-color: #d1fae5; color: #065f46; }
.status-needs_review { background-color: #fef3c7; color: #92400e; }
.status-unmatched { background-color: #fee2e2; color: #991b1b; }
.status-unmapped { background-color: #f3f4f6; color: #6b7280; }

/* Action buttons */
.action-cell {
  white-space: nowrap;
}

.btn-action {
  padding: 4px 10px;
  font-size: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  margin: 0 2px;
  background-color: #fff;
  color: #333;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-action:hover {
  background-color: #f0f0f0;
}

.btn-search-snomed { border-color: #3b82f6; color: #3b82f6; }
.btn-search-snomed:hover { background-color: #eff6ff; }
.btn-confirm { border-color: #10b981; color: #10b981; }
.btn-confirm:hover { background-color: #ecfdf5; }
.btn-remove { border-color: #ef4444; color: #ef4444; }
.btn-remove:hover { background-color: #fef2f2; }
.btn-select-snomed { border-color: #10b981; color: #10b981; }
.btn-select-snomed:hover { background-color: #ecfdf5; }

.snomed-code-link {
  color: #3b82f6;
  text-decoration: none;
  font-family: monospace;
  font-weight: 500;
}

.snomed-code-link:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid #ecf0f1;
}

.modal-header h3 {
  font-size: 1.2rem;
  color: #2c3e50;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #7f8c8d;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: #2c3e50;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
}

.modal-operation-name {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 12px;
}

.modal-search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.modal-search-row .search-input {
  flex: 1;
}

.modal-results {
  max-height: 400px;
  overflow-y: auto;
}

.modal-result-item {
  padding: 12px;
  border: 1px solid #ecf0f1;
  border-radius: 6px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.modal-result-item:hover {
  background-color: #f8f9fa;
}

.modal-result-main {
  flex: 1;
  min-width: 200px;
}

.modal-result-code {
  font-family: monospace;
  font-weight: 600;
  color: #3b82f6;
  margin-right: 10px;
}

.modal-result-display {
  color: #2c3e50;
}

.modal-result-fsn {
  width: 100%;
  font-size: 0.85rem;
  color: #7f8c8d;
  font-style: italic;
}

/* Concept detail */
.concept-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.concept-field {
  display: flex;
  gap: 12px;
}

.concept-label {
  font-weight: 600;
  color: #2c3e50;
  min-width: 90px;
  flex-shrink: 0;
}

.concept-value {
  color: #555;
  word-break: break-word;
}

.concept-list {
  list-style: disc;
  margin: 0;
  padding-left: 20px;
  color: #555;
}

.concept-list li {
  padding: 2px 0;
}

/* Responsive adjustments for SNOMED table */
@media (max-width: 1024px) {
  .snomed-table {
    font-size: 0.8rem;
  }

  .snomed-table th,
  .snomed-table td {
    padding: 6px 8px;
  }
}

@media (max-width: 768px) {
  .snomed-filters {
    flex-direction: column;
  }

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

  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
}
