/*
 * Precision — components.
 *
 * Requires tokens.css, and expects buttons.css alongside it: the BUTTONS
 * section that used to sit in this file is gone, replaced by the two-tier
 * system in that one.
 *
 * Shared by the Novasyne CTMS and both workbenches. What is *not* here, on
 * purpose: each platform's own navigation. The merged build had a single icon
 * rail for all three, and that rail was the one part of the design that only
 * made sense while they were one application.
 */

/* ========================================
   BASE STYLES
   ======================================== */
* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--background);
  min-height: 100vh;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


/* ========================================
   TYPOGRAPHY
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
  
}

.text-primary { color: var(--primary) !important; }
.text-accent { color: var(--accent) !important; }
.text-muted { color: var(--text-muted) !important; }


/* ========================================
   MAIN CONTAINER
   ======================================== */
.main-container {
  max-width: 1400px;
  padding: 0 1.5rem;
  margin: 0 auto;
}

.container-fluid {
  max-width: 1400px;

}


/* ========================================
   CARDS
   ======================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  font-weight: 600;
}

.card-body {
  padding: 1.5rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
}


/* ========================================
   FORMS
   ======================================== */
.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.375rem;
}

.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: var(--transition-fast);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.1);
  outline: none;
}

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

.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

.badge {
  line-height: 2;
  min-width:80px;
}


/* ========================================
   ALERTS
   ======================================== */
.alert {
  border: none;
  border-radius: var(--radius);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

.alert-success {
  background: var(--success-soft);
  color: var(--success);
}

.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.alert-info {
  background: var(--info-soft);
  color: var(--info);
}


/* ========================================
   TABLES
   ======================================== */
.table {
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  background: var(--surface-alt);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 0.875rem 1rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.table tbody td {
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.table tbody tr {
  transition: var(--transition-fast);
}

.table-hover tbody tr:hover {
  background: var(--surface-hover) !important;
}

.table-striped tbody tr:nth-of-type(odd) {
  background: var(--surface-alt);
}


/* ========================================
   MODALS
   ======================================== */
.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.modal-header {
  background: var(--primary);
  color: var(--text-inverse);
  padding: 1rem 1.25rem;
  border: none;
}

.modal-header .modal-title {
  font-weight: 700;
  font-size: 1rem;
}

.modal-header .btn-close {
  filter: brightness(0) invert(1);
  opacity: 0.8;
}

.modal-header .btn-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
  gap: 0.5rem;
}


/* ========================================
   PAGINATION
   ======================================== */
.pagination .page-link {
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  transition: var(--transition-fast);
}

.pagination .page-link:hover {
  background: var(--surface-alt);
  color: var(--text-primary);
  border-color: var(--border);
}

.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}


/* ========================================
   UTILITY CLASSES
   ======================================== */
.shadow-elevated {
  box-shadow: var(--shadow-lg);
}

.bg-surface {
  background: var(--surface);
}

.bg-surface-alt {
  background: var(--surface-alt);
}

.border-subtle {
  border: 1px solid var(--border);
}

.rounded-lg {
  border-radius: var(--radius-lg);
}


/* ========================================
   SCROLLBAR
   ======================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface-alt);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}


/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 992px) {
  .main-container {
    padding: 0 1rem;
  }
}

@media (max-width: 768px) {
  body {
    font-size: 13px;
  }
  
  .btn {
    padding: 0.5rem 0.875rem;
  }
}


/* ========================================
   LEGACY BOOTSTRAP OVERRIDES
   ======================================== */
.table-responsive {
  overflow-x: auto;
}


/* ========================================
   STATE CHIPS

   A recordings table is scanned for adverse events, not read. Type and
   severity were plain text, which means finding one is a reading task. As a
   chip it is a glance.

   Semantic colour, never the brand: --primary means "NeuroStudio", --danger
   means "this needs attention", and letting the two blur would make the
   product's own colour look like an alert.
   ======================================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* The dot carries the same information as the fill, so the chip still reads
   when the two colours are indistinguishable to the reader. */
.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.chip-biomarker { color: var(--info); background: var(--info-soft); }
.chip-scale { color: var(--success); background: var(--success-soft); }
.chip-eeg,
.chip-wearable { color: var(--primary); background: var(--primary-soft); }
.chip-imaging { color: var(--accent-dark); background: var(--surface-alt); }
.chip-symptom { color: var(--warning); background: var(--warning-soft); }
.chip-adverse { color: var(--danger); background: var(--danger-soft); }
.chip-neutral { color: var(--text-secondary); background: var(--surface-alt); }


/* ========================================
   TABULAR FIGURES

   Anything that appears in a column of numbers is set in the mono: values line
   up on the decimal, and a subject code cannot be misread because the zero and
   the letter O are different shapes.
   ======================================== */
.mono,
.subject-code,
.metric-value,
.timestamp {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.subject-code {
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.01em;
}

.metric-value {
  font-weight: 500;
}

.timestamp {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

table td .mono,
table td .metric-value {
  font-size: 0.8125rem;
}


/* ========================================
   DATATABLES

   The tables are DataTables 1.x, whose own stylesheet comes off a CDN and is
   written with high specificity. Six templates each carried a private copy of
   these overrides, all still painting #20519c — Novasyne's blue — three phases
   after the product stopped using it, and they had already drifted: the
   recordings page picked a green current-page button while every other table
   had a blue one.

   Declared once here. The !important flags are the vendor sheet's fault, not
   ours: DataTables ships `.paginate_button.current { background: ... }` as a
   gradient, and a gradient cannot be beaten by specificity alone.
   ======================================== */
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.875rem;
  width: auto;
  display: inline-block;
}

.dataTables_wrapper .dataTables_length select {
  padding-right: 2.25rem;
}

.dataTables_wrapper .dataTables_filter input {
  margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_length select:focus,
.dataTables_wrapper .dataTables_filter input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-secondary) !important;
  font-size: 0.8125rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--surface-hover) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: var(--text-inverse) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  background: transparent !important;
  border-color: transparent !important;
  color: var(--text-muted) !important;
}

