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

:root {
  --black:      #0a0a0a;
  --white:      #ffffff;
  --grey-50:    #f7f7f7;
  --grey-100:   #ebebeb;
  --grey-200:   #d8d8d8;
  --grey-300:   #b8b8b8;
  --grey-400:   #8c8c8c;
  --grey-500:   #6a6a6a;
  --grey-600:   #4a4a4a;
  --grey-700:   #2e2e2e;
  --grey-800:   #1c1c1c;

  --panel-left-width: 38%;
  --radius: 6px;
  --radius-sm: 4px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 150ms ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--black);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.login-panel-left {
  flex: 0 0 var(--panel-left-width);
  background: var(--black);
  display: flex;
  flex-direction: column;
  padding: 56px 52px;
  position: relative;
  overflow: hidden;
}

/* Subtle grid texture on the dark panel */
.login-panel-left::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.login-panel-left::after {
  content: '';
  position: absolute;
  bottom: -180px;
  right: -180px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.04) 0%, transparent 70%);
  pointer-events: none;
}

.login-logo {
  position: relative;
  z-index: 1;
}

.login-logo img {
  height: 36px;
  filter: invert(1);
  opacity: 0.95;
}

.login-panel-left .tagline {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding-bottom: 8px;
}

.login-panel-left .tagline-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-bottom: 16px;
}

.login-panel-left .tagline-heading {
  font-size: clamp(22px, 2.4vw, 30px);
  font-weight: 700;
  line-height: 1.25;
  color: var(--white);
  letter-spacing: -0.02em;
}

.login-panel-left .tagline-sub {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255,255,255,0.45);
  max-width: 280px;
}

.login-panel-left .tagline-features {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tagline-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  font-weight: 400;
}

.tagline-feature-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  flex-shrink: 0;
}

/* Right panel */
.login-panel-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--white);
}

.login-form-wrap {
  width: 100%;
  max-width: 360px;
}

.login-form-wrap h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--black);
  margin-bottom: 6px;
}

.login-form-wrap .login-subtitle {
  font-size: 13px;
  color: var(--grey-500);
  margin-bottom: 36px;
  line-height: 1.5;
}

.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff4f4;
  border: 1px solid #f5c5c5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #c0392b;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--grey-600);
  margin-bottom: 7px;
}

.form-input {
  width: 100%;
  padding: 11px 14px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--black);
  background: var(--white);
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

.form-input:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.form-input::placeholder { color: var(--grey-300); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), opacity var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--black);
  color: var(--white);
}
.btn-primary:hover { background: var(--grey-700); }

.btn-secondary {
  background: var(--grey-50);
  color: var(--black);
  border: 1.5px solid var(--grey-200);
}
.btn-secondary:hover { background: var(--grey-100); }

.btn-ghost {
  background: transparent;
  color: var(--grey-600);
  border: 1.5px solid transparent;
  padding: 7px 12px;
  font-size: 13px;
}
.btn-ghost:hover { background: var(--grey-50); color: var(--black); }

.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-icon {
  padding: 6px;
  background: transparent;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-sm);
  color: var(--grey-500);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.btn-icon:hover { border-color: var(--grey-400); color: var(--black); background: var(--grey-50); }

.btn-full { width: 100%; }

/* ── App Shell ───────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--white);
}

.topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 32px;
  border-bottom: 1px solid var(--grey-100);
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 24px;
}

.topbar-logo img {
  height: 24px;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--grey-200);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--grey-600);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-user {
  font-size: 12px;
  font-weight: 500;
  color: var(--grey-500);
  padding: 0 4px;
}

.page-content {
  flex: 1;
  padding: 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── Search Bar ──────────────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.search-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 160px;
  max-width: 220px;
}

.search-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--grey-400);
}

.search-hint {
  font-size: 11px;
  color: var(--grey-300);
}

.search-input {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--black);
  background: var(--white);
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.search-input::placeholder { color: var(--grey-300); }

.search-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-bottom: 1px;
}

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--grey-100);
  border-radius: var(--radius);
  overflow: hidden;
}

.pacs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pacs-table thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--grey-400);
  background: var(--grey-50);
  border-bottom: 1px solid var(--grey-100);
  white-space: nowrap;
  user-select: none;
}

.pacs-table thead th:first-child { padding-left: 20px; }
.pacs-table thead th:last-child  { padding-right: 20px; }

.pacs-table tbody tr {
  border-bottom: 1px solid var(--grey-100);
  transition: background var(--transition);
}
.pacs-table tbody tr:last-child { border-bottom: none; }
.pacs-table tbody tr:hover { background: var(--grey-50); }

.pacs-table td {
  padding: 14px 16px;
  color: var(--grey-700);
  vertical-align: middle;
  line-height: 1.4;
}
.pacs-table td:first-child { padding-left: 20px; }
.pacs-table td:last-child  { padding-right: 20px; }

.td-patient-id { font-weight: 600; color: var(--black); font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
.td-name       { font-weight: 500; color: var(--black); }
.td-accession  { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; color: var(--grey-600); }
.td-modality   {}
.td-description { color: var(--grey-600); max-width: 280px; }
.td-date       { font-size: 12px; color: var(--grey-400); white-space: nowrap; }
.td-actions    { white-space: nowrap; }

/* Modality pill */
.modality-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--grey-100);
  color: var(--grey-700);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  gap: 3px;
}

