/* ==========================================================================
   Medicred Client Portal - High-Contrast App Interface
   Brand Colors:
   Primary Blue: #009FDA (Vibrant & Welcoming)
   Primary Green: #A6C23A (Success & Action)
   Dark Blue: #002136 (Deep, Premium Contrast)
   ========================================================================== */

:root {
  /* Brand Core */
  --color-blue: #009FDA;
  --color-green: #A6C23A;
  --color-dark: #002136;
  
  /* UI Palette */
  --color-white: #FFFFFF;
  --color-bg: #F0F4F8;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F8FAFC;
  --color-input-bg: #Eef2f6;
  
  /* Text */
  --color-text: #1E293B;
  --color-text-muted: #64748B;
  
  /* Structural */
  --color-border: #E2E8F0;
  
  /* Typography */
  --font-family: 'Omnes Pro', 'Omnes', -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  
  /* Radii */
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-pill: 9999px;
  
  /* Shadows */
  --shadow-glass: 0 8px 32px rgba(0, 33, 54, 0.08);
  --shadow-card: 0 10px 30px -4px rgba(0, 33, 54, 0.06);
  --shadow-float: 0 20px 40px -10px rgba(0, 159, 218, 0.15);
  
  /* Animation */
  --transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ==========================================================================
   Global & Typography
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-family);
  background-color: var(--color-bg);
  background-image: 
    radial-gradient(circle at 100% 0%, rgba(0, 159, 218, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 0% 100%, rgba(166, 194, 58, 0.04) 0%, transparent 40%);
  background-attachment: fixed;
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--color-dark); font-weight: 700; letter-spacing: -0.03em; }
a { color: var(--color-blue); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--color-dark); }
.muted { color: var(--color-text-muted); }

.container {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem 1.5rem;
}
.container.narrow { max-width: 720px; }

/* ==========================================================================
   The "Floating Island" Navigation (Scroll & Dropdown Added)
   ========================================================================== */
.topbar {
  position: sticky;
  top: 1rem;
  z-index: 100;
  max-width: 1140px;
  margin: 1rem auto 3rem auto;
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-glass);
  border: 1px solid rgba(255, 255, 255, 0.8);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: nowrap;
  /* Smooth slide up/down on scroll */
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.3s ease;
}

/* When Javascript detects scrolling down, it adds this class */
.topbar.header-hidden {
  transform: translateY(calc(-100% - 2rem));
}

.topbar-brand {
  display: flex;
  align-items: center;
}

.topbar-brand .muted { display: none; }
.topbar-logo { height: 64px; width: auto; flex-shrink: 0; margin-bottom: -0.5rem; }

/* Hide mobile toggle by default on desktop */
.mobile-menu-toggle { display: none; }

/* Desktop Navigation Links */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  white-space: nowrap;
}

.topbar-actions a {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-pill);
}

.topbar-actions a:hover {
  background-color: rgba(0, 159, 218, 0.1);
  color: var(--color-blue);
}

/* ==========================================================================
   Mobile Nav Structure - Dropdown Conversion
   ========================================================================== */
