/* ============================================================
   e-Voting System - CSS
   ============================================================ */

:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;
  --dark: #1F2937;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  --white: #FFFFFF;
  --sidebar-width: 260px;
  --sidebar-collapsed: 70px;
  --topbar-height: 64px;
  --border-radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Bai Jamjuree', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
}

/* ============================================================
   Loading Screen
   ============================================================ */
.loading-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.loading-content {
  text-align: center;
  color: white;
}

.loading-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: pulse 2s infinite;
}

.loading-content h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.loading-content p {
  opacity: 0.8;
  font-size: 14px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top: 3px solid white;
  border-radius: 50%;
  margin: 24px auto 0;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* ============================================================
   Login Page
   ============================================================ */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  font-size: 56px;
  margin-bottom: 12px;
}

.login-header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

.login-header p {
  color: var(--gray-500);
  font-size: 14px;
  margin-top: 8px;
  line-height: 1.5;
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.login-form label i {
  margin-right: 6px;
  color: var(--gray-400);
}

.login-form input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}

.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.login-divider {
  text-align: center;
  margin: 20px 0;
  position: relative;
}

.login-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--gray-200);
}

.login-divider span {
  background: white;
  padding: 0 16px;
  position: relative;
  color: var(--gray-400);
  font-size: 13px;
}

.login-footer {
  margin-top: 24px;
  text-align: center;
}

.compliance-badges {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-etda { background: #EEF2FF; color: var(--primary); }
.badge-land { background: #FEF3C7; color: #92400E; }
.badge-pdpa { background: #D1FAE5; color: #065F46; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 2px solid transparent;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-outline {
  background: transparent;
  border-color: var(--gray-300);
  color: var(--gray-600);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(79, 70, 229, 0.05);
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--gray-500);
  border-radius: 8px;
  transition: var(--transition);
}
.btn-icon:hover { background: var(--gray-100); color: var(--primary); }

.mt-2 { margin-top: 12px; }

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--gray-100);
}

.sidebar-logo { font-size: 32px; }

.sidebar-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-menu {
  list-style: none;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

.menu-item {
  margin-bottom: 2px;
}

.menu-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--gray-600);
  text-decoration: none;
  border-radius: 10px;
  transition: var(--transition);
  font-weight: 500;
  font-size: 14px;
}

.menu-item a:hover {
  background: var(--gray-100);
  color: var(--primary);
}

.menu-item.active a {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.menu-item a i {
  width: 20px;
  text-align: center;
  font-size: 16px;
}

.menu-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 12px 16px;
}

.menu-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-400);
  padding: 16px 16px 6px;
  list-style: none;
  user-select: none;
}

.menu-group-label:first-child {
  padding-top: 8px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--gray-100);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  font-size: 11px;
  color: var(--gray-400);
}

/* ============================================================
   Main App Layout
   ============================================================ */
#main-app {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ============================================================
   Main Content
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  flex: 1;
  width: calc(100% - var(--sidebar-width));
  transition: var(--transition);
  overflow-x: hidden;
}

.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { flex: 1; }
.topbar-title h1 { font-size: 20px; font-weight: 600; }

.sidebar-toggle { display: none; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notification-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--danger);
  color: white;
  font-size: 10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#notifications-btn { position: relative; }

.page-content {
  padding: 24px;
}

.page-actions {
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

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

/* ============================================================
   Stats Grid
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

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

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-blue .stat-icon { background: #EEF2FF; color: var(--primary); }
.stat-green .stat-icon { background: #D1FAE5; color: var(--success); }
.stat-orange .stat-icon { background: #FEF3C7; color: var(--warning); }
.stat-purple .stat-icon { background: #EDE9FE; color: #7C3AED; }

.stat-info h3 {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

.stat-info p {
  font-size: 13px;
  color: var(--gray-500);
}

/* ============================================================
   Content Grid
   ============================================================ */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

/* ============================================================
   Compliance Grid
   ============================================================ */
.compliance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.compliance-item {
  padding: 20px;
  border-radius: 10px;
  border: 2px solid var(--gray-200);
}

.compliance-ok {
  border-color: var(--success);
  background: #F0FDF4;
}

.compliance-item i {
  font-size: 24px;
  color: var(--success);
  margin-bottom: 8px;
}

.compliance-item h4 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.compliance-item p {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 12px;
}

.compliance-item ul {
  list-style: none;
  font-size: 13px;
}

.compliance-item li {
  padding: 3px 0;
}

/* ============================================================
   Meeting Items
   ============================================================ */
.meeting-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: var(--transition);
  cursor: pointer;
}

