/**
 * Glass Card Component
 * 
 * Glassmorphism card component with backdrop-filter blur effect.
 * Includes @supports fallback for browsers without backdrop-filter support.
 * 
 * @see .ai_handoffs/plans/ADR-105_ALKEMY_FULL_UI_REDESIGN_SPECIFICATION.md Section 2.1
 */

@layer alkemy-design {
  /* ==========================================================================
     Base Glass Card
     ========================================================================== */
  
  .glass-card {
    position: relative;
    background: var(--bg-card, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--border-card, rgba(0, 212, 255, 0.2));
    border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-card, 0 4px 24px rgba(0, 0, 0, 0.3));
    transition: 
      background-color var(--transition-fast, 150ms ease),
      border-color var(--transition-fast, 150ms ease),
      box-shadow var(--transition-normal, 250ms ease),
      transform var(--transition-fast, 150ms ease);
  }

  /* Backdrop blur effect when supported */
  @supports (backdrop-filter: blur(10px)) {
    .glass-card {
      backdrop-filter: blur(var(--glass-blur, 10px));
      -webkit-backdrop-filter: blur(var(--glass-blur, 10px));
    }
  }

  /* Fallback for browsers without backdrop-filter */
  @supports not (backdrop-filter: blur(10px)) {
    .glass-card {
      background: var(--bg-secondary, rgba(13, 32, 53, 0.95));
    }
  }

  /* ==========================================================================
     Glass Panel (Reusable Hub-style styling for cards, containers, modals)
     Extracted from Hub Tiles: dark gradient overlay, glowing borders, sharp text shadows.
     Use on sub-pages for consistent premium glassmorphism.
     ========================================================================== */

  .glass-panel {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    border: 1px solid var(--border-card);
    box-shadow: var(--shadow-panel, 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1));
    background: var(--bg-card);
    transition:
      box-shadow 200ms ease,
      border-color 200ms ease;
  }

  .glass-panel:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-panel-hover, 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 24px rgba(0, 212, 255, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.15));
  }

  /* Optional: dark gradient overlay (e.g. over a background image) */
  .glass-panel__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to right,
      rgba(10, 22, 40, 0.95) 0%,
      rgba(10, 22, 40, 0.7) 40%,
      rgba(10, 22, 40, 0) 100%
    );
    z-index: 1;
    pointer-events: none;
  }

  /* Content sits above overlay */
  .glass-panel__content {
    position: relative;
    z-index: 2;
    padding: 20px;
  }

  /* Sharp glowing text for titles (reusable across cards/modals) */
  .glass-panel__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-shadow: var(--shadow-text-glow, none);
    letter-spacing: 0.5px;
    margin: 0 0 0.5em 0;
  }

  /* Body text with same sharp shadow for readability on dark */
  .glass-panel__body,
  .glass-panel__text {
    color: var(--text-secondary);
    text-shadow: var(--shadow-text-subtle, none);
    margin: 0;
  }

  /* Icon/decoration inside panel with same glow as hub icons */
  .glass-panel__icon svg,
  .glass-panel .glass-panel__icon svg {
    filter: var(--shadow-icon-glow, none);
  }

  /* Size variants for different contexts */
  .glass-panel--radius-md {
    border-radius: 16px;
  }

  .glass-panel--radius-lg {
    border-radius: 24px;
  }

  .glass-panel--radius-xl {
    border-radius: 32px;
  }

  /* Modal/dialog variant: no hover glow (use for overlays) */
  .glass-panel--static:hover {
    border-color: var(--border-card);
    box-shadow: var(--shadow-panel, 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1));
  }

  /* ==========================================================================
     Hub Tile - Premium Glassmorphism with Photo Backgrounds
     ========================================================================== */
  
  .hub-tile {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    border: 1px solid var(--border-card);
    box-shadow: var(--shadow-panel, 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1));
    transition: 
      transform 200ms ease,
      box-shadow 200ms ease,
      border-color 200ms ease;
    cursor: pointer;
  }

  .hub-tile:hover {
    transform: translateY(-4px) scale(1.02);
    border-color: var(--border-glow);
    box-shadow: var(--shadow-panel-hover, 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 24px rgba(0, 212, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.15));
  }

  .hub-tile:active {
    transform: translateY(-2px) scale(1.01);
  }

  .hub-tile__background {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    z-index: 0;
  }

  .hub-tile__glass-overlay {
    position: absolute;
    inset: 0;
    /* No blur; optional very subtle sheen only */
    background: transparent;
    z-index: 1;
  }

  /* Global gradient: solid dark left, fade to transparent right so image shows through */
  .hub-tile__gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to right,
      rgba(10, 22, 40, 0.95) 0%,
      rgba(10, 22, 40, 0.7) 40%,
      rgba(10, 22, 40, 0) 100%
    );
    z-index: 2;
  }

  .hub-tile__content {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    height: 100%;
    padding: 20px;
  }

  /* ==========================================================================
     Glowing Neon Icons
     ========================================================================== */
  
  /* Icon + label: top-left, crisp (no blur), subtle glow via drop-shadow/text-shadow */
  .hub-icon {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
  }

  .hub-icon svg {
    filter: var(--shadow-icon-glow, none);
    transition: filter 200ms ease;
  }

  .hub-tile:hover .hub-icon svg {
    filter: var(--shadow-icon-glow-hover, none);
  }

  .hub-icon__label {
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.5px;
  }

  /* ==========================================================================
     Global Header
     ========================================================================== */
  
  .global-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-overlay, rgba(10, 22, 40, 0.85));
    border-bottom: 1px solid var(--border-subtle);
  }

  .global-header__logo {
    justify-self: start;
  }

  .global-header__center {
    display: flex;
    justify-content: center;
    justify-self: center;
  }

  .global-header__user-wrapper {
    justify-self: center;
  }

  .global-header__search {
    justify-self: end;
  }

  .global-header__actions {
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
    padding-right: 2px;
  }

  @supports (backdrop-filter: blur(20px)) {
    .global-header {
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
    }
  }

  .global-header__logo {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }

  .global-header__logo-img {
    height: 32px;
    width: 32px;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 0 1px rgba(125, 211, 252, 0.22);
    overflow: hidden;
  }

  .global-header__logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    margin-left: 4px;
    white-space: nowrap;
  }

  @media (max-width: 1200px) {
    .global-header {
      padding: 10px 14px;
      grid-template-columns: minmax(140px, 1fr) auto minmax(90px, 1fr);
    }

    .global-header__logo {
      gap: 10px;
    }

    .global-header__logo-text {
      font-size: 17px;
      margin-left: 3px;
    }

    .global-header__actions {
      gap: 6px;
      padding-right: 0;
    }
  }

  @media (max-width: 980px) {
    .global-header {
      grid-template-columns: minmax(120px, 1fr) auto minmax(80px, 1fr);
      padding: 9px 10px;
    }

    .global-header__logo-img {
      width: 28px;
      height: 28px;
      border-radius: 7px;
    }

    .global-header__logo-text {
      font-size: 16px;
      margin-left: 2px;
      letter-spacing: 0.35px;
    }

    .global-header__actions {
      gap: 4px;
    }
  }

  .global-header__user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
  }

  /* Wrapper so dropdown anchors under the user pill - shrink-wrap to pill width */
  .global-header__user-wrapper {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
  }

  .global-header__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    min-width: 192px;
    padding: 8px 0;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    /* Must stay above hub tiles (prevent bleed-through) */
    z-index: 2000;
    background: var(--bg-secondary, rgba(6, 16, 28, 0.98));
  }

  .global-header__user:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
  }

  .global-header__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-tertiary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .global-header__search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
  }

  .global-header__search:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
  }

  /* ==========================================================================
     Underwater Background
     ========================================================================== */
  
  .underwater-bg {
    background: 
      radial-gradient(ellipse at 20% 80%, rgba(0, 100, 150, 0.15) 0%, transparent 50%),
      radial-gradient(ellipse at 80% 20%, rgba(0, 150, 200, 0.1) 0%, transparent 40%),
      radial-gradient(ellipse at 50% 50%, rgba(0, 80, 120, 0.08) 0%, transparent 60%),
      linear-gradient(180deg, #050d18 0%, #0a1628 30%, #0d2035 70%, #061220 100%);
    min-height: 100vh;
  }

  /* ==========================================================================
     Interactive States
     ========================================================================== */
  
  .glass-card:hover {
    background: var(--bg-card-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--border-glow, rgba(0, 212, 255, 0.4));
    box-shadow: var(--shadow-glow, 0 0 20px rgba(0, 212, 255, 0.15));
  }

  .glass-card:focus-within {
    border-color: var(--accent-primary, #00d4ff);
    box-shadow: 
      var(--shadow-card, 0 4px 24px rgba(0, 0, 0, 0.3)),
      0 0 0 3px rgba(0, 212, 255, 0.15);
  }

  /* ==========================================================================
     Size Variants
     ========================================================================== */
  
  .glass-card--sm {
    padding: var(--space-sm, 8px) var(--space-md, 16px);
    border-radius: var(--radius-md, 12px);
  }

  .glass-card--md {
    padding: var(--space-md, 16px) var(--space-lg, 24px);
  }

  .glass-card--lg {
    padding: var(--space-lg, 24px) var(--space-xl, 32px);
  }

  /* ==========================================================================
     Style Variants
     ========================================================================== */
  
  /* Elevated variant with stronger shadow */
  .glass-card--elevated {
    box-shadow: 
      var(--shadow-card, 0 4px 24px rgba(0, 0, 0, 0.3)),
      0 8px 32px rgba(0, 0, 0, 0.2);
  }

  /* Glow variant with accent border */
  .glass-card--glow {
    border-color: var(--border-glow, rgba(0, 212, 255, 0.4));
    box-shadow: 
      var(--shadow-card, 0 4px 24px rgba(0, 0, 0, 0.3)),
      var(--shadow-glow, 0 0 20px rgba(0, 212, 255, 0.15));
  }

  /* Interactive/clickable variant */
  .glass-card--interactive {
    cursor: pointer;
  }

  .glass-card--interactive:hover {
    transform: translateY(-2px);
  }

  .glass-card--interactive:active {
    transform: translateY(0);
  }

  /* ==========================================================================
     Status Variants
     ========================================================================== */
  
  .glass-card--success {
    border-color: rgba(0, 255, 136, 0.3);
  }

  .glass-card--success:hover {
    border-color: rgba(0, 255, 136, 0.5);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.15);
  }

  .glass-card--warning {
    border-color: rgba(255, 159, 28, 0.3);
  }

  .glass-card--warning:hover {
    border-color: rgba(255, 159, 28, 0.5);
    box-shadow: 0 0 20px rgba(255, 159, 28, 0.15);
  }

  .glass-card--danger {
    border-color: rgba(255, 71, 87, 0.3);
  }

  .glass-card--danger:hover {
    border-color: rgba(255, 71, 87, 0.5);
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.15);
  }

  /* ==========================================================================
     Card Inner Structure
     ========================================================================== */
  
  .glass-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--space-md, 16px);
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    margin-bottom: var(--space-md, 16px);
  }

  .glass-card__title {
    font-size: var(--text-lg, 16px);
    font-weight: var(--font-semibold, 600);
    color: var(--text-primary, #ffffff);
    margin: 0;
  }

  .glass-card__subtitle {
    font-size: var(--text-sm, 12px);
    color: var(--text-muted, #6b7280);
    margin-top: var(--space-xs, 4px);
  }

  .glass-card__body {
    flex: 1;
  }

  .glass-card__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm, 8px);
    padding-top: var(--space-md, 16px);
    border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    margin-top: var(--space-md, 16px);
  }

  /* ==========================================================================
     Card Icon
     ========================================================================== */
  
  .glass-card__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card, rgba(255, 255, 255, 0.05));
    border-radius: var(--radius-md, 12px);
    color: var(--accent-primary, #00d4ff);
  }

  .glass-card__icon svg {
    width: 20px;
    height: 20px;
  }

  /* ==========================================================================
     Parameter Detail Modal – scrollable Recent Readings (thin themed scrollbar)
     ========================================================================== */
  .parameter-detail-modal-readings-scroll {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 212, 255, 0.5) rgba(255, 255, 255, 0.06);
  }
  .parameter-detail-modal-readings-scroll::-webkit-scrollbar {
    width: 8px;
  }
  .parameter-detail-modal-readings-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
  }
  .parameter-detail-modal-readings-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.4);
    border-radius: 4px;
    box-shadow: 0 0 6px rgba(0, 212, 255, 0.3);
  }
  .parameter-detail-modal-readings-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.6);
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
  }

  /* ==========================================================================
     Parameter Row Layout (Dashboard)
     Horizontal layout with "squeeze" behavior:
     sparkline shrinks first, metrics remain readable.
     ========================================================================== */
  .parameter-row-layout {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    min-width: 0;
  }

  .parameter-row-graph {
    flex: 1 1 auto;
    min-width: 50px;
  }

  .parameter-row-graph .sparkline-container {
    min-width: 50px;
    flex-shrink: 1;
  }

  .parameter-row-metrics {
    flex: 0 0 auto;
    min-width: 130px;
    max-width: 62%;
    font-variant-numeric: tabular-nums;
  }

  /* Mobile-specific adjustment */
  @media (max-width: 640px) {
    .parameter-row-metrics {
      min-width: 110px;
    }
  }

  /* ==========================================================================
     Parameter Tile Value Layout
     ========================================================================== */
  .parameter-value {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 0;
    min-width: 0;
    width: 100%;
    text-align: right;
    line-height: 1.15;
    white-space: nowrap;
    font-family: var(--font-mono);
  }

  .parameter-value--single {
    flex-wrap: nowrap;
    padding-right: 0.35rem;
  }

  .parameter-value--stacked {
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 0.2rem;
    line-height: 1.25;
    padding-right: 0.35rem;
    white-space: nowrap;
  }

  .parameter-value-number {
    font-variant-numeric: tabular-nums;
    display: inline-block;
    min-width: 5.8ch;
    text-align: right;
  }

  .parameter-unit {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-left: 2px;
    line-height: 1;
    display: inline-block;
    min-width: 2.8ch;
    text-align: left;
  }

  .parameter-unit--placeholder {
    visibility: hidden;
  }

  .parameter-range-line {
    display: inline-flex;
    align-items: baseline;
    justify-content: flex-end;
    width: 100%;
    gap: 0;
  }

  .parameter-range-label {
    opacity: 0.5;
    min-width: 2.2ch;
    text-align: left;
    margin-right: 0.35rem;
  }
}
