body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: #f5f5f7;
  color: #222;
}

.topbar {
  background: #111827;
  color: white;
  padding: 1rem 2rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
}

.topbar p {
  margin: 0.25rem 0 0;
  opacity: 0.8;
  font-size: 0.9rem;
}

/* Equal width columns that CAN shrink: minmax(0, 1fr) */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  gap: 1rem;
  padding: 1rem 2rem 2rem;
  grid-template-areas:
    "upload summary"
    "calendar calendar"
    "table map"
    "downloads downloads";
}

.panel {
  background: white;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  min-width: 0; /* allow grid items to shrink instead of forcing column wider */
}

/* Panels paired in rows should visually match in width & basic height */
.upload-panel,
.summary-panel {
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.upload-panel { grid-area: upload; }
.summary-panel { grid-area: summary; }
.calendar-panel { grid-area: calendar; }
.table-panel { grid-area: table; display: flex; flex-direction: column; }
.map-panel { grid-area: map; display: flex; flex-direction: column; }
.downloads-panel { grid-area: downloads; }

h2 {
  margin-top: 0;
  font-size: 1.2rem;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.4rem;
  margin-bottom: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-fullscreen-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}

.panel-fullscreen-btn:hover {
  background: #e5e7eb;
}

/* Fullscreen behavior */
.panel.fullscreen {
  position: fixed;
  inset: 0;
  margin: 0;
  border-radius: 0;
  z-index: 9999;
  background: white;
  box-shadow: none;
}

/* Upload form */
#upload-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

#file-input {
  flex: 1;
}

button {
  background: #2563eb;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

button:hover:not([disabled]) {
  background: #1d4ed8;
}

.status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #4b5563;
}

/* Executive summary area uses available height with its own scroll */
#executive-summary {
  font-size: 0.9rem;
  line-height: 1.5;
  max-height: 260px;
  overflow-y: auto;
}

.summary-panel.fullscreen #executive-summary {
  max-height: calc(100vh - 80px);
}

/* Calendar */
#calendar {
  max-width: 100%;
}

/* Make calendar able to scroll horizontally if needed (2-month view) */
.fc-scroller {
  overflow-x: auto !important;
}

/* Calendar list: fixed height + vertical scroll */
#calendar-table-container {
  max-height: 320px;
  overflow-y: auto;
  overflow-x: auto;
}

/* Table: allow horizontal scroll if needed */
table {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 1;
}

th, td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

tr:nth-child(even) td {
  background: #f9fafb;
}

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid rgba(0,0,0,0.1);
}

.pill-consultation { background: #eef2ff; }
.pill-treatment { background: #dcfce7; }
.pill-pharmacy { background: #fee2e2; }
.pill-billing { background: #fef9c3; }
.pill-other { background: #e5e7eb; }

/* Calendar event block styling */
.event-block {
  border-radius: 0.4rem;
  padding: 0.15rem 0.3rem;
  margin-bottom: 0.1rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #ffffff;
  overflow: hidden;
}

.event-line {
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.event-type {
  font-weight: 600;
  color: #1d4ed8;
}

.event-facility {
  color: #059669;
}

.event-person {
  color: #b45309;
}

.event-doi {
  font-size: 0.75rem;
  font-weight: 600;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
}

/* Map + legend: match visual height with calendar list */
#map {
  width: 100%;
  height: 320px;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  margin-bottom: 0.5rem;
}

.map-legend {
  font-size: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.legend-title {
  font-weight: 600;
  margin-right: 0.5rem;
}

.legend-item {
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.1);
}

.legend-home { background: #fef3c7; }
.legend-consultation { background: #eef2ff; }
.legend-treatment { background: #dcfce7; }
.legend-pharmacy { background: #fee2e2; }
.legend-billing { background: #fef9c3; }
.legend-other { background: #e5e7eb; }

/* Fullscreen variants for map/table so content fills viewport but keeps legend/header */
.map-panel.fullscreen #map {
  height: calc(100vh - 100px); /* leave space for header + legend */
}

.map-panel.fullscreen .map-legend {
  margin-top: 0.5rem;
}

.table-panel.fullscreen #calendar-table-container {
  max-height: calc(100vh - 80px); /* leave space for header */
}

/* Mobile layout */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "upload"
      "summary"
      "calendar"
      "table"
      "map"
      "downloads";
  }
}
