/* Define Design Tokens & System Variables */
:root {
  --primary-color: #10B981;      /* Emerald Mint Green */
  --primary-dark: #064E3B;       /* Deep Forest Green */
  --primary-light: #34D399;      /* Bright Green */
  --accent-color: #FBBF24;       /* Warm Gold */
  --accent-dark: #D97706;        /* Amber Gold */
  --bg-color: #F4FBF7;           /* Soft Green Tinted Background */
  --card-bg: #FFFFFF;
  --text-main: #0B251C;          /* Deep Forest Charcoal */
  --text-muted: #526E63;
  --border-color: #E1F2EA;
  --success-color: #059669;      /* Forest Green */
  --danger-color: #DC2626;       /* Crimson Red */
  --info-color: #2563EB;         /* Royal Blue */
  --warning-color: #D97706;      /* Amber Orange */
  
  --shadow-sm: 0 2px 4px rgba(6, 78, 59, 0.04);
  --shadow-md: 0 4px 12px rgba(6, 78, 59, 0.06);
  --shadow-lg: 0 8px 24 rgba(6, 78, 59, 0.09);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: all 0.3s ease;
}

/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', 'Inter', -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  font-size: 15px;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--primary-dark);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
  background: #C2BED0;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light);
}

/* App Container Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar Styling */
.sidebar {
  width: 280px;
  background: linear-gradient(180deg, var(--primary-dark) 0%, #20003B 100%);
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  box-shadow: 4px 0 15px rgba(0, 0, 0, 0.15);
  padding: 24px 16px;
}

.sidebar-header {
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 24px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background-color: #FFFFFF; /* Circular white emblem backing for dark sidebar */
  border-radius: 50%;
  padding: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.logo-text h2 {
  color: var(--accent-color);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

.logo-text p {
  color: #E2DFE9;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #E2DFE9;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: var(--transition);
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  transform: translateX(4px);
}

.nav-item.active {
  background: linear-gradient(90deg, var(--primary-light) 0%, var(--primary-color) 100%);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(155, 77, 202, 0.3);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  color: #AAA6B9;
  text-align: center;
}

.sidebar-footer .version {
  font-weight: 600;
  color: var(--accent-color);
  margin-bottom: 4px;
}

/* Main Content Area */
.main-content {
  margin-left: 280px;
  flex-grow: 1;
  padding: 32px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Top Bar Styling */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border-color);
}

.page-title-container h1 {
  font-size: 1.85rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--card-bg);
  padding: 8px 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.user-profile .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Views Management */
.content-view {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dashboard Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  margin-bottom: 8px;
}

.stat-card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(106, 13, 173, 0.05);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

/* Colors for stat card icons */
.stat-icon.purple { background-color: #F3E5F5; color: var(--primary-color); }
.stat-icon.blue { background-color: #E3F2FD; color: var(--info-color); }
.stat-icon.yellow { background-color: #FFFDE7; color: #F57F17; }
.stat-icon.green { background-color: #E8F5E9; color: var(--success-color); }

.stat-content h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.2;
}

.stat-trend {
  font-size: 0.75rem;
}

.text-muted { color: var(--text-muted); }

/* Dashboard Charts Grid */
.dashboard-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 32px;
}

.span-2 {
  grid-column: span 2;
}

.details-card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  background-color: #FAF9FC;
}

.card-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.card-body {
  padding: 24px;
}

/* Custom CSS Bar Charts */
.custom-bar-chart {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-bar-item {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
}

.chart-bar-label {
  width: 180px;
  font-weight: 500;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.chart-bar-track {
  flex-grow: 1;
  height: 12px;
  background-color: #ECEAF0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.chart-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-light) 0%, var(--primary-color) 100%);
  border-radius: 6px;
  width: 0;
  transition: width 1s cubic-bezier(0.1, 0.8, 0.3, 1);
}

.chart-bar-value {
  width: 50px;
  text-align: right;
  font-weight: 700;
  color: var(--primary-dark);
}

/* Age & Medical Charts Grid */
.stat-extra-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.stat-sub-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-muted);
  border-left: 3px solid var(--primary-color);
  padding-left: 8px;
}

/* Records Directory - Actions */
.action-row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.search-box {
  position: relative;
  width: 320px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  fill: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 12px 16px 12px 46px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--card-bg);
  color: var(--text-main);
  font-size: 0.9rem;
  transition: var(--transition);
  font-family: 'Sarabun', sans-serif;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(155, 77, 202, 0.15);
}

.filter-group {
  display: flex;
  gap: 12px;
}

.filter-group select {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--card-bg);
  font-size: 0.9rem;
  font-family: 'Sarabun', sans-serif;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.filter-group select:focus {
  border-color: var(--primary-light);
}

.export-group {
  display: flex;
  gap: 12px;
}

/* Button UI Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: 'Sarabun', sans-serif;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-color) 100%);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(106, 13, 173, 0.2);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(106, 13, 173, 0.3);
}

.btn-secondary {
  background-color: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background-color: #FAF9FC;
  border-color: var(--primary-light);
}

.btn-success {
  background-color: var(--success-color);
  color: #FFFFFF;
}
.btn-success:hover {
  background-color: #256428;
  transform: translateY(-2px);
}

.btn-danger {
  background-color: var(--danger-color);
  color: #FFFFFF;
}
.btn-danger:hover {
  background-color: #A81C1C;
}

.btn-gps, .btn-cam {
  border: 1px dashed var(--primary-color);
  background-color: #FAF5FF;
  color: var(--primary-color);
}
.btn-gps:hover, .btn-cam:hover {
  background-color: #F3E8FF;
}

/* Records Directory - Main Layouts */
.records-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.view-toggle-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.results-count {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.toggle-buttons {
  display: flex;
  background-color: #ECEAF0;
  padding: 4px;
  border-radius: var(--radius-sm);
  gap: 4px;
}

.btn-toggle {
  border: none;
  background: none;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Sarabun', sans-serif;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition);
}

.btn-toggle.active {
  background-color: var(--card-bg);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

/* Grid View styling */
.records-grid-view {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.records-grid-view.active {
  display: grid;
}

.profile-card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  cursor: pointer;
}

.profile-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.card-img-container {
  height: 200px;
  width: 100%;
  background-color: #ECEAF0;
  position: relative;
  overflow: hidden;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition);
}

.profile-card:hover .card-img {
  transform: scale(1.05);
}

.image-counter-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: rgba(0,0,0,0.6);
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 12px;
}

.card-badge {
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #FFFFFF;
}

.card-badge.male { background-color: var(--info-color); }
.card-badge.female { background-color: var(--primary-light); }
.card-badge.other { background-color: var(--warning-color); }

.card-info {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.card-info h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.card-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-info-row svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.card-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #FAF9FC;
}

.card-doc-no {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.card-btn-view {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-color);
  background: none;
  border: none;
  cursor: pointer;
}

/* Table View styling */
.records-table-view {
  display: none;
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.records-table-view.active {
  display: block;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.records-table th {
  background-color: #FAF9FC;
  padding: 16px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.9rem;
  border-bottom: 2px solid var(--border-color);
}

.records-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.88rem;
  vertical-align: middle;
}

.records-table tbody tr:hover {
  background-color: #FAF6FD;
}

.table-img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background-color: #ECEAF0;
}

.table-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.table-badge.normal { background-color: #E8F5E9; color: var(--success-color); }
.table-badge.warning { background-color: #FFF3E0; color: var(--warning-color); }
.table-badge.danger { background-color: #FFEBEE; color: var(--danger-color); }

.table-actions {
  display: flex;
  gap: 8px;
}

.table-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: var(--transition);
}

.table-btn:hover {
  background-color: #ECEAF0;
}
.table-btn.view:hover { color: var(--info-color); }
.table-btn.edit:hover { color: var(--warning-color); }
.table-btn.delete:hover { color: var(--danger-color); }

.table-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Form Wizard Container */
.form-wizard-container {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.form-steps {
  display: flex;
  background-color: #FAF9FC;
  border-bottom: 1px solid var(--border-color);
}

.step-indicator {
  flex-grow: 1;
  text-align: center;
  padding: 16px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

.step-indicator.active {
  color: var(--primary-color);
  border-color: var(--primary-color);
  background-color: #FFFFFF;
}

.step-indicator.completed {
  color: var(--success-color);
}

.record-form {
  padding: 32px;
}

.form-step-panel {
  display: none;
  padding: 32px;
  animation: fadeIn 0.3s ease;
}

.form-step-panel.active {
  display: block;
}

.form-section-card {
  background-color: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}

.form-section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--bg-color);
}

.section-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: -16px;
  margin-bottom: 20px;
}

/* Responsive Form Rows */
.form-row {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
}

.form-row.col-1 { grid-template-columns: 1fr; }
.form-row.col-2 { grid-template-columns: 1fr 1fr; }
.form-row.col-3 { grid-template-columns: repeat(3, 1fr); }
.form-row.col-4 { grid-template-columns: repeat(4, 1fr); }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--primary-dark);
}

.form-group label .required {
  color: var(--danger-color);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.9rem;
  outline: none;
  background-color: #FFFFFF;
  color: var(--text-main);
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(155, 77, 202, 0.1);
}

/* Custom Checkbox and Radio designs */
.radio-group-container {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.radio-flex {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.radio-label, .checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 8px 0;
}

.inline-text-input {
  max-width: 160px;
  padding: 4px 8px !important;
  border-radius: 4px !important;
}

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }

/* Media Upload and Camera styles */
.media-controls-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.upload-buttons {
  display: flex;
  gap: 12px;
}

.camera-stream-wrapper {
  max-width: 400px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--border-color);
  background-color: #000;
  position: relative;
  display: flex;
  flex-direction: column;
}

