@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Design Tokens (Clinical Clarity) ─── */
:root {
  /* Primary */
  --primary:              #091426;
  --on-primary:           #ffffff;
  --primary-container:    #1e293b;
  --on-primary-container: #8590a6;
  --inverse-primary:      #bcc7de;

  /* Secondary */
  --secondary:              #0051d5;
  --on-secondary:           #ffffff;
  --secondary-container:    #316bf3;
  --on-secondary-container: #fefcff;

  /* Tertiary */
  --tertiary:              #001815;
  --on-tertiary:           #ffffff;
  --tertiary-container:    #002f2a;
  --on-tertiary-container: #28a094;

  /* Error */
  --error:              #ba1a1a;
  --on-error:           #ffffff;
  --error-container:    #ffdad6;
  --on-error-container: #93000a;

  /* Surfaces */
  --surface:                    #f7f9fb;
  --surface-dim:                #d8dadc;
  --surface-bright:             #f7f9fb;
  --surface-container-lowest:   #ffffff;
  --surface-container-low:      #f2f4f6;
  --surface-container:          #eceef0;
  --surface-container-high:     #e6e8ea;
  --surface-container-highest:  #e0e3e5;
  --on-surface:                 #191c1e;
  --on-surface-variant:         #45474c;
  --inverse-surface:            #2d3133;
  --inverse-on-surface:         #eff1f3;
  --surface-tint:               #545f73;
  --surface-variant:            #e0e3e5;

  /* Outline */
  --outline:         #75777d;
  --outline-variant: #c5c6cd;

  /* Fixed accents */
  --primary-fixed:            #d8e3fb;
  --primary-fixed-dim:        #bcc7de;
  --on-primary-fixed:         #111c2d;
  --on-primary-fixed-variant: #3c475a;
  --secondary-fixed:          #dbe1ff;
  --secondary-fixed-dim:      #b4c5ff;
  --on-secondary-fixed:       #00174b;

  /* Semantic aliases */
  --action-accent:     #2563EB;
  --contribution-teal: #0D9488;
  --surface-subtle:    #F1F5F9;
  --text-muted:        #64748B;
  --border-light:      #E2E8F0;
  --background:        #f7f9fb;
  --on-background:     #191c1e;

  /* Spacing */
  --margin-page:         2rem;
  --margin-mobile:       1rem;
  --gutter-grid:         1.5rem;
  --card-padding:        1.5rem;
  --stack-gap:           0.75rem;
  --container-max-width: 1200px;

  /* Rounded */
  --rounded-sm:   0.25rem;
  --rounded:      0.5rem;
  --rounded-md:   0.75rem;
  --rounded-lg:   1rem;
  --rounded-xl:   1.5rem;
  --rounded-full: 9999px;
}

/* ─── Reset ─── */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, Arial, sans-serif;
  margin: 0;
  background: var(--background);
  color: var(--on-background);
  font-size: 16px;
  line-height: 24px;
}

/* ─── Header ─── */
header {
  background: var(--surface-container-low);
  padding: 20px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(25, 28, 30, 0.06);
  border-bottom: 1px solid var(--border-light);
}

h1 {
  margin: 0;
  color: var(--primary-container);
  font-size: 32px;
  font-weight: 700;
  line-height: 40px;
  letter-spacing: -0.02em;
}

.lead {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 24px;
}

/* ─── Controls ─── */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ─── Buttons ─── */
.btn {
  background: var(--surface-subtle);
  border: 1px solid var(--border-light);
  padding: 8px 16px;
  border-radius: var(--rounded-lg);
  cursor: pointer;
  color: var(--on-surface);
  font-weight: 600;
  font-size: 14px;
  line-height: 16px;
  letter-spacing: 0.01em;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.1s ease;
}

.btn:hover {
  background: var(--surface-container-high);
  border-color: var(--outline-variant);
  transform: translateY(-1px);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}

.btn.ghost:hover {
  background: var(--surface-subtle);
  color: var(--on-surface);
}

.btn.primary {
  background: var(--action-accent);
  color: var(--on-primary);
  border-color: var(--action-accent);
}

.btn.primary:hover {
  background: var(--secondary);
  border-color: var(--secondary);
}

.btn.secondary {
  background: var(--contribution-teal);
  color: var(--on-tertiary);
  border-color: var(--contribution-teal);
}

.btn.secondary:hover {
  background: #0b8278;
  border-color: #0b8278;
}

/* ─── Main ─── */
main {
  padding: var(--margin-page);
  max-width: var(--container-max-width);
  margin: 0 auto;
}

/* ─── Grid ─── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--gutter-grid);
}

/* ─── Cards ─── */
.card {
  background: var(--surface-container-lowest);
  padding: var(--card-padding);
  border-radius: var(--rounded);
  box-shadow: 0 2px 8px rgba(25, 28, 30, 0.04);
  cursor: pointer;
  text-align: center;
  border: 1px solid var(--border-light);
  transition: all 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--outline-variant);
  background: var(--surface-subtle);
  box-shadow: 0 6px 18px rgba(25, 28, 30, 0.08);
}