.meeting-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.meeting-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--gray-100);
}

.meeting-info { flex: 1; }
.meeting-info h4 { font-size: 15px; font-weight: 600; }
.meeting-info p { font-size: 13px; color: var(--gray-500); }

.meeting-status {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-draft { background: var(--gray-100); color: var(--gray-600); }
.status-published { background: #DBEAFE; color: #1D4ED8; }
.status-registration { background: #FEF3C7; color: #92400E; }
.status-in_progress { background: #D1FAE5; color: #065F46; }
.status-voting { background: #FEE2E2; color: #991B1B; }
.status-completed { background: #E0E7FF; color: #3730A3; }
.status-cancelled { background: var(--gray-200); color: var(--gray-500); }

/* ============================================================
   Voting UI
   ============================================================ */
.vote-option {
  display: block;
  padding: 14px 20px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 15px;
}

.vote-option:hover {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.03);
}

.vote-option.selected {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.08);
  font-weight: 600;
}

.vote-option input { margin-right: 12px; }

.vote-result-bar {
  margin-bottom: 12px;
}

.vote-result-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 14px;
}

.vote-result-track {
  height: 24px;
  background: var(--gray-100);
  border-radius: 12px;
  overflow: hidden;
}

.vote-result-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.8s ease;
  display: flex;
  align-items: center;
  padding-left: 12px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  min-width: fit-content;
}

.fill-agree { background: var(--success); }
.fill-disagree { background: var(--danger); }
.fill-abstain { background: var(--gray-400); }

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 14px;
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-lg { max-width: 700px; }

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
}

.modal-header h2 {
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================================
   PDPA
   ============================================================ */
.pdpa-notice {
  background: #FFF7ED;
  border: 1px solid #FED7AA;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.pdpa-notice h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: #92400E;
}

.pdpa-notice p, .pdpa-notice ul {
  font-size: 13px;
  color: var(--gray-600);
}

.pdpa-notice ul {
  list-style: disc;
  padding-left: 20px;
  margin: 8px 0;
}

.consent-checkboxes {
  padding: 12px 0;
}

.consent-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.consent-item:hover { background: var(--gray-50); }

.consent-item input { margin-top: 3px; }

.consent-item .required { color: var(--danger); }

/* ============================================================
   Form Elements
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
  background: white;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
}

/* ============================================================
   Enhanced Form Sections
   ============================================================ */
.form-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title i {
  color: var(--primary);
}

#project-form-card .card-body {
  background: linear-gradient(180deg, #FAFBFF 0%, white 100%);
}

#project-form-card .content-grid > div {
  background: white;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--gray-100);
}

small.text-muted {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--gray-400);
}

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 14px 20px;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 400px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.text-muted { color: var(--gray-500); }
.text-center { text-align: center; }

/* ============================================================
   QR Code & Scanner Styles
   ============================================================ */
.qr-camera-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 1;
}

.qr-camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-scan-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-scan-frame {
  width: 220px;
  height: 220px;
  border: 3px solid var(--success);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
  animation: qr-scan-pulse 2s infinite;
}

@keyframes qr-scan-pulse {
  0%, 100% { border-color: var(--success); box-shadow: 0 0 0 9999px rgba(0,0,0,0.4), 0 0 20px rgba(16,185,129,0.3); }
  50% { border-color: #34D399; box-shadow: 0 0 0 9999px rgba(0,0,0,0.4), 0 0 30px rgba(16,185,129,0.5); }
}

.scanner-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
}

.scanner-waiting {
  background: #FEF3C7;
  color: #92400E;
}

.scanner-success {
  background: #D1FAE5;
  color: #065F46;
}

.scanner-error {
  background: #FEE2E2;
  color: #991B1B;
}

/* QR Code Cards */
.qr-ballot-card {
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  page-break-inside: avoid;
  background: white;
}