#camera-stream {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.camera-stream-wrapper .btn {
  margin: 12px;
  align-self: center;
}

/* Photo Preview Slots (Max 4) */
.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-top: 8px;
}

.photo-slot {
  aspect-ratio: 1/1;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-color);
  background-color: #FAF9FC;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(198, 40, 40, 0.9);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  transition: var(--transition);
}

.photo-delete-btn:hover {
  background-color: var(--danger-color);
  transform: scale(1.1);
}

/* GPS Section styles */
.gps-capture-container {
  background-color: #F8F9FA;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
}

.subsection-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary-dark);
}

.gps-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.gps-values {
  display: flex;
  gap: 16px;
  font-size: 0.9rem;
}

.gps-values strong {
  color: var(--primary-color);
}

.gps-tip {
  font-size: 0.75rem;
  margin-top: 8px;
}

/* Form Actions Footer */
.form-footer-actions {
  display: flex;
  justify-content: flex-end;
  padding: 24px 32px;
  background-color: #FAF9FC;
  border-top: 1px solid var(--border-color);
  gap: 12px;
}

/* Profile Detail Display View */
.profile-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.profile-actions-bar .right-buttons {
  display: flex;
  gap: 12px;
}

.profile-card-display {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 32px;
}

.profile-header-layout {
  display: flex;
  gap: 32px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 24px;
  margin-bottom: 24px;
}