/* Row actions */
.row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* Expand chevron */
.expand-btn {
  background: none;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  cursor: pointer;
  color: var(--grey-500);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.expand-btn:hover { color: var(--black); border-color: var(--grey-400); background: var(--grey-50); }
.expand-btn .chevron {
  display: block;
  flex-shrink: 0;
  transition: transform 220ms ease;
}
.expand-btn.open .chevron { transform: rotate(180deg); }
.expand-btn .spinner-inline {
  width: 13px;
  height: 13px;
  border: 2px solid var(--grey-200);
  border-top-color: var(--grey-600);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
  flex-shrink: 0;
}
.expand-btn.loading .chevron { display: none; }
.expand-btn.loading .spinner-inline { display: inline-block; }

/* Child rows (expanded studies) */
.child-row td { background: var(--grey-50); padding-top: 10px; padding-bottom: 10px; }
.child-row td:first-child { padding-left: 40px; }
.child-row:last-child td { border-bottom: none; }

/* Loading row */
.loading-row td {
  background: var(--grey-50);
  color: var(--grey-400);
  font-size: 12px;
  padding: 12px 20px;
}

/* ── Status / Alerts ─────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 20px;
}
.alert-error { background: #fff4f4; border: 1px solid #f5c5c5; color: #b91c1c; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: var(--grey-50); border: 1px solid var(--grey-200); color: var(--grey-600); }

.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--grey-400);
}
.empty-state-icon { font-size: 28px; margin-bottom: 12px; opacity: 0.5; }
.empty-state-text { font-size: 14px; font-weight: 500; color: var(--grey-600); margin-bottom: 6px; }
.empty-state-sub  { font-size: 13px; color: var(--grey-400); }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--grey-100);
  font-size: 12px;
  color: var(--grey-500);
}
.pagination-info { letter-spacing: 0.01em; }
.pagination-controls { display: flex; gap: 6px; }

/* ── Preview Modal ───────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(3px);
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--white);
  border-radius: 10px;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--grey-100);
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--black); letter-spacing: -0.01em; }
.modal-subtitle { font-size: 12px; color: var(--grey-400); margin-top: 3px; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--grey-400);
  line-height: 1;
  padding: 0 0 0 12px;
  flex-shrink: 0;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--black); }

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

/* PACS viewport */
.pacs-viewport {
  background: #0a0a0a;
  border-radius: var(--radius);
  height: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
}

.pacs-viewport img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.pacs-viewport-msg {
  color: rgba(255,255,255,0.4);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}

.frame-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 0 4px;
}
.frame-nav .btn { min-width: 32px; padding: 4px 8px; font-size: 13px; flex-shrink: 0; }
#frame-play { min-width: 38px; }
#frame-slider { flex: 1; min-width: 80px; cursor: pointer; accent-color: #ffffff; }
.frame-counter { font-size: 12px; color: var(--grey-400); min-width: 62px; text-align: right; white-space: nowrap; flex-shrink: 0; }

/* Preload progress beneath the overlay spinner */
#viewport-preload-status { font-size: 11px; opacity: 0.55; margin-top: 6px; }

/* Meta row */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--grey-100);
}
.meta-item { display: flex; flex-direction: column; gap: 3px; }
.meta-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--grey-400); }
.meta-value { font-size: 13px; color: var(--grey-700); font-weight: 500; }

/* ── Overlay Spinner ─────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--grey-100);
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.overlay-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--grey-600);
}

/* ── Misc ─────────────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.datastore-badge {
  font-size: 11px;
  color: var(--grey-400);
  background: var(--grey-50);
  border: 1px solid var(--grey-100);
  border-radius: 100px;
  padding: 3px 10px;
  font-family: monospace;
  letter-spacing: 0.02em;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--black);
}
.page-header-sub {
  font-size: 13px;
  color: var(--grey-400);
  margin-top: 3px;
}

/* Responsive */
@media (max-width: 800px) {
  .login-panel-left { display: none; }
  .page-content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .search-bar { gap: 8px; }
  .search-field { min-width: 120px; }
}