.qr-ballot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px dashed var(--gray-200);
}

.qr-ballot-header h4 {
  font-size: 16px;
  font-weight: 700;
}

.qr-ballot-unit {
  font-size: 14px;
  color: var(--gray-600);
}

.qr-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.qr-option-item {
  text-align: center;
  padding: 12px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  transition: var(--transition);
}

.qr-option-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.qr-option-item .qr-image {
  margin: 8px auto;
}

.qr-option-item .qr-label {
  font-size: 13px;
  font-weight: 600;
  margin-top: 8px;
  color: var(--gray-700);
}

.qr-option-agree { border-color: var(--success); background: #F0FDF4; }
.qr-option-disagree { border-color: var(--danger); background: #FEF2F2; }
.qr-option-abstain { border-color: var(--gray-400); background: #F9FAFB; }
.qr-option-no-vote { border-color: var(--warning); background: #FFFBEB; }

/* Voting action bar with QR buttons */
.vote-action-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}

/* Print styles for QR codes */
@media print {
  .qr-ballot-card {
    border: 1px solid #333;
    margin-bottom: 20px;
    padding: 16px;
  }
  
  .qr-options-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
  }
  
  .qr-option-item {
    border: 1px solid #666;
    padding: 8px;
  }
}

/* ============================================================
   Responsive - Desktop (> 1024px) default styles above
   ============================================================ */

/* Tablet Landscape (769px - 1024px) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px;
  }

  .sidebar-header h2 {
    font-size: 17px;
  }

  .menu-item a {
    padding: 9px 12px;
    font-size: 13px;
  }

  .menu-group-label {
    padding: 12px 12px 4px;
    font-size: 9px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-info h3 {
    font-size: 24px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

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

  .page-content {
    padding: 16px;
  }

  .card-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-body {
    padding: 16px;
  }
}

/* Tablet Portrait & Small Tablets (481px - 768px) */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
    --topbar-height: 56px;
  }

  /* Sidebar becomes off-canvas overlay */
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  /* Sidebar overlay backdrop */
  .sidebar.open::after {
    content: '';
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: -1;
  }

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

  .sidebar-toggle {
    display: block;
  }

  .topbar {
    padding: 0 16px;
  }

  .topbar-title h1 {
    font-size: 17px;
  }

  .page-content {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
    gap: 10px;
  }

  .stat-icon {
    width: 42px;
    height: 42px;
    font-size: 18px;
    border-radius: 10px;
  }

  .stat-info h3 {
    font-size: 22px;
  }

  .stat-info p {
    font-size: 12px;
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .compliance-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .compliance-item {
    padding: 16px;
  }

  /* Meeting items stack better */
  .meeting-item {
    padding: 12px;
    gap: 12px;
  }

  .meeting-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
    border-radius: 10px;
  }

  .meeting-info h4 {
    font-size: 14px;
  }

  .meeting-info p {
    font-size: 12px;
  }

  /* Cards */
  .card {
    border-radius: 10px;
    margin-bottom: 12px;
  }

  .card-header {
    padding: 12px 14px;
  }

  .card-header h3 {
    font-size: 14px;
  }

  .card-body {
    padding: 14px;
  }

  /* Forms */
  .form-control, .form-select {
    padding: 10px 12px;
    font-size: 14px;
  }

  /* Buttons touch-friendly */
  .btn {
    padding: 12px 20px;
    font-size: 14px;
    min-height: 44px;
  }

  .btn-sm {
    padding: 8px 14px;
    min-height: 36px;
  }

  /* Vote options touch-friendly */
  .vote-option {
    padding: 16px 20px;
    font-size: 15px;
    min-height: 50px;
  }

  /* Modal */
  .modal-content {
    max-width: 100%;
    margin: 10px;
    border-radius: 16px;
  }

  .modal-lg {
    max-width: 100%;
  }

  /* Login */
  .login-card {
    padding: 30px 24px;
    border-radius: 16px;
  }

  .login-logo {
    font-size: 48px;
  }

  .login-header h1 {
    font-size: 24px;
  }

  /* Page actions */
  .page-actions {
    margin-bottom: 12px;
  }

  .page-actions .btn {
    flex: 1;
    min-width: 0;
  }

  /* Empty states */
  .empty-state {
    padding: 30px 20px;
  }

  .empty-state i {
    font-size: 40px;
    margin-bottom: 12px;
  }

  /* User info in sidebar */
  .sidebar-footer {
    padding: 12px;
  }

  .user-name {
    font-size: 12px;
  }
}

