/* ===== TATHYA MEDICAL RECORDS - Main Stylesheet ===== */

:root {
  --primary: #1a3a5c;
  --primary-light: #2a5a8c;
  --accent: #e8794a;
  --accent-light: #f0966a;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #6b7d8e;
  --border: #dce3ea;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --info: #3498db;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== LOGIN PAGE ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #1a3a5c 0%, #2a5a8c 50%, #1a3a5c 100%);
}

.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card .logo {
  width: 64px;
  height: 64px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: white;
  font-size: 28px;
  font-weight: bold;
}

.login-card h1 {
  font-size: 22px;
  color: var(--primary);
  margin-bottom: 6px;
}

.login-card .subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 18px;
  text-align: left;
}

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

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: var(--transition);
  background: var(--bg);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-light);
  background: white;
}

.login-btn {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 8px;
}

.login-btn:hover { background: var(--primary-light); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* ===== DASHBOARD LAYOUT ===== */
.dashboard {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--primary);
  color: white;
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 10px;
}

.sidebar-header h2 {
  font-size: 18px;
  margin-bottom: 2px;
}

.sidebar-header .patient-name {
  font-size: 12px;
  opacity: 0.7;
}

.sidebar-nav { flex: 1; list-style: none; padding: 10px 0; }

.sidebar-nav li { margin: 2px 0; }

.sidebar-nav li a {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 14px;
  transition: var(--transition);
  gap: 10px;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255,255,255,0.12);
  color: white;
}

.sidebar-nav li a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 12px;
  opacity: 0.6;
}

.logout-btn {
  display: block;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.logout-btn:hover { color: white; }

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 24px;
  max-width: calc(100vw - 260px);
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.top-bar h1 {
  font-size: 24px;
  color: var(--primary);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--primary);
  padding: 6px;
}

/* ===== STATS CARDS ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

.stat-card.accent .stat-number { color: var(--accent); }
.stat-card.success .stat-number { color: var(--success); }
.stat-card.warning .stat-number { color: var(--warning); }

/* ===== SECTION ===== */
.section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  font-size: 18px;
  color: var(--primary);
}

/* ===== FILTERS ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-width: 220px;
  background: var(--bg);
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-light);
  background: white;
}

.filter-select {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  cursor: pointer;
  transition: var(--transition);
}

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

/* ===== FILE GRID ===== */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.file-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.file-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow);
}

.file-card .file-icon {
  font-size: 28px;
  margin-bottom: 10px;
}

.file-card .file-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.3;
}

.file-card .file-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.file-card .file-desc {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
  flex: 1;
  line-height: 1.4;
}

