/* Global Styles */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { 
  font-family: Arial, sans-serif; 
  background-color: #f0f0f0; 
  color: #333;
  font-size: 16px; /* Base font size for better mobile readability */
  line-height: 1.5;
}

/* Header */
header { 
  background-color: #007bff; 
  color: white; 
  padding: 1.5rem 1rem; 
  text-align: center; 
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 { 
  margin: 0; 
  color: white;
  font-size: 1.75rem;
}

/* Navigation */
nav { 
  background-color: #f8f9fa; 
  padding: 0.75rem; 
  text-align: center;
  overflow: visible; /* Allow dropdowns to overflow */
  white-space: nowrap;
  position: relative;
  z-index: 100;
}
nav a { 
  margin: 0.5rem; 
  text-decoration: none; 
  color: #007bff; 
  font-weight: bold; 
  display: inline-block;
  padding: 0.75rem 1rem; /* Larger touch target */
  min-height: 44px; /* iOS minimum touch target */
  line-height: 1.5;
}
nav a:hover { text-decoration: underline; }
nav a.active { 
  color: white; 
  background-color: #007bff; 
  border-radius: 4px; 
}
nav a.logout { color: #dc3545; }

/* Dropdown Menu - Pure CSS hover-based */
.dropdown {
  position: relative;
  display: inline-block;
  margin: 0.5rem;
}
.dropdown-toggle {
  margin: 0 !important;
  text-decoration: none;
  color: #007bff;
  font-weight: bold;
  display: inline-block;
  padding: 0.75rem 1rem;
  min-height: 44px;
  line-height: 1.5;
  cursor: pointer;
}
.dropdown-toggle:hover {
  text-decoration: underline;
}
.dropdown-toggle.active {
  color: white;
  background-color: #007bff;
  border-radius: 4px;
}
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background-color: white;
  min-width: 200px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  z-index: 9999;
  border-radius: 4px;
  padding: 0;
  margin: 0;
}
.dropdown-menu a {
  color: #333 !important;
  padding: 0.75rem 1rem;
  text-decoration: none;
  display: block;
  text-align: left;
  margin: 0 !important;
  font-weight: normal;
  border-bottom: 1px solid #f0f0f0;
}
.dropdown-menu a:last-child {
  border-bottom: none;
}
.dropdown-menu a:hover {
  background-color: #f8f9fa;
  text-decoration: none;
}
/* Show dropdown on hover (desktop) and focus-within (mobile/touch) */
.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu {
  display: block;
}
/* Make toggle focusable for mobile touch */
.dropdown-toggle:focus {
  outline: none;
}

/* Inline form for small actions */
.inline-form { display: inline; margin-right: 1rem; }

/* Layout */
.container { 
  max-width: 1200px; 
  margin: 1rem auto; 
  padding: 1.5rem; 
  background-color: white; 
  border-radius: 8px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.1); 
}
.container h1 { 
  color: #333; 
  margin-bottom: 1.5rem; 
  text-align: center;
  font-size: 1.5rem;
}

