/* ==========================================================================
   1. GLOBAL BASE STYLES
   ========================================================================== */
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background-color: #f7fafc;
  color: #2d3748;
  margin: 0;
  padding: 0;
}

.container {
  max-width: 95%;
  margin: 0 auto;
  padding: 0 20px;
  margin-bottom: 20px;
}

.card {
  max-width: 100%;
  margin: 0 auto;
  background: white;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.action-button {
    display: inline-flex;
    align-items: center;
    padding: 10px 18px;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: transform 0.1s ease;
    border: none;
    cursor: pointer;
}

.action-button:active {
    transform: scale(0.98);
}

.btn-blue { background-color: #2b6cb0; }
.btn-blue:hover { background-color: #2b4c7e; }
.btn-green { background-color: #38a169; }
.btn-green:hover { background-color: #276749; }
.btn-orange { background-color: #dd6b20; }
.btn-orange:hover { background-color: #c05621; }
.btn-red { background-color: #e53e3e; }
.btn-red:hover { background-color: #9b2c2c; }
.btn-purple { background-color: #805ad5; }
.btn-purple:hover { background-color: #553c9a; }

.btn-save {
    background: #38a169;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
}

/* Login Page Specific Styles */
.login-container {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    margin: 100px auto; /* Centers it vertically/horizontally */
}

.login-container h2 { 
    margin-top: 0; 
    margin-bottom: 1.5rem; 
    text-align: center; 
    color: #2b6cb0; 
}

.error-banner {
    background-color: #fed7d7;
    color: #9b2c2c;
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    border: 1px solid rgba(0,0,0,0.05);
}

.btn-submit {
    width: 100%;
    padding: 0.75rem;
    background-color: #2b6cb0;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}
.btn-submit:hover { background-color: #1a4975; }

.form-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column; /* This ensures the label is on top and input is below */
}

.form-group label {
    margin-bottom: 5px;     /* Adds a little space between label and input */
    font-weight: 600;
    color: #4a5568;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;            /* Forces input to fill the container width */
    padding: 0.75rem;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    box-sizing: border-box; /* Ensures padding doesn't push the width beyond 100% */
}

/* ==========================================================================
   2. HEADER & LAYOUT
   ========================================================================== */
header {
  background-color: #2b6cb0;
  color: white;
  padding: 15px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
}

header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

/* --- Footer Styling --- */
.site-footer {
  background-color: #2b6cb0; /* Matches header */
  color: white;
  padding: 20px 0;
  margin-top: 40px;
  text-align: center;
  font-size: 0.85rem;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
  width: 100%;
}

.site-footer p {
  margin: 0;
  opacity: 0.9;
}

/* ==========================================================================
   3. HAMBURGER MENU & NAV LOGIC
   ========================================================================== */
#menu-toggle {
  display: none;
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 24px;
  height: 24px;
  cursor: pointer;
  z-index: 1000;
}

.hamburger-btn span {
  width: 24px;
  height: 3px;
  background-color: white;
  border-radius: 2px;
}

/* Dropdown Menu Container */
.nav-menu {
  display: none;
  position: absolute;
  top: 60px;
  right: 15px;
  width: 250px;
  background: white;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  border-radius: 8px;
  overflow: hidden;
}

/* Toggle Interaction */
#menu-toggle:checked ~ .nav-menu {
  display: block;
}

/* Menu Link Styles */
.nav-menu a {
  display: block;
  padding: 15px 20px;
  color: #2d3748;
  text-decoration: none;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.95rem;
}

.nav-menu a:hover {
  background-color: #f7fafc;
  color: #2b6cb0;
}

/* ==========================================================================
   4. UI UTILITIES & FORM ELEMENTS
   ========================================================================== */
.nav-logout {
  color: #e53e3e !important;
  font-weight: bold;
}

.home-selector-bar {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 0;
  margin-bottom: 25px;
}

select {
  background-color: #ffffff !important; /* Force white background */
  color: #2d3748 !important; /* Dark text for readability */
  padding: 6px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  cursor: pointer;
}

/* Style the individual options */
select option {
  background-color: #ffffff;
  color: #2d3748;
}

/* ==========================================================================
   5. RESPONSIVE ADJUSTMENTS
   ========================================================================== */
@media (max-width: 600px) {
  .container {
    max-width: 95%;
  }
}

/* ==========================================================================
   6. DASHBOARD COMPONENTS
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.tile {
  background: white;
  padding: 25px 15px;
  border-radius: 12px;
  text-decoration: none;
  color: #2d3748;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}

.tile:hover {
  background: #f7fafc;
  transform: translateY(-3px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

.tile span {
  font-size: 1.8rem;
  display: block;
  margin-bottom: 10px;
}
.tile h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

/* Tile Variations */
.tile-alert {
  border: 2px solid #e53e3e;
  color: #e53e3e;
}
.admin-tile {
  border: 1px dashed #2b6cb0;
}

/* ==========================================================================
   7. RESIDENTS/STAFF COMPONENTS
   ========================================================================== */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.room-card {
  text-align: left; /* Override the center-align of standard tiles */
  display: flex;
  flex-direction: column;
}

.room-meta {
  margin: 5px 0;
  font-size: 0.9rem;
}

.room-badge {
  background: #ebf8ff;
  color: #2b6cb0;
  border: 1px solid #bee3f8;
  padding: 10px 20px;
  border-radius: 6px;
  text-align: center;
  font-weight: bold;
  width: 350px;
}

.card-divider {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 10px 0;
}
.resident-link {
  display: block;
  font-weight: bold;
  color: #2b6cb0;
  text-decoration: none;
  margin-top: 10px;
}

/* Status Indicators */
.status-occupied {
  border-left: 5px solid #38a169;
}
.status-vacant {
  border-left: 5px solid #a0aec0;
}

.dnacpr-alert {
  background: #fff5f5;
  color: #c53030;
  font-size: 0.75rem;
  padding: 5px;
  margin-top: 8px;
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
}

.flag-title {
  color: #c53030;
  font-weight: bold;
  font-size: 1.1rem;
  margin: 0 0 5px 0;
  display: flex;
  align-items: center;
}

.empty-room {
  color: #a0aec0;
  font-style: italic;
  font-size: 0.85rem;
}

.profile-header {
  background: white;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 20px;
}

.profile-title h1 {
  margin: 0 0 5px 0;
  font-size: 2rem;
  color: #1a202c;
}

.meta-badge {
  background: #edf2f7;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: #4a5568;
  margin-right: 8px;
  display: inline-block;
}

/* Risk Score Badges */
.risk-badge {
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 12px;
  display: inline-block;
}

.risk-low {
  background: #c6f6d5;
  color: #22543d;
}

.risk-med {
  background: #feebc8;
  color: #744210;
}

.risk-high {
  background: #fed7d7;
  color: #9b2c2c;
}

.tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 20px;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 5px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scrollbar-width: none; /* Firefox: hides scrollbar */
  mask-image: linear-gradient(to right, black 95%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 95%, transparent 100%);
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
  flex: 0 0 auto;
  padding: 8px 16px;
  cursor: pointer;
  background: #edf2f7;
  border: none;
  font-weight: bold;
  color: #4a5568;
  border-radius: 4px;
}

.tab-btn.active {
  background: #2b6cb0;
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Accordion Container */
.accordion-item {
    margin-bottom: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
}

.accordion-header {
    width: 100%;
    padding: 15px;
    text-align: left;
    background: #f7fafc;
    border: none;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Status Colors */
.plan-card.urgent .accordion-header { background: #fed7d7; color: #822727; }
.plan-card.soon .accordion-header { background: #fefcbf; color: #744210; }

.review-label {
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

.accordion-content {
    padding: 15px;
    display: none;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

/* Styled Button */
.btn-add {
    background: #4a5568;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}
.btn-add:hover { background: #2d3748; }

/* Base styles for the table */
.data-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.data-table th, .data-table td { padding: 12px; border-bottom: 1px solid #ddd; text-align: left; }

.prn-container {
        background: #f7fafc;
        border: 2px solid #e2e8f0;
        border-radius: 8px;
        padding: 15px;
        transition: all 0.2s ease;
    }

    .prn-toggle-label {
        display: flex;
        align-items: center;
        gap: 12px;
        cursor: pointer;
        font-size: 16px;
    }

    .prn-toggle-label input {
        width: 20px;
        height: 20px;
        cursor: pointer;
    }

    .prn-text {
        color: #4a5568;
    }

    /* Highlight the box when checked */
    .prn-container:has(input:checked) {
        border-color: #3182ce;
        background: #ebf8ff;
    }

/* The Mobile Transformation */

@media (max-width: 768px) {
    /* --- TABLE MODIFICATIONS --- */
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td {
        display: block;
        width: 100%; /* Changed to 100% for better fit */
        box-sizing: border-box;
    }
    .data-table tr { 
        margin-bottom: 15px; 
        border: 1px solid #ccc; 
        border-radius: 8px; 
        padding: 10px; 
        background: #f9f9f9; 
    }
    .data-table td { 
        display: flex; 
        justify-content: space-between; 
        padding: 6px 0; 
        border-bottom: none;
    }
    .data-table td::before { 
        content: attr(data-label); 
        font-weight: bold; 
        color: #555; 
    }

    /* --- PROFILE HEADER MODIFICATIONS --- */
    .profile-header {
        flex-direction: column;
        flex-wrap: wrap;
    }
    .room-badge {
        width: 100%;
        margin-top: 15px;
        box-sizing: border-box;
    }
    .meta-badge {
        margin-bottom: 8px;
        display: inline-block; /* Ensures they respect the margin */
    }
    
    /* --- GENERAL LAYOUT MODIFICATIONS --- */
    .card-row, .card-container { 
        flex-direction: column;
    }
    .profile-header .action-button {
        margin-top: 10px;
        width: 100%;
        justify-content: center;
        box-sizing: border-box;
    }
    .tab-btn {
        padding: 12px 20px; /* Increase vertical padding for easier tapping */
        font-size: 15px;    /* Slightly larger text for readability */
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 75%; /* Or your preferred fixed width */
    }
}

/* ==========================================================================
   8. EMAR COMPONENTS
   ========================================================================== */

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.round-btn { flex: 1; min-width: 100px; padding: 12px; background: #e2e8f0; text-align: center; text-decoration: none; border-radius: 6px; font-weight: bold; color: #4a5568; }
.round-btn.active { background: #3182ce; color: white; }

/* Resident Cards */
.resident-card { background: white; margin-bottom: 15px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); overflow: hidden; }
.resident-header { background: #edf2f7; padding: 15px; border-bottom: 1px solid #e2e8f0; font-weight: bold; }

/* Medication Rows - The Unified Definition */
.med-row { 
    padding: 15px; 
    border-bottom: 1px solid #f7fafc; 
    display: flex; 
    flex-direction: column; /* Mobile first: stacked */
    gap: 10px; 
    min-height: 70px;
}

/* Desktop View: Horizontal layout for meds */
@media (min-width: 768px) {
    .med-row { 
        flex-direction: row; 
        align-items: center; 
        justify-content: space-between; 
    }
}

/* Row Coloring */
.row-given { background-color: #f0fff4 !important; }
.row-exception { background-color: #fff5f5 !important; }

/* Status Badge & Form Styling */
.status-badge { padding: 8px 12px; border-radius: 6px; font-size: 0.85em; text-align: right; }
.med-row form { display: flex; gap: 10px; align-items: center; }
.med-row select, .med-row input { padding: 8px; border: 1px solid #cbd5e0; border-radius: 6px; }

    /* ==========================================================================
   9. MED STOCK COMPONENTS
   ========================================================================== */

/* Table Styling */
    .stock-card { background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); overflow: hidden; margin-top: 20px; }
    .stock-table { width: 100%; border-collapse: collapse; }
    .stock-table th, .stock-table td { padding: 12px 15px; border-bottom: 1px solid #edf2f7; text-align: left; }
    .stock-table th { background: #f7fafc; font-size: 13px; color: #4a5568; }
    
    /* Badges */
    .stock-badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: bold; }
    .stock-critical { background: #fff5f5; color: #c53030; border: 1px solid #feb2b2; }
    .stock-healthy { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
    
    /* Manifest Panel */
    .manifest-panel { background: #f7fafc; padding: 20px; border-radius: 8px; margin-top: 20px; border: 1px solid #e2e8f0; }
    .manifest-box { width: 100%; height: 150px; margin-top: 10px; padding: 10px; border: 1px solid #cbd5e0; border-radius: 4px; font-family: monospace; }
    
    /* Responsive Table: Mobile Stack */
    @media (max-width: 768px) {
        .stock-table thead { display: none; }
        .stock-table tr { display: block; padding: 15px; border-bottom: 2px solid #edf2f7; }
        .stock-table td { display: block; text-align: right; border-bottom: none; padding: 5px 0; }
        .stock-table td::before { content: attr(data-label); float: left; font-weight: bold; color: #718096; }
    }