@media (max-width: 768px) {
  .topbar {
    top: 0.5rem;
    margin: 0.5rem 1rem 2rem 1rem;
    padding: 1rem 1.25rem;
    flex-direction: column;
    align-items: flex-start;
    border-radius: var(--radius-lg);
    gap: 0;
  }

  .topbar-brand {
    justify-content: space-between;
    width: 100%;
  }
  
  /* OVERRIDE the global button styles specifically for the toggle */
  button.mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto; /* Fixes the 100% stretch */
    gap: 0.5rem;
    background-color: var(--color-input-bg); /* Clean gray pill */
    color: var(--color-dark);
    font-size: 0.9rem;
    padding: 1rem 1rem;
    border: none;
    border-radius: var(--radius-pill);
    box-shadow: none; /* Removes big shadow */
    cursor: pointer;
    transition: var(--transition);
  }
  
  /* The Down Arrow indicator */
  button.mobile-menu-toggle::after {
    content: '';
    display: inline-block;
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--color-dark);
    transition: transform 0.3s ease;
  }
  
  button.mobile-menu-toggle:hover {
    background-color: #E2E8F0;
    transform: translateY(0); /* Prevents the hover jump effect */
    box-shadow: none;
  }

  /* The Nav Menu (Hidden by Default) */
  .topbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    overflow: hidden;
    max-height: 0; /* Hides the old menu completely */
    opacity: 0;
    padding: 0;
    transition: max-height 0.4s ease, opacity 0.3s ease, margin-top 0.3s ease, padding 0.3s ease;
  }
  
  /* Styles applied when you click the menu button */
  .topbar.menu-open .topbar-actions {
    max-height: 400px;
    opacity: 1;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
  }
  
  /* Make the button blue when active */
  .topbar.menu-open button.mobile-menu-toggle {
    background-color: rgba(0, 159, 218, 0.1);
    color: var(--color-blue);
  }
  
  /* Flip the arrow to point UP when active */
  .topbar.menu-open button.mobile-menu-toggle::after {
    transform: rotate(180deg);
    border-top-color: var(--color-blue);
  }

  /* Bigger, card-like tap targets for mobile nav links */
  .topbar-actions a {
    text-align: center;
    padding: 0.8rem 1rem;
    background-color: var(--color-surface-hover);
    border-radius: var(--radius-sm);
  }
}

/* ==========================================================================
   Headings & Badges
   ========================================================================== */
.page-heading { margin-bottom: 1.5rem; text-align: center; }
.page-heading h1 { font-size: 2.5rem; margin-bottom: 0.5rem; line-height: 2.8rem; }

.split-heading { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }
.pill-stack { display: flex; justify-content: center; gap: 0.5rem; flex-wrap: wrap; }

@media (min-width: 768px) {
  .page-heading { text-align: left; }
  .split-heading { flex-direction: row; justify-content: space-between; align-items: flex-end; }
  .pill-stack { justify-content: flex-end; }
}

@media (max-width: 768px) {
  .pill-stack { width: 100%; justify-content: center; }
}

.last-refreshed { display: inline-flex; align-items: center; padding: 0.5rem 1.25rem; font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); background-color: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-pill); margin-top: 0.75rem; box-shadow: 0 2px 8px rgba(0, 33, 54, 0.04); }
@media (max-width: 768px) { .last-refreshed { width: 100%; justify-content: center; } }

.status-pill { display: inline-flex; align-items: center; padding: 0.5rem 1.25rem; font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; border-radius: var(--radius-pill); }
.stage-approved { background-color: var(--color-blue); color: var(--color-white); box-shadow: 0 4px 14px rgba(68, 168, 199, 0.382); justify-content: center; width: 100%; }
.status-pill.na { background-color: var(--color-input-bg); color: var(--color-text-muted); }

/* ==========================================================================
   Dashboard Layout & Cards
   ========================================================================== */
.dashboard-overview { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2.5rem; }
@media (min-width: 992px) { .dashboard-overview { grid-template-columns: 1fr 360px; } }
.overview-left { display: flex; flex-direction: column; gap: 1.5rem; height: 100%; }
.summary-card, .chart-card, .detail-card, .action-card, .panel-form { background-color: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 2rem; }
.detail-card-your-info { margin-bottom: 2rem; }
.detail-card h2 { font-size: 1.4rem; margin-bottom: 1.5rem; }

.summary-row-status { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px) { .summary-row-status { grid-template-columns: repeat(3, 1fr); gap: 1.5rem; align-items: stretch; } }

.finance-card { display: flex; flex-direction: column; justify-content: center; height: 100%; }
.finance-card span { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); margin-bottom: 0.5rem; }
.finance-card strong { font-size: 1.4rem; color: var(--color-dark); }