/* Buttons */
.btn { 
  display: inline-block; 
  padding: 0.75rem 1.25rem; 
  border-radius: 4px; 
  text-decoration: none; 
  cursor: pointer;
  min-height: 44px; /* iOS touch target */
  line-height: 1.5;
  font-size: 1rem;
}
.btn-primary { background-color: #007bff; color: white; }
.btn-primary:hover { background-color: #0056b3; }
.btn-success { background-color: #28a745; color: white; }
.btn-success:hover { background-color: #218838; }
.btn-danger { background-color: #dc3545; color: white; }
.btn-danger:hover { background-color: #c82333; }
.btn-secondary { background-color: #6c757d; color: white; }
.btn-secondary:hover { background-color: #5a6268; }
.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.form-actions button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  flex: 1;
  min-width: 150px;
  line-height: 1.5;
  margin: 0;
  vertical-align: middle;
}
.form-buttons { 
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.form-buttons button {
  height: 44px;
  padding: 0 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
}
.add-btn { 
  display: block; 
  margin: 1.5rem auto; 
  padding: 1rem 2rem; 
  background-color: #007bff; 
  color: white; 
  text-decoration: none; 
  border-radius: 4px; 
  text-align: center; 
  width: fit-content;
  min-height: 44px;
  font-size: 1rem;
}
.add-btn:hover { background-color: #0056b3; }
.edit-btn { 
  background-color: #28a745; 
  color: white; 
  border: none; 
  padding: 0.75rem 1rem; 
  border-radius: 4px; 
  cursor: pointer; 
  text-decoration: none; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem; 
  margin-right: 0.5rem;
  min-height: 44px;
  line-height: 1;
}
.edit-btn:hover { background-color: #218838; }
.delete-btn { 
  background-color: #dc3545; 
  color: white; 
  border: none; 
  padding: 0.75rem 1rem; 
  border-radius: 4px; 
  cursor: pointer; 
  text-decoration: none; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  min-height: 44px;
  line-height: 1;
}
.delete-btn:hover { background-color: #c82333; }
.btn-block { 
  display: block; 
  margin: 1.5rem auto; 
  padding: 1rem 2rem; 
  text-align: center; 
  width: fit-content;
  min-height: 44px;
}

/* Forms */
form { display: flex; flex-direction: column; }
label { 
  margin-top: 1rem; 
  color: #333; 
  font-weight: bold;
  font-size: 1rem;
}
input, select, textarea { 
  padding: 0.75rem; 
  margin-top: 0.5rem; 
  border: 1px solid #ddd; 
  border-radius: 4px; 
  font-size: 1rem;
  min-height: 44px; /* Touch-friendly */
  width: 100%;
}
form:not(.inline-form) button[type="submit"] { 
  margin-top: 1.5rem; 
  padding: 1rem 2rem; 
  background-color: #007bff; 
  color: white; 
  border: none; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 1rem; 
  font-weight: bold;
  min-height: 44px;
}
form:not(.inline-form) button[type="submit"]:hover { background-color: #0056b3; }

/* Tables */
.table { 
  width: 100%; 
  border-collapse: collapse;
  font-size: 0.95rem;
}
.table th, .table td { 
  padding: 0.75rem; 
  text-align: left; 
  border-bottom: 1px solid #ddd; 
}
.table th { 
  background-color: #f8f9fa; 
  font-weight: bold;
  white-space: nowrap;
}
.staff-table { 
  width: 100%; 
  border-collapse: collapse;
  font-size: 0.95rem;
}
.staff-table th, .staff-table td { 
  padding: 0.75rem; 
  text-align: left; 
  border-bottom: 1px solid #ddd; 
}
.staff-table th { 
  background-color: #f8f9fa; 
  font-weight: bold;
  white-space: nowrap;
}
.status-active { color: #28a745; font-weight: bold; }
.status-inactive { color: #dc3545; font-weight: bold; }

/* Table container for horizontal scrolling on mobile */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Medical Record Display */
.medical-record-display {
  background-color: #f8f9fa;
  border: 2px solid #007bff;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.medical-record-display h2 {
  margin: 0 0 0.75rem 0;
  color: #007bff;
  font-size: 1.1rem;
  font-weight: bold;
}

.medical-record-number {
  font-size: 2rem;
  font-weight: bold;
  color: #333;
  margin: 0.5rem 0;
  letter-spacing: 1px;
}

/* Cards/Groups */
.group { display: flex; align-items: center; margin-bottom: 1rem; padding: 1rem; border: 1px solid #ddd; border-radius: 4px; background-color: #fafafa; }
.group-info { flex: 1; }
.group-info h3 { margin: 0 0 0.5rem 0; color: #444; }
.group-info p { margin: 0.25rem 0; color: #666; }

/* Login */
.login-container { 
  max-width: 400px; 
  width: 100%; 
  padding: 2rem; 
  background-color: white; 
  border-radius: 8px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  margin: 1rem;
}
.error { 
  color: #dc3545; 
  text-align: center; 
  margin-top: 1rem; 
  padding: 0.75rem; 
  background-color: #f8d7da; 
  border-radius: 4px;
  font-size: 0.95rem;
}
.error-container { 
  max-width: 400px; 
  width: 100%; 
  padding: 2rem; 
  background-color: white; 
  border-radius: 8px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.1); 
  text-align: center;
  margin: 1rem;
}
/* Utility */
.center-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 1rem; }
.back-link { 
  display: inline-block; 
  margin-bottom: 1rem; 
  color: #007bff; 
  text-decoration: none;
  padding: 0;
  font-size: 1rem;
  line-height: 1.5;
}
.back-link:hover { text-decoration: underline; }
.subtitle { 
  text-align: center; 
  color: #666; 
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 768px) {
  header h1 { font-size: 1.5rem; }
  
  nav { 
    padding: 0.5rem;
    overflow: visible;
    white-space: normal;
  }
  nav a { 
    margin: 0.25rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
  
  /* Dropdown on mobile */
  .dropdown-menu {
    position: fixed;
    left: 10px;
    right: 10px;
    top: auto;
    width: auto;
    max-width: calc(100vw - 20px);
  }
  
  .container { 
    margin: 0.5rem; 
    padding: 1rem;
    border-radius: 4px;
  }
  .container h1 { font-size: 1.25rem; }
  
  .group { 
    flex-direction: column; 
    align-items: flex-start; 
  }
  
  /* Stack buttons vertically on mobile */
  .edit-btn, .delete-btn {
    display: block;
    width: 100%;
    margin: 0.25rem 0;
    text-align: center;
  }
  
  /* Make table scrollable */
  .table, .staff-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    font-size: 0.85rem;
  }
  
  .table th, .table td,
  .staff-table th, .staff-table td {
    padding: 0.5rem;
  }
  
  .login-container, .error-container {
    padding: 1.5rem;
    margin: 0.5rem;
  }
  
  .add-btn, .btn-block {
    width: 100%;
    margin: 1rem 0;
  }
  
  /* Medical record display responsive */
  .medical-record-display {
    padding: 1rem;
  }
  
  .medical-record-number {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  body { font-size: 14px; }
  
  header { padding: 1rem 0.5rem; }
  header h1 { font-size: 1.25rem; }
  
  nav a {
    font-size: 0.85rem;
    padding: 0.5rem;
    margin: 0.15rem;
  }
  
  .container { 
    margin: 0.25rem; 
    padding: 0.75rem;
  }
  .container h1 { font-size: 1.1rem; }
  
  .table, .staff-table { font-size: 0.75rem; }
  
  .table th, .table td,
  .staff-table th, .staff-table td {
    padding: 0.4rem;
  }
  
  input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .btn, .edit-btn, .delete-btn {
    font-size: 0.9rem;
    padding: 0.6rem 1rem;
  }
  
  .login-container, .error-container {
    padding: 1rem;
  }
  
  /* Medical record display for very small screens */
  .medical-record-display {
    padding: 0.75rem;
  }
  
  .medical-record-display h2 {
    font-size: 1rem;
  }
  
  .medical-record-number {
    font-size: 1.25rem;
  }
  
  .date-added-display span {
    font-size: 0.8em;
  }
}
