/* ==========================================================================
   MEDLINK HEALTHCARE THEME FOR OHIF VIEWER
   Style inspired by https://medlink.healthcare/
   Colors:
     Brand Cyan: #38b6ff (RGB: 56, 182, 255 | HSL: 202 100% 61%)
     Dark Shade: #0f1f20 (RGB: 15, 31, 32 | HSL: 184 36% 9%)
     Panel Dark: #142627 (RGB: 20, 38, 39)
     Panel Hover: #1b3334 (RGB: 27, 51, 52)
     Border Dark: #223f40 (RGB: 34, 63, 64)
   ========================================================================== */

:root {
  /* Tailwind / Shadcn CSS Variables */
  --highlight: 202 100% 61% !important;
  --primary: 202 100% 61% !important;
  --primary-foreground: 0 0% 100% !important;
  --secondary: 184 30% 18% !important;
  --secondary-foreground: 0 0% 98% !important;
  --background: 184 36% 9% !important;
  --foreground: 0 0% 98% !important;
  --card: 184 30% 11% !important;
  --card-foreground: 0 0% 98% !important;
  --popover: 184 30% 11% !important;
  --popover-foreground: 0 0% 98% !important;
  --muted: 184 25% 15% !important;
  --muted-foreground: 185 20% 70% !important;
  --accent: 184 30% 18% !important;
  --accent-foreground: 0 0% 98% !important;
  --border: 184 22% 20% !important;
  --input: 184 25% 18% !important;
  --ring: 202 100% 61% !important;
  --radius: 0.375rem !important;
}

/* Base Body & App Container */
body, #root {
  background-color: #0c1819 !important;
  color: #edf0f5 !important;
  font-family: 'Inter', 'Open Sans', system-ui, -apple-system, sans-serif !important;
}

/* Header & Top Bar */
header,
.header,
.bg-primary-dark {
  background-color: #0f1f20 !important;
  border-bottom: 1px solid #1a3334 !important;
}

/* Secondary & Sidebar Panels */
.bg-secondary-dark,
aside,
.study-browser {
  background-color: #122223 !important;
  border-color: #1a3334 !important;
}

.bg-secondary-main {
  background-color: #162a2b !important;
}

.bg-secondary-light {
  background-color: #1c3536 !important;
}

/* Active & Primary Backgrounds */
.bg-primary-main,
.bg-primary-active,
.bg-primary-light {
  background-color: #38b6ff !important;
}

/* Text on Cyan Backgrounds must be dark & high contrast (Fix "Основний" / Primary button) */
button.bg-primary-main,
button[class*="bg-primary-main"],
button.bg-primary-active,
button.bg-primary-light,
[data-cy="studyBrowser-panel"] button.bg-primary-main,
[data-cy="studyBrowser-panel"] button[class*="bg-primary-main"],
.bg-primary-main span,
.bg-primary-main p {
  color: #071718 !important; /* Deep dark teal/black - ultra crisp on #38b6ff */
  font-weight: 700 !important;
}

/* Inactive StudyBrowser tabs ("Останній", "Усі") */
[data-cy="studyBrowser-panel"] button.bg-black,
[data-cy="studyBrowser-panel"] button[class*="bg-black"] {
  background-color: #122223 !important;
  color: #ffffff !important; /* Pure white on dark background */
  border: 1px solid #1c3536 !important;
}

[data-cy="studyBrowser-panel"] button.bg-black:hover {
  background-color: #182e2f !important;
  color: #38b6ff !important;
}

/* Active Text & Links on Dark Backgrounds */
:not(button):not([class*="bg-primary"]).text-primary-light,
:not(button):not([class*="bg-primary"]).text-primary-active,
:not(button):not([class*="bg-primary"]).text-primary {
  color: #38b6ff !important;
}

/* Borders */
.border-primary-light,
.border-primary-active,
.border-primary-main {
  border-color: #38b6ff !important;
}

.border-secondary-dark,
.border-secondary-main,
.border-secondary-light {
  border-color: #1a3334 !important;
}

/* Active Viewport Frame */
.border-primary-active,
.viewport-section.active,
[data-cy="viewport-element"].active,
.border-2.border-primary-light {
  border-color: #38b6ff !important;
  box-shadow: 0 0 10px rgba(56, 182, 255, 0.35) !important;
}

/* Toolbar Buttons */
button.text-primary-active,
.toolbar-button.active,
[data-cy*="tool"].active {
  background-color: #1a353b !important;
  color: #38b6ff !important;
}

button:hover:not(:disabled) {
  border-color: #38b6ff !important;
}

/* Scrollbars */
.ohif-scrollbar::-webkit-scrollbar-thumb {
  background-color: #1c3536 !important;
  border-radius: 4px !important;
}

.ohif-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: #38b6ff !important;
}

/* Modals & Dropdown Menus */
[role="menu"],
[role="dialog"],
.modal-content {
  background-color: #122223 !important;
  border: 1px solid #223f40 !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important;
}

/* Overlay Text (DICOM tags on viewport corners) */
.ViewportOverlay {
  color: #85d2ff !important;
  font-family: 'Inter', monospace !important;
}

