/* ==========================================================================
   Snowbird Longevity OS 3.0 - Standalone SaaS Platform Stylesheet
   Theme: Enterprise Medical Longevity & Precision Digital Health
   ========================================================================== */

:root {
  --saas-bg: #050811;
  --saas-sidebar: #090E1C;
  --saas-topbar: rgba(9, 14, 28, 0.92);
  --saas-card: #0E162A;
  --saas-card-hover: #141F3A;
  --saas-border: rgba(255, 255, 255, 0.08);
  --saas-border-glow: rgba(16, 185, 129, 0.3);
  
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  
  --accent-emerald: #10B981;
  --accent-cyan: #06B6D4;
  --accent-blue: #3B82F6;
  --accent-purple: #8B5CF6;
  --accent-amber: #F59E0B;
  --accent-rose: #F43F5E;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--saas-bg);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Top Header & Global Role Switcher
   ========================================================================== */
.saas-header {
  height: 64px;
  max-height: 64px;
  background: var(--saas-topbar);
  border-bottom: 1px solid var(--saas-border);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
  flex-shrink: 0;
  gap: 12px;
}

.saas-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.saas-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10B981 0%, #06B6D4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.saas-title h1 {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.saas-title p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Role Switcher Toolbar (Center piece of UX) */
.role-switcher-group {
  display: flex;
  align-items: center;
  background: rgba(14, 22, 42, 0.8);
  border: 1px solid var(--saas-border);
  padding: 3px;
  border-radius: 9999px;
  gap: 3px;
  flex-shrink: 0;
}

.btn-role-tab {
  padding: 6px 14px;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-role-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn-role-tab.active {
  background: linear-gradient(135deg, #10B981 0%, #06B6D4 100%);
  color: #000;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
  font-weight: 700;
}

/* Right Profile Actions */
.saas-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.center-select-box {
  background: var(--saas-card);
  border: 1px solid var(--saas-border);
  border-radius: 6px;
  color: var(--accent-cyan);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  max-width: 190px;
}

.center-select-box option {
  background: #0E162A;
  color: #FFF;
}

.hipaa-shield-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.1);
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.btn-back-home {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--saas-border);
  transition: 0.2s;
}

.btn-back-home:hover {
  color: #FFF;
  border-color: var(--text-secondary);
}

/* ==========================================================================
   Main App Workspace (Sidebar + Dynamic Content)
   ========================================================================== */
.saas-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* Sidebar */
.saas-sidebar {
  width: 240px;
  background: var(--saas-sidebar);
  border-right: 1px solid var(--saas-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 16px 12px;
}

.sidebar-category {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 8px 12px 4px 12px;
  margin-top: 8px;
}

.sidebar-nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: rgba(16, 185, 129, 0.15);
  color: #FFF;
  border-left: 3px solid var(--accent-emerald);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--saas-border);
  padding-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.user-meta-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-meta-role {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */
.saas-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 60px 32px;
  background-color: var(--saas-bg);
}

/* View Header */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.view-header p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 2px;
}

/* ==========================================================================
   Common Dashboard Cards & Grids
   ========================================================================== */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.grid-4col {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.saas-card {
  background: var(--saas-card);
  border: 1px solid var(--saas-border);
  border-radius: 14px;
  padding: 20px;
  position: relative;
  transition: border-color 0.2s;
}

.saas-card:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title-row h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #FFF;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   MEMBER PORTAL SPECIFIC: Longevity Clock & CGM Chart
   ========================================================================== */
.longevity-clock-hero {
  background: linear-gradient(135deg, #101B30 0%, #0A1120 100%);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 18px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  position: relative;
  overflow: hidden;
}

.longevity-clock-hero::after {
  content: "";
  position: absolute;
  top: -30%;
  right: -5%;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.clock-main-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 20px;
  align-items: center;
}

.clock-dial-box {
  display: flex;
  align-items: center;
  gap: 20px;
}

.bio-age-number {
  font-size: 3.2rem;
  font-weight: 900;
  font-family: var(--font-mono);
  color: var(--accent-emerald);
  line-height: 1;
}

.bio-age-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.bio-delta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.2);
  color: #34D399;
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 6px;
}

.metric-pill-item {
  background: rgba(10, 15, 28, 0.6);
  border: 1px solid var(--saas-border);
  border-radius: 12px;
  padding: 14px 18px;
}

.metric-pill-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.metric-pill-val {
  font-size: 1.4rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #FFF;
}

/* CGM Dynamic Chart Container */
.cgm-chart-box {
  height: 220px;
  width: 100%;
  position: relative;
  margin-top: 10px;
}

.cgm-svg-chart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Daily Checklist */
.task-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--saas-border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.task-item-row:hover {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(255, 255, 255, 0.15);
}

.task-item-row.completed {
  opacity: 0.65;
  background: rgba(16, 185, 129, 0.05);
  border-color: rgba(16, 185, 129, 0.2);
}

.task-check-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #64748B;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 12px;
}

.task-item-row.completed .task-check-circle {
  background: var(--accent-emerald);
  border-color: var(--accent-emerald);
  color: #000;
  font-weight: bold;
  font-size: 0.8rem;
}

/* ==========================================================================
   CARE TEAM WORKSTATION SPECIFIC
   ========================================================================== */