.profile-header-photos {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.profile-main-photo-wrapper {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #ECEAF0;
  border: 1px solid var(--border-color);
}

.profile-main-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-thumbnails-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.profile-thumb-slot {
  aspect-ratio: 1/1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background-color: #ECEAF0;
}

.profile-thumb-slot.active {
  border-color: var(--primary-color);
}

.profile-thumb-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-header-details {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.profile-primary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.profile-primary-row h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.profile-meta-chips {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.profile-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background-color: #ECEAF0;
  color: var(--text-main);
}

.profile-chip.purple { background-color: #D1FAE5; color: var(--primary-color); }
.profile-chip.blue { background-color: #E3F2FD; color: var(--info-color); }
.profile-chip.orange { background-color: #FFF3E0; color: var(--warning-color); }
.profile-chip.red { background-color: #FFEBEE; color: var(--danger-color); }

.doc-info-block {
  background-color: #FAF9FC;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  font-size: 0.88rem;
}

.doc-info-item span {
  font-weight: 600;
  color: var(--text-muted);
}

.doc-info-item p {
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

/* Tabbed sections inside profile page */
.profile-sections-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.profile-section-block {
  background-color: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px 24px;
}

.profile-section-block.span-2 {
  grid-column: span 2;
}

.profile-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-color);
  border-bottom: 2px solid #D1FAE5;
  padding-bottom: 8px;
  margin-bottom: 16px;
}

.profile-data-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.profile-data-list.single-col {
  grid-template-columns: 1fr;
}

.profile-data-item {
  display: flex;
  flex-direction: column;
}

.profile-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.profile-value {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.assistance-needs-box {
  background-color: #FFFDE7;
  border: 1px solid #FFF59D;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
}

.assistance-needs-box ol {
  padding-left: 20px;
}

.assistance-needs-box li {
  font-weight: 700;
  color: #5D4037;
  margin-bottom: 8px;
}

.notes-box {
  background-color: #F8F9FA;
  border-left: 4px solid var(--primary-color);
  padding: 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-line;
  font-size: 0.9rem;
}

/* Print Stylesheet overrides */
.print-only {
  display: none;
}

@media print {
  body {
    background-color: #FFFFFF;
    color: #000000;
    font-size: 14px;
    font-family: 'Sarabun', serif;
  }
  
  .app-container, .profile-actions-bar {
    display: none !important;
  }
  
  .print-only {
    display: block !important;
    padding: 20px;
    background-color: #FFFFFF;
  }

  .print-form-title {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 24px;
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
  }

  .print-table td {
    border: 1px solid #000;
    padding: 8px 12px;
    vertical-align: top;
    font-size: 13px;
  }

  .print-header-grid {
    display: grid;
    grid-template-columns: 1fr 150px;
    gap: 16px;
    margin-bottom: 16px;
  }

  .print-photos-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 16px;
    margin-bottom: 16px;
  }

  .print-photo-box {
    aspect-ratio: 4/3;
    border: 1px solid #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .print-photo-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .print-section-header {
    background-color: #EFEFEF !important;
    font-weight: bold;
    font-size: 14px;
    border: 1px solid #000;
    padding: 6px 12px;
    margin-top: 16px;
    margin-bottom: 4px;
  }

  .print-row-field {
    margin-bottom: 6px;
    line-height: 1.4;
  }

  .print-underline {
    border-bottom: 1px dotted #000;
    padding-left: 8px;
    padding-right: 8px;
    display: inline-block;
    font-weight: bold;
  }

  .print-sign-grid {
    display: flex;
    justify-content: flex-end;
    margin-top: 40px;
    font-size: 13px;
  }

  .print-sign-box {
    text-align: center;
    width: 300px;
  }
}

/* Tablet Responsive styling */
@media (max-width: 1024px) {
  .sidebar {
    width: 76px;
    padding: 24px 8px;
  }
  .sidebar-header .logo-text,
  .sidebar-footer,
  .nav-item {
    font-size: 0;
  }
  .nav-item {
    justify-content: center;
    padding: 14px;
  }
  .nav-icon {
    width: 24px;
    height: 24px;
  }
  .main-content {
    margin-left: 76px;
    padding: 24px;
  }
  .dashboard-details-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
  .stat-extra-grid {
    grid-template-columns: 1fr;
  }
  .profile-sections-container {
    grid-template-columns: 1fr;
  }
  .profile-section-block.span-2 {
    grid-column: span 1;
  }
}

/* Phone Responsive styling */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  }
  .sidebar-header {
    border: none;
    margin: 0;
    padding: 0;
  }
  .nav-menu {
    flex-direction: row;
    gap: 4px;
  }
  .nav-item {
    padding: 8px 12px;
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .form-row.col-2, .form-row.col-3, .form-row.col-4 {
    grid-template-columns: 1fr;
  }
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-box {
    width: 100%;
  }
  .filter-group {
    flex-direction: column;
  }
  .export-group {
    flex-direction: column;
  }
  .photo-preview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .profile-header-layout {
    flex-direction: column;
  }
  .profile-header-photos {
    width: 100%;
  }
}

/* Dashboard Search Hero Card */
.dashboard-hero-card {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
  color: #FFFFFF;
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 8px;
  position: relative;
  overflow: visible;
}

.dashboard-hero-card h2 {
  color: var(--accent-color);
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.dashboard-hero-card p {
  color: #E2DFE9;
  font-size: 0.95rem;
}

.hero-search-wrapper {
  position: relative;
  width: 380px;
  flex-shrink: 0;
}

.dashboard-search {
  width: 100%;
}

.dashboard-search input {
  background-color: rgba(255, 255, 255, 0.15) !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  color: #FFFFFF !important;
  padding-right: 16px !important;
}

.dashboard-search input::placeholder {
  color: #C2BED0;
}

.dashboard-search input:focus {
  background-color: #FFFFFF !important;
  color: var(--text-main) !important;
  border-color: var(--accent-color) !important;
}

.dashboard-search:focus-within .search-icon {
  fill: var(--primary-color);
}

/* Search results dropdown */
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #FFFFFF;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #F0EDF5;
  transition: var(--transition);
  color: var(--text-main);
  text-decoration: none;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background-color: #ECFDF5;
}

.dropdown-thumb {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background-color: #ECEAF0;
}

.dropdown-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.dropdown-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary-dark);
}

.dropdown-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.dropdown-badge {
  background-color: #D1FAE5;
  color: var(--primary-color);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.dropdown-no-results {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Adjust layout on mobile */
@media (max-width: 768px) {
  .dashboard-hero-card {
    flex-direction: column;
    align-items: stretch;
    padding: 20px;
  }
  .hero-search-wrapper {
    width: 100%;
  }
}

/* Login Screen Styles */
.login-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at 30% 30%, #065F46 0%, #022C22 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.login-card {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(6, 78, 59, 0.25);
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-header {
  margin-bottom: 24px;
}

.login-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.login-header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 6px;
}

.login-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.login-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  margin-bottom: 24px;
}

.login-group label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary-dark);
}

