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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f5f5f0;
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 48px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.01em;
}

.topbar-links {
  display: flex;
  gap: 0.25rem;
}

.topbar-links a {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  color: #aaa;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.topbar-links a:hover, .topbar-links a.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.topbar-crop-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.topbar-crop-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.topbar-crop-select {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.topbar-crop-select:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
}

.topbar-crop-select:focus {
  outline: none;
  border-color: rgba(255,255,255,0.35);
}

.topbar-crop-select option {
  background: #1a1a2e;
  color: #fff;
}

.topbar-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.12);
  margin: 0 0.25rem;
}

/* Main content */
.main {
  flex: 1;
  padding: 2rem;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: #1a1a1a;
}

/* Sticky top bar wraps page-header + filter bar */
.sticky-top-bar {
  position: sticky;
  top: 48px;
  z-index: 30;
  background: #f5f5f0;
  padding-bottom: 0.75rem;
  box-shadow: none;
}

.page-header {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  margin-bottom: 0.875rem;
}

.page-header h1 {
  margin-bottom: 0;
  white-space: nowrap;
}

.page-header-right {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
  margin-left: auto;
  padding-left: 1rem;
  white-space: nowrap;
}

.page-header-right .record-count {
  margin-bottom: 0;
}

.page-header-right .select-action-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #1a1a1a;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  color: #444;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  margin-bottom: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

input[type="text"], select {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  background: #fafafa;
  color: #1a1a1a;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus, select:focus {
  border-color: #9b7ff5;
  background: #fff;
}

input[type="text"] { width: 220px; }