.card h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary-container);
}

.meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ─── Modal (base overlay) ─── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(25, 28, 30, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}

.modal-content {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-radius: var(--rounded);
  padding: 25px;
  width: 90%;
  max-width: 600px;
  max-height: 80%;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(25, 28, 30, 0.18);
  border: 1px solid var(--border-light);
  color: var(--on-surface);
}

.modal-box {
  width: 100%;
  max-width: 800px;
  background: var(--surface-container);
  border-radius: var(--rounded);
  padding: 20px;
  position: relative;
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(25, 28, 30, 0.22);
  border: 1px solid var(--border-light);
}

.modal .close {
  position: absolute;
  right: 15px;
  top: 10px;
  font-size: 30px;
  font-weight: bold;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: color 0.3s ease, transform 0.2s ease;
}

.modal .close:hover {
  color: var(--error);
  transform: scale(1.2);
}

.close-btn {
  position: absolute;
  right: 14px;
  top: 14px;
  background: var(--error);
  color: var(--on-error);
  border: none;
  padding: 8px 10px;
  border-radius: var(--rounded);
  cursor: pointer;
  transition: background 0.15s ease;
}

.close-btn:hover {
  background: #a01616;
}

.modal-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 8px;
}

/* ─── Search Input (Modal) ─── */
#searchInput {
  width: 100% !important;
  padding: 8px 40px 8px 12px;
  border-radius: var(--rounded);
  border: 1px solid var(--border-light);
  font-size: 15px;
  outline: none;
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#searchInput:focus {
  border-color: var(--action-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* ─── Topic Rows ─── */
.topic-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content max-content;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--rounded);
  border: 1px solid var(--border-light);
  margin-bottom: 10px;
  background: var(--surface-container-lowest);
  transition: background 0.15s ease;
}

.topic-row:hover {
  background: var(--surface-subtle);
}

.topic-main {
  min-width: 0;
}

.topic-name {
  font-weight: 600;
  color: var(--on-surface);

  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;

  /* Default: medium screens */
  -webkit-line-clamp: 2;
}
/* Small screens (phones) */
@media (max-width: 480px) {
  .topic-name {
    -webkit-line-clamp: 1;
    font-size: 0.9rem;
  }
}

/* Tablets */
@media (min-width: 481px) and (max-width: 768px) {
  .topic-name {
    -webkit-line-clamp: 2;
  }
}

/* Laptops */
@media (min-width: 769px) and (max-width: 1200px) {
  .topic-name {
    -webkit-line-clamp: 3;
  }
}

/* Large / widescreen displays */
@media (min-width: 1201px) {
  .topic-name {
    -webkit-line-clamp: 4;
  }
}

.download-btn {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--rounded);
  border: 1px solid var(--border-light);
  background: var(--surface-container-lowest);
  color: var(--action-accent);
  font-weight: 600;
  white-space: nowrap;
  justify-self: end;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.download-btn:hover {
  background: var(--surface-subtle);
  border-color: var(--action-accent);
}

.topic-size {
  white-space: nowrap;
  justify-self: end;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── Notice ─── */
.notice {
  background: var(--error-container);
  padding: 10px;
  border-radius: var(--rounded);
  border: 1px solid #f5c6c2;
  color: var(--on-error-container);
  margin-bottom: 12px;
}

.small {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.text-muted {
  color: var(--text-muted);
}

.center {
  display: flex;
  justify-content: center;
}

/* ─── Footer ─── */
footer {
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Instructions Modal ─── */
#instructionsModal ul {
  list-style: disc;
  margin-left: 20px;
  color: var(--on-surface);
}

#instructionsModal h2 {
  margin-top: 0;
  color: var(--action-accent);
}

/* ─── Global Search ─── */
#globalSearchContainer {
  display: flex;
  width: 100%;
  justify-content: center;
  padding: 10px 0;
  background: var(--surface-container-low);
  box-shadow: 0 2px 5px rgba(25, 28, 30, 0.06);
}

.search-wrapper {
  position: relative;
  width: 90%;
  max-width: 900px;
}

#globalSearch {
  width: 100%;
  padding: 10px 40px 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--rounded);
  font-size: 15px;
  outline: none;
  background-color: var(--surface-container-lowest);
  color: var(--on-surface);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#globalSearch:focus {
  border-color: var(--action-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

#clearSearch {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 22px;
  color: var(--outline);
  cursor: pointer;
  display: none;
  user-select: none;
  transition: color 0.2s ease;
}

#clearSearch:hover {
  color: var(--error);
}

mark {
  background: #fef08a;
  color: var(--on-surface);
  font-weight: bold;
  border-radius: 3px;
  padding: 0 2px;
}