.password-input-wrapper {
  position: relative;
  width: 100%;
}

.password-input-wrapper input {
  width: 100%;
  padding: 12px 48px 12px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-color);
  font-size: 1.1rem;
  letter-spacing: 0.3em;
  font-family: 'Inter', sans-serif;
  text-align: center;
  outline: none;
  transition: var(--transition);
}

.password-input-wrapper input::placeholder {
  letter-spacing: normal;
  font-size: 0.9rem;
  font-family: 'Sarabun', sans-serif;
  text-align: center;
}

.password-input-wrapper input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(106, 13, 173, 0.15);
}

.toggle-password {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.toggle-password svg {
  width: 20px;
  height: 20px;
  fill: var(--text-muted);
  transition: var(--transition);
}

.toggle-password:hover svg {
  fill: var(--primary-color);
}

.btn-login {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(106, 13, 173, 0.25);
}

.login-error {
  color: var(--danger-color);
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 4px;
}

/* Animations */
.animate-fade-in {
  animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Background Watermark styling */
.watermark-bg {
  position: fixed;
  top: 55%;
  left: 55%;
  transform: translate(-50%, -50%);
  width: 90vw;
  max-width: 1400px;
  opacity: 0.15; /* Same opacity */
  pointer-events: none; /* Click through */
  z-index: 0; /* Behind cards */
  display: flex;
  align-items: center;
  justify-content: center;
}

.watermark-bg img {
  width: 100%;
  height: auto;
  max-height: 95vh;
  object-fit: contain;
  mix-blend-mode: multiply; /* Make white background transparent */
}

/* Hide watermark when printing */
@media print {
  .watermark-bg {
    display: none !important;
  }
}

/* =============================================================
   Real-time Online Settings Panel Styles
   ============================================================= */
.settings-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 0 30px;
  position: relative;
  z-index: 1;
}

.settings-status-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.status-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-icon-wrapper {
  background: var(--bg-color);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}

.cloud-icon {
  width: 28px;
  height: 28px;
  fill: var(--primary-color);
}

.status-details h3 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 700;
}