.alert-banner-box {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-badge-critical {
  background: #F43F5E;
  color: #FFF;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.btn-action-sop {
  background: var(--accent-rose);
  color: #FFF;
  border: none;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.btn-action-sop:hover {
  transform: scale(1.04);
}

/* Clinical Table */
.clinician-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.clinician-table th {
  background: #090E1C;
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--saas-border);
  text-align: left;
}

.clinician-table td {
  padding: 14px;
  border-bottom: 1px solid var(--saas-border);
  color: var(--text-secondary);
}

.clinician-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.patient-name-cell strong {
  color: #FFF;
  display: block;
}

.patient-name-cell span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* AI Report Generator Card */
.ai-generator-hero {
  background: linear-gradient(145deg, #131B30 0%, #0A0E18 100%);
  border: 1px solid rgba(6, 182, 212, 0.35);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

.btn-ai-generate {
  background: linear-gradient(135deg, #06B6D4 0%, #3B82F6 100%);
  color: #FFF;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.3);
  transition: all 0.2s;
}

.btn-ai-generate:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.45);
}

/* ==========================================================================
   ADMIN OPERATIONS SPECIFIC
   ========================================================================== */
.multi-center-pill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.center-card-item {
  background: var(--saas-card);
  border: 1px solid var(--saas-border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.center-card-item:hover,
.center-card-item.active {
  border-color: var(--accent-cyan);
  background: #111A30;
}

.center-card-item h4 {
  font-size: 0.95rem;
  color: #FFF;
  margin-bottom: 4px;
}

.center-card-item p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Audit Log List */
.audit-log-stream {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.audit-log-row {
  background: rgba(10, 15, 26, 0.6);
  border: 1px solid var(--saas-border);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ==========================================================================
   Modal Dialogs & Drawers
   ========================================================================== */
.saas-modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 7, 15, 0.82);
  backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.saas-modal-backdrop.active {
  display: flex;
}

.saas-modal-dialog {
  background: #0E162A;
  border: 1px solid var(--saas-border-glow);
  border-radius: 18px;
  max-width: 720px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.6);
  position: relative;
}

.modal-close-icon {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #FFF;
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .clock-main-grid {
    grid-template-columns: 1fr 1fr;
  }
  .grid-3col, .grid-4col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  /* Header adjustments for mobile */
  .saas-header {
    height: auto;
    max-height: none;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 8px;
    position: sticky;
    top: 0;
  }

  .saas-brand {
    justify-content: space-between;
    width: 100%;
  }
  .saas-title h1 {
    font-size: 0.95rem;
  }
  .saas-title p {
    display: none;
  }

  .role-switcher-group {
    width: 100%;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px;
    background: rgba(14, 22, 42, 0.95);
    gap: 4px;
  }
  .role-switcher-group::-webkit-scrollbar {
    display: none;
  }
  .btn-role-tab {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.78rem;
    white-space: nowrap;
    gap: 4px;
  }

  .saas-top-right {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
  }
  .center-select-box {
    flex: 1;
    max-width: none;
    font-size: 0.75rem;
    padding: 6px 8px;
  }
  .hipaa-shield-badge {
    display: none;
  }
  .btn-back-home {
    font-size: 0.75rem;
    padding: 6px 10px;
    white-space: nowrap;
  }

  /* Layout: Convert desktop sidebar to horizontal swipeable bar */
  .saas-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .saas-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--saas-border);
    padding: 8px;
    background: #090E1C;
    flex-direction: row;
    align-items: center;
  }
  .sidebar-category {
    display: none;
  }
  .sidebar-nav-list {
    flex-direction: row;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    width: 100%;
  }
  .sidebar-nav-list::-webkit-scrollbar {
    display: none;
  }
  .sidebar-item {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.78rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--saas-border);
  }
  .sidebar-item.active {
    border-left: 1px solid var(--accent-emerald);
    background: rgba(16, 185, 129, 0.2);
    color: #FFF;
  }
  .sidebar-footer {
    display: none;
  }

  /* Main Content Canvas */
  .saas-content {
    padding: 14px 12px 60px 12px;
    overflow-y: visible;
    width: 100%;
  }

  .view-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .view-header h2 {
    font-size: 1.2rem;
  }
  .view-header button,
  .view-header .btn-ai-generate {
    width: 100%;
    justify-content: center;
  }

  /* Red-flag Alert on Mobile */
  .alert-banner-box {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .btn-action-sop {
    width: 100%;
    text-align: center;
    padding: 10px;
    font-size: 0.85rem;
  }

  /* Card layouts */
  .grid-2col, .grid-3col, .grid-4col, .clock-main-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .longevity-clock-hero {
    padding: 16px 14px;
    border-radius: 14px;
  }
  .bio-age-number {
    font-size: 2.4rem;
  }

  .saas-card {
    padding: 16px 14px;
    border-radius: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* CGM Chart */
  .cgm-chart-box {
    height: 180px;
  }

  /* Table responsive wrap */
  .clinician-table {
    min-width: 620px;
  }
  .clinician-table th, .clinician-table td {
    padding: 10px 8px;
    font-size: 0.78rem;
  }

  /* Modals on mobile */
  .saas-modal-dialog {
    max-width: 95%;
    padding: 20px 14px;
    max-height: 90vh;
  }
}