.file-card .file-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.category-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-blood { background: #fde8e8; color: #c0392b; }
.badge-metabolic { background: #e8f4fd; color: #2471a3; }
.badge-genetics { background: #e8f8e8; color: #1e8449; }
.badge-imaging { background: #fef5e7; color: #b9770e; }
.badge-neurology { background: #f4ecf7; color: #6c3483; }
.badge-prescription { background: #e8faf0; color: #148f77; }
.badge-neonatal { background: #fdebd0; color: #a04000; }
.badge-antenatal { background: #fce4ec; color: #c2185b; }
.badge-cardiology { background: #e3f2fd; color: #1565c0; }
.badge-audiology { background: #f3e5f5; color: #7b1fa2; }
.badge-ophthalmology { background: #e0f7fa; color: #00838f; }
.badge-action-plan { background: #fff3e0; color: #e65100; }
.badge-video { background: #fce4ec; color: #c62828; }
.badge-other { background: #eceff1; color: #546e7a; }

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}

.download-btn:hover { background: var(--primary-light); }

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}

.view-btn:hover {
  background: var(--bg);
  border-color: var(--primary-light);
}

/* ===== VIDEO PREVIEW MODAL ===== */
.video-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.video-modal-overlay.open { display: flex; }

.video-modal {
  background: black;
  border-radius: var(--radius);
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
  overflow: hidden;
}

.video-modal video {
  max-width: 90vw;
  max-height: 85vh;
  display: block;
}

.video-modal .close-modal {
  position: absolute;
  top: 8px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 18px;
  cursor: pointer;
  z-index: 2;
}

.video-modal .close-modal:hover { background: rgba(255,255,255,0.3); }

.no-results {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
  font-size: 15px;
  grid-column: 1 / -1;
}

/* ===== TABLE VIEW ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  background: var(--primary);
  color: white;
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover td { background: #f8f9fb; }

.data-table .table-download {
  padding: 4px 10px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-size: 11px;
  white-space: nowrap;
}

/* ===== TIMELINE ===== */
.timeline {
  position: relative;
  padding-left: 30px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border);
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  margin-bottom: 24px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -26px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 3px solid white;
  box-shadow: 0 0 0 2px var(--primary-light);
}

.timeline-item.milestone::before {
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.timeline-date {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 2px;
}

.timeline-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.timeline-desc {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.4;
}

.timeline-doc-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--primary-light);
  text-decoration: underline;
  cursor: pointer;
}

/* ===== CALENDAR ===== */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.calendar-nav h3 {
  font-size: 16px;
  color: var(--primary);
}

.calendar-nav button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
}

.calendar-nav button:hover { background: var(--bg); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}

.calendar-day-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  padding: 8px 0;
  text-transform: uppercase;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  min-height: 40px;
}

.calendar-day:hover { background: var(--bg); }

.calendar-day.today {
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.calendar-day.has-event::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  bottom: 6px;
}

.calendar-day.today.has-event::after { background: white; }

.calendar-day.other-month { color: #ccc; }

/* ===== DOCTOR DIRECTORY ===== */
.doctor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.doctor-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.doctor-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow);
}

.doctor-card h3 {
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 4px;
}

.doctor-card .specialty {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 10px;
}

.doctor-card .detail {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.doctor-card .detail .label {
  font-weight: 600;
  color: var(--text);
  min-width: 50px;
}

/* ===== ADD RECORD FORM ===== */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.form-row.full { grid-template-columns: 1fr; }

.add-form input,
.add-form select,
.add-form textarea {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  transition: var(--transition);
}

.add-form input:focus,
.add-form select:focus,
.add-form textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  background: white;
}

.add-form textarea { resize: vertical; min-height: 70px; }

.add-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.submit-btn {
  padding: 12px 28px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.submit-btn:hover { background: var(--primary-light); }

.form-success {
  color: var(--success);
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ===== PAGE CONTENT (hidden/shown) ===== */
.page-content { display: none; }
.page-content.active { display: block; }

/* ===== CUSTOM TIMELINE ENTRIES ===== */
.timeline-item.custom-entry {
  background: #fafafa;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-left: -16px;
  border: 1px dashed var(--border);
}

.timeline-item.custom-entry::before {
  background: var(--success) !important;
  box-shadow: 0 0 0 2px var(--success) !important;
}

/* ===== CATEGORY MANAGER ===== */
.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border-radius: 20px;
  font-size: 13px;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.category-chip:hover {
  border-color: var(--primary-light);
}

.category-chip .delete-cat {
  color: var(--danger);
  cursor: pointer;
  margin-left: 4px;
  font-weight: bold;
}

.category-chip .builtin-tag {
  font-size: 10px;
  color: var(--text-light);
  background: #eee;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ===== FILE INPUT STYLING ===== */
input[type="file"] {
  cursor: pointer;
  font-family: inherit;
}

input[type="file"]:hover {
  border-color: var(--primary-light) !important;
  background: #f0f4f8 !important;
}

input[type="file"]::file-selector-button {
  padding: 6px 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  margin-right: 10px;
  transition: var(--transition);
}

input[type="file"]::file-selector-button:hover {
  background: var(--primary-light);
}

/* ===== ADMIN-ONLY ELEMENTS ===== */
.admin-only { }

/* ===== PATIENT SUMMARY ===== */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.summary-table td:first-child {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  width: 160px;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 1024px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .sidebar-overlay.open { display: block; }

  .main-content {
    margin-left: 0;
    max-width: 100vw;
    padding: 16px;
  }

  .mobile-menu-btn { display: block; }

  .top-bar h1 { font-size: 20px; }

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

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

  .filter-bar { flex-direction: column; }
  .search-input { min-width: 100%; }
  .filter-select { width: 100%; }
  #dateFrom, #dateTo { max-width: 100% !important; width: 100%; }

  .form-row { grid-template-columns: 1fr; }

  .calendar-day { font-size: 11px; min-height: 32px; }

  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }

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

  .section { padding: 16px; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .stat-card { padding: 14px; }
  .stat-card .stat-number { font-size: 24px; }

  .login-card { padding: 28px 20px; }
  .login-card h1 { font-size: 20px; }

  .calendar-grid { gap: 1px; }
  .calendar-day { font-size: 10px; }
  .calendar-day-header { font-size: 9px; }
}

/* Print */
@media print {
  .sidebar, .top-bar, .filter-bar, .download-btn, .logout-btn,
  .mobile-menu-btn, .sidebar-overlay, .add-record-section { display: none !important; }
  .main-content { margin-left: 0; max-width: 100%; padding: 0; }
  .section { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