.status-badge.offline {
  background-color: #F3F4F6;
  color: #6B7280;
  border: 1px solid #E5E7EB;
}

.status-badge.connected {
  background-color: #ECFDF5;
  color: #10B981;
  border: 1px solid #A7F3D0;
}

.status-badge.connecting {
  background-color: #EFF6FF;
  color: #3B82F6;
  border: 1px solid #BFDBFE;
}

.status-badge.error {
  background-color: #FEF2F2;
  color: #EF4444;
  border: 1px solid #FCA5A5;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-badge.connecting .status-dot {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
}

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

.settings-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.settings-card-header {
  padding: 16px 20px;
  background-color: #FAFDFB;
  border-bottom: 1px solid var(--border-color);
}

.settings-card-header h2 {
  font-size: 1.05rem;
  color: var(--primary-dark);
  font-weight: 700;
  margin: 0;
}

.settings-card-body {
  padding: 20px;
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #D1D5DB;
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

.slider.round {
  border-radius: 24px;
}

.slider.round:before {
  border-radius: 50%;
}

.sync-action-box {
  transition: var(--transition);
}

.sync-action-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

/* Custom indicator for online mode in navigation */
.online-indicator-nav {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10B981;
  margin-left: 6px;
  box-shadow: 0 0 8px #10B981;
}