button, input[type="submit"] {
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 1rem;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover, input[type="submit"]:hover { background: #2d2d4e; }

.btn-clear {
  background: none;
  color: #888;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  text-decoration: none;
  transition: background 0.15s;
}

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

label { font-size: 13px; color: #555; display: flex; align-items: center; gap: 0.35rem; }

/* Record count */
.record-count {
  font-size: 13px;
  color: #888;
  margin-bottom: 0.75rem;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e5e5e5;
  margin-top: 0.875rem;
}

.data-table thead {
  z-index: 20;
}

.data-table thead th:first-child { border-top-left-radius: 9px; }
.data-table thead th:last-child  { border-top-right-radius: 9px; }

.data-table th {
  position: sticky;
  top: 163px;
  z-index: 20;
  background: #f5f5f0;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  padding: 0.35rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid #e5e5e5;
}

.data-table td {
  padding: 0.6rem 0.875rem;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
  vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table td.col-wrap { max-width: 220px; word-wrap: break-word; white-space: normal; }

.data-table tbody tr:hover { background: #faf9f7; }

.data-table a {
  color: #7c5cbf;
  text-decoration: none;
  font-weight: 500;
}

.data-table a:hover { text-decoration: underline; }

/* Detail page */
/* Panel system */
.detail-panels {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.detail-panels-left { flex: 0 0 520px; min-width: 0; }
.detail-panels-right { flex: 1; min-width: 220px; }

.detail-panel {
  border: 1px solid #e5e5e0;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.detail-panel > summary {
  list-style: none;
  padding: 0.5rem 0.875rem;
  background: #f5f5f0;
  border-radius: 6px 6px 0 0;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.detail-panel > summary::-webkit-details-marker { display: none; }
.detail-panel > summary::after { content: "▾"; font-size: 14px; }
.detail-panel[open] > summary::after { content: "▴"; }
.detail-panel > summary:hover { background: #eeede8; }

.detail-panel-body { padding: 0.75rem 0.875rem; }

.detail-dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 0.25rem 0.5rem;
  margin: 0;
  font-size: 13px;
}

.detail-dl dt { color: #888; font-weight: normal; }
.detail-dl dd { margin: 0; word-wrap: break-word; }

.detail-panel-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.75rem 0 0.4rem;
}

.detail-panel-subtitle:first-child { margin-top: 0; }

.detail-list { margin: 0 0 0.5rem; padding-left: 1.2rem; font-size: 13px; }
.detail-list li { margin-bottom: 0.35rem; }
.detail-list-meta { margin-left: 1rem; }
.detail-list-markers { margin-left: 0.75rem; }

.detail-meta-footer { font-size: 12px; color: #aaa; font-style: italic; margin-top: 0.5rem; }

.mono { font-family: monospace; }

/* Legacy detail layout (kept for reference) */
.detail-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.detail-table {
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e5e5e5;
}

.detail-table th {
  background: #f5f5f0;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  padding: 0.5rem 0.875rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid #f0f0f0;
}

.detail-table td {
  padding: 0.5rem 0.875rem;
  color: #333;
  border-bottom: 1px solid #f0f0f0;
}

.detail-table tr:last-child th,
.detail-table tr:last-child td { border-bottom: none; }

/* Side boxes */
.side-box {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  min-width: 220px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.side-box h2 { margin-bottom: 0.75rem; }

.side-box p { margin: 0.4rem 0; font-size: 13px; }

.side-box a {
  color: #7c5cbf;
  text-decoration: none;
  font-weight: 500;
}

.side-box a:hover { text-decoration: underline; }

.side-box ul { padding-left: 1.1rem; margin: 0.25rem 0; }

.side-box li { margin: 0.3rem 0; font-size: 13px; }

.none-text { color: #bbb; font-size: 13px; font-style: italic; }

/* Flash messages */
.flash-notice { background: #e6f4ea; color: #276221; border: 1px solid #b7dfb9; border-radius: 6px; padding: 0.5rem 0.875rem; margin-bottom: 1rem; font-size: 13px; }
.flash-alert  { background: #fdecea; color: #a61c00; border: 1px solid #f5c6c2; border-radius: 6px; padding: 0.5rem 0.875rem; margin-bottom: 1rem; font-size: 13px; }

/* Inline editing table */
.markers-table .inline-input {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  font-size: 13px;
  width: 100%;
  background: #fafafa;
  color: #1a1a1a;
  transition: border-color 0.15s, background 0.15s;
}

.markers-table .inline-input:focus {
  outline: none;
  border-color: #9b7ff5;
  background: #fff;
}

.markers-table .inline-input--short  { width: 80px; }
.markers-table .inline-input--tiny   { width: 52px; }
.markers-table .inline-input--wide   { width: 190px; }

.markers-table .row-inactive td { opacity: 0.45; }
.markers-table .row-new td { background: #f9f7ff; }

.btn-save-inline {
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 0.3rem 0.7rem;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-save-inline:hover { background: #2d2d4e; }
.btn-save-inline.btn-add { background: #3a7c3a; }
.btn-save-inline.btn-add:hover { background: #2d5e2d; }

.hidden-form { display: none; }

/* Back link */
.detail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.detail-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-counter {
  font-size: 12px;
  color: #888;
  min-width: 3rem;
  text-align: center;
}

.nav-btn {
  display: inline-block;
  color: #7c5cbf;
  text-decoration: none;
  font-size: 13px;
  padding: 0.2rem 0.6rem;
  border: 1px solid #c4b0e8;
  border-radius: 4px;
}

.nav-btn:hover { background: #f3eeff; text-decoration: none; }

.nav-btn--disabled {
  color: #bbb;
  border-color: #e0e0e0;
  cursor: default;
}

.back-link {
  display: inline-block;
  color: #7c5cbf;
  text-decoration: none;
  font-size: 13px;
}

.back-link:hover { text-decoration: underline; }

/* Progeny section */
.progeny-section { margin-top: 2rem; }

.progeny-section ul { padding-left: 1.1rem; }

.progeny-section li { margin: 0.35rem 0; font-size: 13px; }

.progeny-section a { color: #7c5cbf; text-decoration: none; font-weight: 500; }

.progeny-section a:hover { text-decoration: underline; }

/* Marker score badges */
.score-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.score-good    { background: #c6efce; color: #276221; }
.score-het     { background: #ffeb9c; color: #7d5a00; }
.score-bad     { background: #e0e0e0; color: #666666; }
.score-unknown { background: #f5f5f5; color: #aaaaaa; font-style: italic; }

/* Basket toolbar */
.basket-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.basket-toolbar-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.basket-load-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-left: 1px solid #e5e5e5;
  padding-left: 1rem;
}

.basket-file-input {
  font-size: 12px;
  color: #555;
}

.basket-radio {
  font-size: 13px;
  color: #555;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}

.btn-load-csv {
  background: #5a7abf;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-load-csv:hover { background: #3d5a99; }

/* Basket column: hidden until select mode is active */
.basket-col { display: none; }
.select-mode .basket-col { display: table-cell; }

/* Select action bar (sits above the table) */
.select-action-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.btn-select-mode {
  background: none;
  color: #666;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-select-mode:hover { background: #f0f0f0; color: #333; }

.btn-select-mode.btn-select-active {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}

.btn-add-basket {
  background: #3a7c3a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.85rem;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add-basket:hover { background: #2d5e2d; }

/* Basket */
.topbar-basket-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.9rem;
  color: #aaa;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.topbar-basket-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.basket-count-badge {
  display: inline-block;
  background: #7c5cbf;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover { background: #a93226; }

/* Right-aligned actions inside the filter bar (e.g. view toggles) */
.filter-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* Scrollable table container (Option A sticky header) */
.table-scroll-container {
  overflow: auto;
  height: calc(100vh - 260px);
  min-height: 300px;
  border-radius: 10px;
  border: 1px solid #e5e5e5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-top: 0.875rem;
}

.table-scroll-container .data-table {
  margin-top: 0;
  box-shadow: none;
  border: none;
  border-radius: 0;
}

.table-scroll-container .data-table th {
  top: 0;
}

/* Trial status icons */
.status-icon {
  font-size: 16px;
  font-weight: 700;
}
.status-icon--active   { color: #276221; }
.status-icon--finished { color: #a61c00; }

/* Hover-reveal row edit button */
.row-edit-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 12px;
  cursor: pointer;
  color: #888;
  opacity: 0;
  transition: opacity 0.15s;
}

.data-table tr:hover .row-edit-btn {
  opacity: 1;
}

.row-actions-cell {
  white-space: nowrap;
  text-align: right;
}

/* View toggle */
.view-toggle, .view-toggle-active {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 13px;
  margin-right: 4px;
}
.view-toggle { color: #7c5cbf; text-decoration: none; border: 1px solid #c4b0e8; }
.view-toggle:hover { background: #f0eafa; }
.view-toggle-active { background: #7c5cbf; color: #fff; font-weight: 600; }

/* Field list thumbnails */
.field-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; display: block; border: 1px solid #e5e5e5; }
.field-thumb:hover { opacity: 0.85; }

/* Trial attachments */
.trial-attachments { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.875rem; }
.trial-attachment-item { display: inline-flex; align-items: center; gap: 0.25rem; background: #f0f4ff; border: 1px solid #c7d4f5; border-radius: 5px; padding: 0.2rem 0.5rem; font-size: 13px; }
.trial-attachment-link { color: #3b5bdb; text-decoration: none; font-weight: 500; }
.trial-attachment-link:hover { text-decoration: underline; }
.trial-attachment-remove { background: none; border: none; color: #aaa; cursor: pointer; font-size: 11px; padding: 0 0.1rem; line-height: 1; }
.trial-attachment-remove:hover { color: #dc2626; }
.trial-attachment-add { font-size: 13px; }
.trial-attachment-add summary { color: #3b5bdb; cursor: pointer; font-weight: 500; list-style: none; }
.trial-attachment-add summary::-webkit-details-marker { display: none; }
.trial-attachment-form { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.4rem; flex-wrap: wrap; }
.attachment-link { font-size: 16px; text-decoration: none; }
.attachment-link:hover { opacity: 0.7; }

/* Admin table (no sticky header — used on pages without a secondary filter bar) */
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid #e5e5e5; margin-top: 0.875rem; }
.admin-table th { background: #f5f5f0; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: #666; padding: 0.35rem 0.875rem; text-align: left; border-bottom: 1px solid #e5e5e5; }
.admin-table td { padding: 0.6rem 0.875rem; border-bottom: 1px solid #f0f0f0; color: #333; vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: #faf9f7; }
.admin-table a { color: #7c5cbf; text-decoration: none; font-weight: 500; }
.admin-table a:hover { text-decoration: underline; }

/* Admin users */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-title  { font-size: 1.1rem; font-weight: 600; color: #1a1a2e; margin: 0; }
.btn-action  { background: #1a1a2e; color: #fff; border: none; border-radius: 6px; padding: 0.4rem 0.9rem; font-size: 13px; font-weight: 500; text-decoration: none; cursor: pointer; transition: background 0.15s; }
.btn-action:hover { background: #2d2d4e; color: #fff; }
.col-actions { display: flex; gap: 0.75rem; align-items: center; white-space: nowrap; }
.btn-link { background: none; border: none; padding: 0; font-size: 13px; cursor: pointer; color: #6b7280; text-decoration: underline; }
.btn-link--danger { color: #dc2626; }
.btn-link--danger:hover { color: #991b1b; }
.role-badge { display: inline-block; border-radius: 4px; padding: 0.15rem 0.5rem; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.role-badge--admin  { background: #fef2f2; color: #991b1b; }
.role-badge--editor { background: #fffbeb; color: #92400e; }
.role-badge--viewer { background: #f0fdf4; color: #166534; }
.user-form { max-width: 420px; display: flex; flex-direction: column; gap: 1rem; }
.form-field { display: flex; flex-direction: column; gap: 0.3rem; }
.form-field label { font-size: 13px; font-weight: 500; color: #374151; }
.form-field input, .form-field select { border: 1px solid #d1d5db; border-radius: 6px; padding: 0.45rem 0.65rem; font-size: 14px; width: 100%; }
.form-field input:focus, .form-field select:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,0.15); }
.form-actions { display: flex; gap: 0.75rem; align-items: center; padding-top: 0.5rem; }

/* Auth — topbar user area */
.topbar-user { display: flex; align-items: center; gap: 0.5rem; }
.topbar-user-name { font-size: 13px; color: #aaa; }
.topbar-logout { background: none; border: none; color: #aaa; font-size: 16px; cursor: pointer; padding: 0 0.25rem; line-height: 1; }
.topbar-logout:hover { color: #fff; }

/* Auth — login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #eef2f6; }
.login-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 1rem; padding: 2.5rem 3rem; box-shadow: 0 8px 20px rgba(15,23,42,0.06); text-align: center; max-width: 360px; width: 100%; }
.login-title { font-size: 1.25rem; font-weight: 700; color: #111827; margin: 0 0 0.25rem; }
.login-sub { font-size: 0.875rem; color: #6b7280; margin: 0 0 2rem; }
.login-note { margin-top: 1.5rem; font-size: 0.78rem; color: #9ca3af; }
.btn-google { display: inline-flex; align-items: center; gap: 0.75rem; background: #fff; border: 1px solid #dadce0; border-radius: 0.5rem; padding: 0.7rem 1.25rem; font-size: 0.95rem; font-weight: 500; color: #3c4043; cursor: pointer; width: 100%; justify-content: center; transition: background 0.15s; }
.btn-google:hover { background: #f8f9fa; }