/* Keyboard focus has to stay visible on a control the mouse never lands on. */
.dataTables_wrapper .dataTables_paginate .paginate_button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dt-buttons {
  margin-bottom: 0.5rem;
}

/* A table wider than the viewport used to scroll the body, which took the
   navigation with it. It scrolls inside its own wrapper now. None of the three
   pages with a DataTable puts a dropdown in a row, which is the case where a
   scroll container would clip rather than help. */
.dataTables_wrapper {
  overflow-x: auto;
}

/* Column headers carry the sort control, so they read as interactive. */
table.dataTable thead th {
  background: var(--surface-alt);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong);
}

table.dataTable tbody tr:hover > * {
  background: var(--surface-hover);
}


/* ========================================
   FOCUS AND MOTION

   Bootstrap's focus ring is a box-shadow in its own blue, which the bridge
   above retints but which disappears entirely against a dark ground — the
   navigation rail, a primary button. One visible ring, defined once, on
   everything that takes focus.

   :focus-visible rather than :focus, so the ring appears for a keyboard user
   and not around a button someone just clicked.
   ======================================== */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* On the rail and on a filled button the accent has nothing to contrast with,
   so the ring switches to the light side. */
.rail-item:focus-visible,
.btn-primary:focus-visible,
.navbar-dark .nav-link:focus-visible {
  outline-color: var(--surface);
  outline-offset: -3px;
}

/* Skip link: the rail and navbar are ~20 tab stops before the content on every
   page. Off-screen until focused, then it lands where it can be read. */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 2000;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: var(--text-inverse);
  border-radius: var(--radius);
  text-decoration: none;
  transition: top var(--transition);
}

.skip-link:focus {
  top: 0.5rem;
  color: var(--text-inverse);
}

/* An animation is a comfort for most people and a symptom trigger for some.
   This says nothing about how much motion the design uses — it says the user
   decides. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ========================================
   RESPONSIVE — NARROW SCREENS

   The rail already becomes a bottom strip below 768px. What was left was
   content that did not fit: a wide table scrolled the body, and the workbench
   tool panels held a fixed 240–300px whatever the viewport was.
   ======================================== */
@media (max-width: 768px) {
  /* Nothing should make the page itself scroll sideways. Wide content gets a
     container of its own above; this is the backstop that makes a miss
     visible as a clipped table rather than a shifted layout. */
  body {
    overflow-x: hidden;
  }

  .table-responsive,
  .dataTables_wrapper {
    -webkit-overflow-scrolling: touch;
  }

  /* DataTables' controls sit in a two-column row that collapses badly. */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    float: none;
    text-align: left;
    margin-bottom: 0.5rem;
  }

  .dataTables_wrapper .dataTables_filter input {
    margin-left: 0;
    width: 100%;
  }

  /* A modal at 100% width with the default margin has no room left. */
  .modal-dialog {
    margin: 0.5rem;
  }
}