.finance-card-large { background: linear-gradient(135deg, var(--color-dark) 0%, #001524 100%); color: var(--color-white); padding: 3.1rem 2.5rem; position: relative; overflow: hidden; height: 100%; }
.finance-card-large::after { content: ''; position: absolute; right: -10%; bottom: -20%; width: 250px; height: 250px; background: radial-gradient(circle, rgba(0, 159, 218, 0.2) 0%, transparent 70%); border-radius: 50%; pointer-events: none; }
.finance-card-large span { color: var(--color-white); }
.finance-card-large strong { font-size: 3.5rem; color: var(--color-blue); line-height: 1.1; margin: 0.25rem 0 1rem 0; text-shadow: 0 4px 20px rgba(83, 176, 201, 0.22); }
.finance-card-large small { font-size: 0.9rem; color: var(--color-white); }
@media (max-width: 767px) { .finance-card-large { padding: 2rem 1.5rem; } }

/* ==========================================================================
   Details Grids & Timeline
   ========================================================================== */
.portal-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2.5rem; }
@media (min-width: 992px) { .portal-grid { grid-template-columns: 1fr 1fr; } }
.details-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 500px) { .details-grid { grid-template-columns: 1fr 1fr; } }
.details-grid div { display: flex; flex-direction: column; }
.details-grid dt { font-size: 0.75rem; color: var(--color-text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.details-grid dd { font-size: 1.05rem; color: var(--color-dark); font-weight: 600; background: var(--color-input-bg); padding: 0.75rem 1.25rem; border-radius: var(--radius-sm); }

.chart-card-header { margin-bottom: 1rem; }
.chart-card-header span { display: block; font-size: 1.25rem; font-weight: 700; color: var(--color-dark); }
.chart-card-header strong { display: inline-block; font-size: 0.9rem; color: var(--color-blue); }

.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; top: 8px; bottom: 0; left: 9px; width: 2px; background-color: var(--color-border); }
.timeline-item { position: relative; margin-bottom: 2rem; }
.timeline-item:last-child { margin-bottom: 0; }
.timeline-dot { position: absolute; left: -2rem; top: 0.25rem; width: 20px; height: 20px; border-radius: 50%; background-color: var(--color-white); border: 3px solid var(--color-border); z-index: 1; }
.timeline-item strong { display: block; color: var(--color-dark); font-size: 1.05rem; margin-bottom: 0.25rem; }
.timeline-item p { font-size: 0.9rem; color: var(--color-text-muted); }
.timeline-item.done .timeline-dot { background-color: var(--color-green); border-color: var(--color-white); box-shadow: 0 0 0 3px var(--color-green); }
.timeline-item.current .timeline-dot { background-color: var(--color-white); border-color: var(--color-blue); border-width: 5px; animation: pulse-blue 2s infinite; }
.timeline-item.current strong { color: var(--color-blue); }
@keyframes pulse-blue { 0% { box-shadow: 0 0 0 0 rgba(0, 159, 218, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(0, 159, 218, 0); } 100% { box-shadow: 0 0 0 0 rgba(0, 159, 218, 0); } }

/* ==========================================================================
   Action Cards
   ========================================================================== */
.portal-actions-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 768px) { .portal-actions-grid { grid-template-columns: repeat(3, 1fr); } }
.action-card { display: flex; flex-direction: column; padding: 1.75rem; background-color: var(--color-green); border-radius: var(--radius-md); border: 2px solid transparent; transition: var(--transition); position: relative; overflow: hidden; }
.action-card::before { content: ''; position: absolute; top: -1px; left: 2px; right: 2px; height: 4px; background: var(--color-white); transform: scaleX(0); transform-origin: left; transition: transform 0.3s ease; }
.action-card strong { color: var(--color-white); font-size: 1.1rem; margin-bottom: 0.5rem; transition: var(--transition); }
.action-card span { font-size: 0.95rem; color: var(--color-white); }
.action-card:hover { border-color: var(--color-green); box-shadow: var(--shadow-float); transform: translateY(-4px); }
.action-card:hover::before { transform: scaleX(1); }
.action-card:hover strong { color: var(--color-white); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-card { padding: 1rem; margin: -1rem; margin-bottom: 2rem; background: transparent; box-shadow: none; overflow-x: auto; scrollbar-width: none; }
.table-card::-webkit-scrollbar { display: none; }
.table-card table { width: 100%; border-collapse: separate; border-spacing: 0 0.5rem; text-align: left; }
.table-card th { padding: 0 1.5rem 0.5rem 1.5rem; font-weight: 700; font-size: 0.8rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.table-card tbody tr { background-color: var(--color-surface); box-shadow: var(--shadow-card); transition: var(--transition); }
.table-card td { padding: 1.25rem 1.5rem; font-size: 1rem; color: var(--color-dark); font-weight: 600; white-space: nowrap; }
.table-card tbody tr td:first-child { border-top-left-radius: var(--radius-md); border-bottom-left-radius: var(--radius-md); }
.table-card tbody tr td:last-child { border-top-right-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }
.table-card tbody tr:hover { transform: scale(1.01); box-shadow: var(--shadow-float); background-color: var(--color-white); z-index: 2; position: relative; }

@media (max-width: 768px) {
  .table-card { overflow-x: visible; padding: 0; margin: 0 0 2rem 0; }
  .table-card table, .table-card thead, .table-card tbody, .table-card tr, .table-card td, .table-card th { display: block; width: 100%; }
  .table-card thead { display: none; }
  .table-card tbody tr { margin-bottom: 1.5rem; padding: 1rem 0; border-radius: var(--radius-lg); }
  .table-card tbody tr td { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1.5rem; text-align: right; border-bottom: 1px solid var(--color-border); border-radius: 0 !important; white-space: normal; }
  .table-card tbody tr td:last-child { border-bottom: none; }
  .table-card td::before { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); text-align: left; margin-right: 1rem; flex-shrink: 0; }
  .table-card td:nth-of-type(1)::before { content: "Invoice Date"; }
  .table-card td:nth-of-type(2)::before { content: "Invoice Number"; }
  .table-card td:nth-of-type(3)::before { content: "Amount Due"; }
  .table-card td:nth-of-type(4)::before { content: "Payment Due"; }
  .table-card td:nth-of-type(5)::before { content: "Payment Date"; }
  .table-card td:nth-of-type(6)::before { content: "Payment Amount"; }
}

/* ==========================================================================
   Forms & Inputs 
   ========================================================================== */
.back-link { display: inline-flex; align-items: center; font-size: 1rem; font-weight: 600; color: var(--color-text-muted); margin-bottom: 2rem; }
.back-link:hover { color: var(--color-blue); transform: translateX(-5px); }
.readonly-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1.5rem; background-color: var(--color-input-bg); padding: 1.5rem; border-radius: var(--radius-md); margin-bottom: 2.5rem; }
.readonly-summary div { display: flex; flex-direction: column; }
.readonly-summary span { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 0.3rem; }
.readonly-summary strong { font-size: 1.05rem; color: var(--color-dark); }
.form, .panel-form { display: flex; flex-direction: column; gap: 1.5rem; }
.form label, .panel-form label { display: flex; flex-direction: column; font-weight: 600; font-size: 1rem; color: var(--color-dark); gap: 0.75rem; }
.form input, .form textarea, .panel-form input, .panel-form textarea { width: 100%; padding: 1.15rem 1.25rem; font-family: var(--font-family); font-size: 1.05rem; color: var(--color-dark); background-color: var(--color-input-bg); border: 2px solid transparent; border-radius: var(--radius-sm); transition: var(--transition); }
.form textarea, .panel-form textarea { min-height: 160px; resize: vertical; }
.form input:focus, .form textarea:focus, .panel-form input:focus, .panel-form textarea:focus { outline: none; background-color: var(--color-white); border-color: var(--color-blue); box-shadow: 0 0 0 5px rgba(0, 159, 218, 0.15); }
button, .button { display: inline-flex; align-items: center; justify-content: center; width: 100%; padding: 1.25rem 1.5rem; background-color: var(--color-blue); color: var(--color-white); font-family: var(--font-family); font-size: 1.1rem; font-weight: 700; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition); box-shadow: 0 8px 20px rgba(0, 159, 218, 0.3); }
button:hover, .button:hover { background-color: var(--color-dark); color: var(--color-white); transform: translateY(-3px); box-shadow: 0 12px 24px rgba(0, 33, 54, 0.25); }
@media (min-width: 640px) { button, .button { width: auto; padding: 1.25rem 3rem; } }