.topic-presenter {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-style: italic;
}

@media (max-width: 600px) {
  #globalSearch {
    font-size: 14px;
  }
  #clearSearch {
    right: 8px;
    font-size: 20px;
  }
  #clearSearch:hover {
    color: var(--error);
  }
  .download-btn {
    font-size: 12px;
  }
  h1 {
    font-size: 24px;
    line-height: 32px;
  }
}

/* ─── Search Results ─── */
#searchResults {
  max-width: 900px;
  margin: 20px auto;
  background: var(--surface-container-lowest);
  border-radius: var(--rounded);
  box-shadow: 0 4px 20px rgba(25, 28, 30, 0.08);
  border: 1px solid var(--border-light);
  overflow: hidden;
  display: none;
  animation: fadeIn 0.3s ease;
}

.result-item {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.2s ease;
}

.result-item:hover {
  background: var(--surface-subtle);
}

.result-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-container);
}

.result-meta {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.8rem;
  color: var(--on-secondary-container);
  background: var(--secondary-container);
  padding: 2px 8px;
  border-radius: var(--rounded-sm);
}

.result-type {
  font-size: 0.9rem;
  color: var(--on-surface-variant);
  margin-top: 4px;
}

.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Layout: sidebar + content ─── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: flex-start;
}

/* ─── Sidebar ─── */
#sidebar {
  background: var(--surface-container-lowest);
  border-radius: var(--rounded);
  box-shadow: 0 2px 8px rgba(25, 28, 30, 0.04);
  border: 1px solid var(--border-light);
  padding: 16px;
  max-height: calc(100vh - 180px);
  position: sticky;
  top: 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 2px;
}

.sidebar-subtitle {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

/* System filter buttons in sidebar */
#sidebar #systemFilters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  margin-bottom: 10px;
  max-height: 260px;
  overflow-y: auto;
}

/* Base style for each system button */
#sidebar #systemFilters .btn {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border-radius: var(--rounded-full);
  padding: 6px 10px;
  font-size: 0.9rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border-light);
  color: var(--on-surface);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

#sidebar #systemFilters .btn:hover {
  background: var(--surface-container-high);
  border-color: var(--outline-variant);
  transform: translateY(-1px);
}

/* Active system */
#sidebar #systemFilters .btn.primary {
  background: var(--action-accent);
  border-color: var(--action-accent);
  color: var(--on-primary);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

/* Small dot before system name */
#sidebar #systemFilters .btn::before {
  content: "●";
  font-size: 0.55rem;
  color: var(--contribution-teal);
}

/* Active dot color */
#sidebar #systemFilters .btn.primary::before {
  color: var(--inverse-on-surface);
}

/* Content area */
#content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Responsive: stack sidebar on top for small screens */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  #sidebar {
    position: static;
    max-height: none;
    order: -1;
  }

  main {
    padding: var(--margin-mobile);
  }
}

/* ─── Sidebar collapse ─── */
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 8px;
}

.sidebar-header:hover .sidebar-title {
  color: var(--action-accent);
}

.sidebar-toggle-icon {
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  justify-content: left;
}

.sidebar-header.collapsed .sidebar-toggle-icon {
  transform: rotate(-90deg);
}

#systemsSection {
  margin-top: 6px;
  transition: max-height 0.2s ease, opacity 0.2s ease, margin-top 0.2s ease;
  overflow: hidden;
}

#systemsSection.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

/* Desktop-only sideways collapse */
@media (min-width: 769px) {
  .layout.sidebar-collapsed {
    grid-template-columns: 70px 1fr;
  }

  .layout.sidebar-collapsed #sidebar {
    padding: 12px 8px;
    align-items: center;
  }

  .layout.sidebar-collapsed #systemsSection {
    display: none;
  }

  .layout.sidebar-collapsed .sidebar-subtitle {
    display: none;
  }

  .layout.sidebar-collapsed .sidebar-header {
    justify-content: center;
  }

  .layout.sidebar-collapsed .sidebar-title {
    font-size: 0.85rem;
    text-align: center;
  }
}

/* ─── Bottom Actions Footer ─── */
#bottomActions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px;
  border-top: 1px solid var(--border-light);
}

/* ─── Upload / Suggest Modals ─── */
#suggestModal textarea,
#uploadModal input[type="text"],
#uploadModal select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--rounded);
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  outline: none;
  transition: border-color 0.2s ease;
}

#suggestModal textarea:focus,
#uploadModal input[type="text"]:focus,
#uploadModal select:focus {
  border-color: var(--action-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

#suggestModal label,
#uploadModal label {
  display: block;
  margin: 10px 0 4px;
  font-weight: 600;
  font-size: 14px;
  color: var(--on-surface);
}

#suggestModal h3,
#uploadModal h3 {
  color: var(--primary-container);
  margin-top: 0;
}
