/* ============================================================
   HealthPortal — Main Stylesheet
   Design system: Inter/system-ui, primary #0066CC, sidebar #1A2B4A
   ============================================================ */

/* ---- Custom Properties ---- */
:root {
  --primary:        #0066CC;
  --primary-dark:   #0052A3;
  --secondary:      #00A3A3;
  --success:        #28A745;
  --warning:        #FFC107;
  --danger:         #DC3545;
  --light-bg:       #F8F9FA;
  --sidebar-bg:     #1A2B4A;
  --sidebar-text:   #CBD5E0;
  --card-shadow:    0 2px 8px rgba(0,0,0,0.08);

  /* Override Bootstrap's default blue (#0d6efd) with portal primary (#0066CC)
     so all Bootstrap components (outline buttons, badges, text-primary, etc.)
     use the same brand color as portal.css custom components. */
  --bs-primary:              #0066CC;
  --bs-primary-rgb:          0,102,204;
  --bs-link-color:           #0066CC;
  --bs-link-color-rgb:       0,102,204;
  --bs-link-hover-color:     #0052A3;
  --bs-link-hover-color-rgb: 0,82,163;
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ---- Base ---- */
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: #1A202C;
  background-color: var(--light-bg);
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

/* ---- Layout: Sidebar + Main ---- */
.layout-sidebar {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-logo {
  padding: 1.25rem 1.5rem;
  font-weight: 700;
  font-size: 1.25rem;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
}

.sidebar-logo img {
  height: 28px;
  width: auto;
}

.sidebar-nav {
  flex-grow: 1;
  padding: 1rem 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.5rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color 0.15s ease, border-left-color 0.15s ease, background 0.15s ease;
  font-size: 0.9rem;
  white-space: nowrap;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: #fff;
  border-left-color: var(--primary);
  background: rgba(255,255,255,0.08);
  text-decoration: none;
}

.sidebar-nav a svg,
.sidebar-nav a img {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-nav a:hover svg,
.sidebar-nav a.active svg {
  opacity: 1;
}

.sidebar-section-label {
  padding: 0.5rem 1.5rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(203,213,224,0.5);
  margin-top: 0.5rem;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.8rem;
  color: rgba(203,213,224,0.7);
}

/* ---- Main Content ---- */
.main-content {
  flex-grow: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.topbar-title {
  font-weight: 600;
  font-size: 1.1rem;
  color: #2D3748;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ---- Page Content ---- */
.page-content {
  padding: 2rem;
  flex-grow: 1;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1A202C;
  margin: 0 0 0.25rem;
}

.page-header .breadcrumb {
  font-size: 0.85rem;
  color: #718096;
}

/* ---- Card ---- */
/* No padding here — Bootstrap's .card-body handles inner spacing.
   Override Bootstrap's default border/shadow so portal cards look consistent. */
.card {
  box-shadow: var(--card-shadow);
  border-color: #E2E8F0;
}

.card-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 1rem;
  color: #2D3748;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-header h2,
.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #2D3748;
  margin: 0;
}

/* ---- Stat Card ---- */
.stat-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}

.stat-label {
  font-size: 0.875rem;
  color: #718096;
  margin-top: 0.25rem;
}

.stat-change {
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger);  }

/* ---- Stat Grid ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  line-height: 1;
  white-space: nowrap;
}

.badge-normal {
  background: #D1FAE5;
  color: #065F46;
}

.badge-abnormal {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-pending {
  background: #FEF3C7;
  color: #92400E;
}

/* ---- Appointment Status Badges ---- */
.status-scheduled  { background: #DBEAFE; color: #1E40AF; border-radius: 9999px; padding: 0.2em 0.6em; font-size: 0.75rem; font-weight: 600; }
.status-completed  { background: #D1FAE5; color: #065F46; border-radius: 9999px; padding: 0.2em 0.6em; font-size: 0.75rem; font-weight: 600; }
.status-cancelled  { background: #FEE2E2; color: #991B1B; border-radius: 9999px; padding: 0.2em 0.6em; font-size: 0.75rem; font-weight: 600; }
.status-noshow     { background: #FEF3C7; color: #92400E; border-radius: 9999px; padding: 0.2em 0.6em; font-size: 0.75rem; font-weight: 600; }

/* ---- Auth / Form Card ---- */
.form-card {
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 2.5rem 2rem;
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.auth-logo img {
  height: 40px;
  margin-bottom: 0.5rem;
}

/* ---- Forms ---- */
.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #4A5568;
  margin-bottom: 0.25rem;
  display: block;
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid #CBD5E0;
  border-radius: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  color: #1A202C;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.15);
}

.form-group {
  margin-bottom: 1rem;
}

.form-hint {
  font-size: 0.8rem;
  color: #718096;
  margin-top: 0.25rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
  text-decoration: none;
}

/* Fix Bootstrap's hardcoded #0d6efd in outline-primary and secondary variants */
.btn-outline-primary {
  --bs-btn-color:              var(--primary);
  --bs-btn-border-color:       var(--primary);
  --bs-btn-hover-bg:           var(--primary);
  --bs-btn-hover-border-color: var(--primary);
  --bs-btn-active-bg:          var(--primary);
  --bs-btn-active-border-color: var(--primary);
  --bs-btn-disabled-color:     var(--primary);
  --bs-btn-disabled-border-color: var(--primary);
}

.btn-secondary {
  background: #fff;
  color: var(--primary);
  border-color: #CBD5E0;
}

.btn-secondary:hover {
  background: #F7FAFC;
  color: var(--primary-dark);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #C82333;
  color: #fff;
  text-decoration: none;
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
}

.btn-block {
  display: flex;
  width: 100%;
  justify-content: center;
}

/* ---- Tables ---- */
.table-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 1rem;
}

.table-wrapper {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table thead th {
  background: #F7FAFC;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #718096;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #E2E8F0;
  white-space: nowrap;
}

.table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #F0F4F8;
  color: #2D3748;
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-hover tbody tr:hover {
  background: #EBF4FF;
}

.alert-abnormal {
  background: #FFF5F5;
  border-left: 3px solid var(--danger);
}

.alert-abnormal td {
  color: #742A2A;
}

/* ---- Messages / Chat Bubbles ---- */
.message-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  max-height: 480px;
  overflow-y: auto;
}

.message-bubble {
  max-width: 70%;
  padding: 0.625rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  position: relative;
}

.message-bubble.sent {
  background: var(--primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message-bubble.received {
  background: #F0F4F8;
  color: #2D3748;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  opacity: 0.7;
}

/* ---- Alerts ---- */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.alert-success  { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-danger   { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning  { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-info     { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ---- Navigation Pills (public header) ---- */
.nav-pills .nav-link.active {
  background-color: rgba(255,255,255,0.2);
  font-weight: 600;
}

.nav-link {
  border-radius: 0.375rem;
  margin-bottom: 2px;
}

/* ---- Tabs ---- */
.tab-list {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #E2E8F0;
  margin-bottom: 1.5rem;
}

.tab-item {
  padding: 0.625rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #718096;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  text-decoration: none;
  transition: color 0.15s;
}

.tab-item:hover,
.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  text-decoration: none;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #A0AEC0;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.95rem;
  margin: 0;
}

/* ---- Avatar ---- */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #CBD5E0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: #4A5568;
  flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }

/* ---- MRN / ID Tag ---- */
.mrn-tag {
  display: inline-block;
  font-family: 'SF Mono', 'Fira Mono', 'Courier New', monospace;
  font-size: 0.8rem;
  background: #EBF4FF;
  color: #2B6CB0;
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* ---- Notification Dot ---- */
.notif-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  vertical-align: middle;
  margin-left: 4px;
}

/* ---- Vital Range Indicators ---- */
.vital-normal   { color: var(--success);  font-weight: 600; }
.vital-high     { color: var(--danger);   font-weight: 600; }
.vital-low      { color: var(--warning);  font-weight: 600; }

/* ---- Printable Statement ---- */
.statement-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-260px);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .page-content {
    padding: 1rem;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .table-card {
    overflow-x: auto;
  }

  .form-card {
    padding: 1.5rem 1rem;
  }

  .topbar {
    padding: 0 1rem;
  }

  .message-bubble {
    max-width: 90%;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Print Styles ---- */
@media print {
  .sidebar,
  .topbar,
  .btn,
  .no-print {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }

  .page-content {
    padding: 0;
  }

  .card,
  .stat-card,
  .table-card {
    box-shadow: none;
    border: 1px solid #E2E8F0;
  }

  .table tbody tr:hover {
    background: none;
  }

  body {
    font-size: 11pt;
    color: #000;
  }
}