/* Smartphone (≤480px) */
@media (max-width: 480px) {
  :root {
    --sidebar-width: 260px;
    --topbar-height: 52px;
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar-title h1 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-content {
    padding: 10px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 12px 10px;
    gap: 8px;
    flex-direction: column;
    text-align: center;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .stat-info h3 {
    font-size: 20px;
  }

  .stat-info p {
    font-size: 11px;
  }

  /* Meeting items vertical on very small */
  .meeting-item {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .meeting-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .meeting-info {
    flex: 1;
    min-width: 0;
  }

  .meeting-info h4 {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .meeting-info p {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .meeting-status {
    font-size: 11px;
    padding: 3px 8px;
  }

  /* Cards ultra compact */
  .card {
    border-radius: 8px;
    margin-bottom: 10px;
  }

  .card-header {
    padding: 10px 12px;
  }

  .card-header h3 {
    font-size: 13px;
    gap: 6px;
  }

  .card-body {
    padding: 12px;
  }

  .card-actions .form-select {
    font-size: 12px;
    padding: 6px 8px;
    max-width: 140px;
  }

  /* Login compact */
  .login-card {
    padding: 24px 20px;
  }

  .login-logo {
    font-size: 40px;
  }

  .login-header h1 {
    font-size: 22px;
  }

  .login-header p {
    font-size: 12px;
  }

  .login-form input {
    padding: 10px 14px;
    font-size: 14px;
  }

  /* Compliance */
  .compliance-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .compliance-item {
    padding: 12px;
  }

  .compliance-item h4 {
    font-size: 14px;
  }

  .compliance-item p,
  .compliance-item ul {
    font-size: 12px;
  }

  /* Vote result bars */
  .vote-result-label {
    font-size: 12px;
  }

  .vote-result-track {
    height: 20px;
  }

  .vote-result-fill {
    font-size: 10px;
    padding-left: 8px;
  }

  /* Toast smaller */
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .toast {
    font-size: 13px;
    padding: 12px 14px;
    max-width: 100%;
  }

  /* Modal full-screen on phone */
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    margin: 0;
  }

  .modal-lg {
    max-width: 100%;
  }

  .modal-header {
    padding: 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }

  /* PDPA */
  .pdpa-notice {
    padding: 14px;
  }

  .pdpa-notice h3 {
    font-size: 14px;
  }

  .consent-item {
    padding: 8px;
    font-size: 13px;
  }

  /* Settings form */
  .content-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Page actions full width */
  .page-actions {
    flex-direction: column;
    gap: 8px;
  }

  .page-actions .btn {
    width: 100%;
  }

  /* Sidebar menu items */
  .menu-group-label {
    padding: 12px 12px 4px;
    font-size: 9px;
  }

  .menu-item a {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
  }
}

/* Ultra-small phones (< 360px) */
@media (max-width: 360px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .stat-card {
    flex-direction: row;
    text-align: left;
  }

  .login-card {
    padding: 20px 16px;
  }

  .topbar-title h1 {
    font-size: 14px;
  }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .menu-item a {
    min-height: 44px;
  }

  .vote-option {
    min-height: 50px;
  }

  .form-control, .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .meeting-item {
    min-height: 60px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Landscape phone orientation */
@media (max-height: 500px) and (orientation: landscape) {
  .login-container {
    padding: 10px;
  }

  .login-card {
    padding: 20px;
  }

  .login-logo {
    font-size: 32px;
    margin-bottom: 4px;
  }

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

  .login-header h1 {
    font-size: 20px;
  }

  .login-header p {
    display: none;
  }

  .loading-icon {
    font-size: 40px;
  }

  .loading-content h1 {
    font-size: 24px;
  }
}

/* Print styles */
@media print {
  .sidebar, .topbar, .page-actions, .btn, .toast-container {
    display: none !important;
  }

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

  .page-content {
    padding: 0 !important;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #ddd;
    break-inside: avoid;
  }
}