/* Loading Spinner Accent */
.loading-indicator,
.spinner {
  border-top-color: #38b6ff !important;
}

/* ==========================================================================
   MOBILE & RESPONSIVE ADAPTATIONS (< 1024px)
   Prevents toolbar buttons from colliding/overlapping on mobile phones.
   ========================================================================== */

@media (max-width: 1024px) {
  /* 1. Header Container: allow natural height and flex layout */
  .relative.h-\[48px\],
  [class*="h-[48px]"],
  div[class*="relative"][class*="items-center"] {
    height: auto !important;
    min-height: 48px !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    position: relative !important;
    padding: 6px 10px !important;
    gap: 6px 0 !important;
  }

  /* 2. Logo Container (1st child): unpin from absolute */
  .relative.h-\[48px\] > div:nth-child(1),
  [class*="h-[48px]"] > div:nth-child(1),
  div[class*="absolute left-0 top-1/2"] {
    position: static !important;
    transform: none !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
  }

  .relative.h-\[48px\] > div:nth-child(1) img,
  [class*="h-[48px]"] > div:nth-child(1) img {
    height: 24px !important;
    max-height: 24px !important;
    width: auto !important;
  }

  /* 3. Patient Info (2nd child): unpin from absolute, make compact */
  .relative.h-\[48px\] > div:nth-child(2),
  [class*="h-[48px]"] > div:nth-child(2),
  div[class*="left-[250px]"] {
    position: static !important;
    transform: none !important;
    margin-left: 8px !important;
    margin-right: auto !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    max-width: 180px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    display: flex !important;
    align-items: center !important;
  }

  /* 4. Menu & Right Actions (4th child): unpin from absolute */
  .relative.h-\[48px\] > div:nth-child(4),
  [class*="h-[48px]"] > div:nth-child(4),
  div[class*="absolute right-0 top-1/2"] {
    position: static !important;
    transform: none !important;
    margin-left: auto !important;
    flex-shrink: 0 !important;
  }

  /* 5. Toolbar (3rd child): unpin, move to dedicated 2nd line, make scrollable */
  .relative.h-\[48px\] > div:nth-child(3),
  [class*="h-[48px]"] > div:nth-child(3),
  div[class*="absolute left-1/2 top-1/2"] {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    order: 10 !important;
    margin: 4px 0 2px 0 !important;
    padding: 4px 2px !important;
    display: flex !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin !important;
    scrollbar-color: #38b6ff #142627 !important;
    border-top: 1px solid rgba(56, 182, 255, 0.15) !important;
  }

  /* Toolbar buttons container */
  .relative.h-\[48px\] > div:nth-child(3) > div,
  [class*="h-[48px]"] > div:nth-child(3) > div {
    display: inline-flex !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: max-content !important;
  }

  /* Individual tool buttons */
  .relative.h-\[48px\] button,
  [class*="h-[48px]"] button,
  .ExpandableToolbarButton {
    min-width: 38px !important;
    height: 38px !important;
    padding: 4px 6px !important;
    flex-shrink: 0 !important;
    border-radius: 6px !important;
  }
}

@media (max-width: 480px) {
  .relative.h-\[48px\] > div:nth-child(2),
  [class*="h-[48px]"] > div:nth-child(2) {
    max-width: 120px !important;
    font-size: 11px !important;
  }
}

/* Animated glowing pulse for Medlink Loading Emblem */
svg[name="loading-ohif-mark"],
.loading-ohif-mark,
div[class*="space-y-5"] svg {
  animation: medlinkLoadingPulse 1.4s ease-in-out infinite alternate !important;
}

@keyframes medlinkLoadingPulse {
  0% {
    transform: scale(0.92);
    filter: drop-shadow(0 0 3px rgba(56, 182, 255, 0.45));
    opacity: 0.8;
  }
  100% {
    transform: scale(1.1);
    filter: drop-shadow(0 0 14px rgba(56, 182, 255, 0.95));
    opacity: 1;
  }
}
/* ==========================================================================
   MEDLINK AI TOOLBAR BUTTON & MODAL
   Styled strictly according to OHIF toolbar aesthetic (monochrome, muted, 6px radius)
   ========================================================================== */
.medlink-ai-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  background-color: #142627 !important;
  border: 1px solid #203c3d !important;
  color: #c5cbd6 !important;
  border-radius: 6px !important;
  padding: 4px 10px !important;
  height: 34px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  transition: all 0.15s ease-in-out !important;
  margin-right: 8px !important;
  user-select: none !important;
}

.medlink-ai-btn:hover {
  background-color: #1a353b !important;
  border-color: #38b6ff !important;
  color: #ffffff !important;
  box-shadow: 0 0 8px rgba(56, 182, 255, 0.25) !important;
}

.medlink-ai-btn:active {
  background-color: #122223 !important;
  transform: translateY(1px) !important;
}

.medlink-ai-btn svg {
  stroke: currentColor !important;
  flex-shrink: 0 !important;
}

@keyframes aiFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