/* ==========================================================================
   Auth Pages & Alerts
   ========================================================================== */
body.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; background: radial-gradient(circle at 10% 20%, rgba(0, 159, 218, 0.15) 0%, transparent 40%), radial-gradient(circle at 90% 80%, rgba(166, 194, 58, 0.15) 0%, transparent 40%), var(--color-bg); }
.auth-card { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(20px); width: 100%; max-width: 480px; padding: 4rem 3rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-float); text-align: center; }
.login-logo { max-width: 260px; height: auto; margin-bottom: 2rem; }
.auth-link-row { margin-top: 2rem; font-size: 1rem; font-weight: 600; }
.alert { padding: 1.25rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; font-size: 1rem; font-weight: 600; text-align: left; }
.alert-error { background-color: #FEF2F2; color: #DC2626; border: 2px solid #FCA5A5; }
.alert-success { background-color: #F4F8E8; color: #3b4d08; border: 2px solid rgba(166, 194, 58, 0.5); }
/* ==========================================================================
   Documents page button layout refinement
   ========================================================================== */
.document-table-card th:nth-child(4),
.document-table-card td:nth-child(4) {
  width: 100%;
}

.document-table-card td:nth-child(4) {
  text-align: left;
}

.document-table-card td:nth-child(4) .button,
.document-table-card td:nth-child(4) .status-pill {
  width: 100%;
  max-width: 280px;
  min-height: 64px;
  padding: 0.95rem 1.35rem;
  border-radius: var(--radius-md);
  white-space: nowrap;
}

.document-action-label-mobile {
  display: none;
}

/* Give document action buttons one consistent desktop column */
@media (min-width: 769px) {
  .document-table-card table {
    table-layout: fixed;
  }

  .document-table-card th:nth-child(1),
  .document-table-card td:nth-child(1) {
    width: 31%;
  }

  .document-table-card th:nth-child(2),
  .document-table-card td:nth-child(2) {
    width: 18%;
  }

  .document-table-card th:nth-child(3),
  .document-table-card td:nth-child(3) {
    width: 18%;
  }

  .document-table-card th:nth-child(4),
  .document-table-card td:nth-child(4) {
    width: 33%;
  }
}

/* Document mobile cards use document labels, not invoice labels */
@media (max-width: 768px) {
  .document-table-card td:nth-of-type(1)::before { content: "Document"; }
  .document-table-card td:nth-of-type(2)::before { content: "Type"; }
  .document-table-card td:nth-of-type(3)::before { content: "Added"; }
  .document-table-card td:nth-of-type(4)::before { content: "Action"; }

  .document-table-card tbody tr td {
    gap: 1rem;
  }

  .document-table-card td:nth-child(4) {
    align-items: center;
  }

  .document-table-card td:nth-child(4) .button,
  .document-table-card td:nth-child(4) .status-pill {
    width: auto;
    min-width: 150px;
    max-width: 190px;
    min-height: 52px;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(0, 159, 218, 0.22);
    transform: none;
  }

  .document-table-card td:nth-child(4) .button:hover {
    transform: translateY(-1px);
  }

  .document-action-label-full {
    display: none;
  }

  .document-action-label-mobile {
    display: inline;
  }
}

@media (max-width: 420px) {
  .document-table-card tbody tr td {
    padding: 0.65rem 1.1rem;
  }

  .document-table-card td:nth-child(4) .button,
  .document-table-card td:nth-child(4) .status-pill {
    min-width: 132px;
    max-width: 160px;
    min-height: 48px;
    padding: 0.65rem 0.8rem;
    font-size: 0.88rem;
  }
}
