:root {
  --background: #f8fafc;
  --foreground: #0f172a;
  --card: #ffffff;
  --card-foreground: #0f172a;
  --primary: #0ea5e9;
  --primary-foreground: #f8fafc;
  --secondary: #f1f5f9;
  --secondary-foreground: #1e293b;
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --accent: #f0f9ff;
  --accent-foreground: #1e293b;
  --destructive: #ef4444;
  --destructive-foreground: #f8fafc;
  --border: #e2e8f0;
  --input: #e2e8f0;
  --ring: #0ea5e9;
  --radius: 0.75rem;
  --sidebar-width: 16rem;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--background);
  color: var(--foreground);
}

/* PWA Fullscreen */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; }
}

/* QR Scanner scan-line animation */
@keyframes scanLine {
  0% { transform: translateY(0); opacity: 1; }
  50% { opacity: 0.5; }
  100% { transform: translateY(260px); opacity: 1; }
}
.scan-line {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #6366f1, transparent);
  animation: scanLine 2s ease-in-out infinite;
  border-radius: 1px;
  box-shadow: 0 0 8px rgba(99,102,241,0.6);
  pointer-events: none;
  z-index: 2;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.3); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.5); }

/* Layout */
.dashboard-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--background);
}

/* Sidebar */
.sidebar {
  position: fixed;
  inset-y: 0;
  left: 0;
  z-index: 35;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--border);
  background-color: white;
  padding-top: 1rem;
  transition: transform 0.3s;
}

@media (min-width: 768px) {
  .sidebar { 
    position: static; 
    transform: translateX(0) !important;
  }
}

.sidebar.closed {
  transform: translateX(-100%);
}

@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar:not(.closed) {
    transform: translateX(0);
  }
}

.sidebar-inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar-brand {
  margin-bottom: 1.5rem;
  padding: 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #0ea5e9, #4f46e5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  flex: 1;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  transition: all 0.15s;
  margin-bottom: 1px;
}

.sidebar-link:hover {
  background-color: #f1f5f9;
  color: #0f172a;
}

.sidebar-link.active {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(14, 165, 233, 0.1);
}

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

.sidebar-footer-box {
  border-radius: 0.5rem;
  padding: 0.75rem;
  font-size: 0.75rem;
  background-color: #f8fafc;
  color: #64748b;
}

.sidebar-footer-box .brand {
  font-weight: 600;
  display: block;
  color: #334155;
}

/* Mobile backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

@media (min-width: 768px) {
  .sidebar-backdrop { display: none; }
}

/* Main content */
.main-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

/* Navbar */
.navbar-custom {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
}

.navbar-custom-inner {
  display: flex;
  height: 4rem;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-toggle-btn {
  display: inline-flex;
  height: 2.25rem;
  width: 2.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
}

.navbar-toggle-btn:hover {
  background-color: #f1f5f9;
  color: #0f172a;
}

@media (min-width: 768px) {
  .navbar-toggle-btn { display: none; }
}

/* Role badge */
.role-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  border: 1px solid;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25rem;
}

.role-badge-admin {
  background: rgba(244, 63, 94, 0.1);
  color: #e11d48;
  border-color: rgba(244, 63, 94, 0.2);
}

.role-badge-teacher {
  background: rgba(99, 102, 241, 0.1);
  color: #6366f1;
  border-color: rgba(99, 102, 241, 0.2);
}

.role-badge-doctor {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.2);
}

/* Notification bell */
.notif-btn {
  position: relative;
  height: 2.25rem;
  width: 2.25rem;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s;
}

.notif-btn:hover {
  background-color: #f1f5f9;
}

.notif-badge {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  display: flex;
  height: 1rem;
  width: 1rem;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background-color: var(--primary);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1;
}

/* Notification panel */
.notif-panel {
  position: absolute;
  right: 0;
  margin-top: 0.5rem;
  width: 20rem;
  max-width: 24rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background-color: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 100;
}

@media (max-width: 767px) {
  .notif-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    right: auto;
    margin-top: 0;
    width: 90%;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 1000;
  }
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f1f5f9;
}

.notif-panel-list {
  max-height: 420px;
  overflow-y: auto;
}

.notif-panel-item {
  display: flex;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  align-items: flex-start;
  border: none;
  background: none;
  cursor: pointer;
  transition: background-color 0.15s;
  border-bottom: 1px solid #f1f5f9;
}

.notif-panel-item:hover {
  background-color: #f8fafc;
}

.notif-panel-item.unread {
  background-color: rgba(240, 249, 255, 0.6);
}

.notif-panel-footer {
  border-top: 1px solid #f1f5f9;
  padding: 0.75rem 1rem;
  text-align: center;
  background-color: rgba(248, 250, 252, 0.5);
}

/* Page content */
.page-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

@media (min-width: 640px) {
  .page-wrapper { padding: 1rem 1rem; }
}

@media (min-width: 1024px) {
  .page-wrapper { padding: 1.5rem; }
}

/* Mobile improvements */
@media (max-width: 767px) {
  .btn-sky, .btn-outline, .btn-icon {
    min-height: 44px;
    min-width: 44px;
  }
  
  .card-medtrack-header {
    padding: 0.75rem;
  }
  
  .card-medtrack-body {
    padding: 0.75rem;
  }
  
  .table-medtrack {
    font-size: 0.75rem;
  }
  
  .table-medtrack th,
  .table-medtrack td {
    padding: 0.5rem;
  }
  
  .kpi-card-body {
    padding: 1rem;
  }
  
  .kpi-value {
    font-size: 1.25rem;
  }
  
  .navbar-custom-inner {
    padding: 0 0.75rem;
  }
  
  .sidebar-brand {
    font-size: 1rem;
    margin-bottom: 1rem;
  }
  
  .sidebar-link {
    padding: 0.75rem;
    font-size: 0.9rem;
  }
  
  .input-medtrack,
  .select-medtrack {
    font-size: 16px;
  }
  
  .modal-medtrack-content {
    max-height: 95vh;
    margin: 0.5rem;
  }
  
  .cal-cell {
    min-height: 40px;
    padding: 0.25rem;
  }
  
  .cal-pill {
    font-size: 0.65rem;
    padding: 0.1rem 0.2rem;
  }
  
  .cal-plus {
    font-size: 1rem;
  }
  
  .page-wrapper {
    padding: 0.75rem;
  }
}

.page-container {
  margin: 0 auto;
  max-width: 80rem;
}

/* Cards */
.card-medtrack {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background-color: white;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.card-medtrack-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background-color: white;
}

.card-medtrack-body {
  padding: 0.75rem 1rem;
}

.cal-scroll-container {
  max-height: 500px;
  overflow-y: auto;
}

/* Buttons */
.btn-sky {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  background-color: var(--primary);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  border: none;
  transition: all 0.15s;
  cursor: pointer;
}

.btn-sky:hover {
  background-color: #0284c7;
}

.btn-sky:disabled {
  opacity: 0.5;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #cbd5e1;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: white;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-outline:hover {
  background-color: #f8fafc;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  border: none;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: transparent;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-ghost:hover {
  background-color: #f1f5f9;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  background: white;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background-color: #f8fafc;
}

.btn-icon-danger {
  border-color: #fecaca;
  color: #dc2626;
}

.btn-icon-danger:hover {
  background-color: #fef2f2;
}

/* Tables */
.table-medtrack {
  width: 100%;
  text-align: left;
  font-size: 0.875rem;
  color: #475569;
}

.table-medtrack thead {
  background-color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 600;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-medtrack th {
  padding: 1rem 1.5rem;
}

.table-medtrack td {
  padding: 1rem 1.5rem;
}

.table-medtrack tbody tr {
  border-bottom: 1px solid var(--border);
}

.table-medtrack tbody tr:hover {
  background-color: rgba(248, 250, 252, 0.5);
}

/* Inputs */
.input-medtrack {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--input);
  background-color: white;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.input-medtrack:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 1px var(--primary);
}

.select-medtrack {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--input);
  background-color: white;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.select-medtrack:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 1px var(--primary);
}

/* Modal */
.modal-medtrack {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal-medtrack-content {
  width: 100%;
  max-width: 42rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background-color: white;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  max-height: 90vh;
  overflow-y: auto;
}

/* Alerts */
.alert-success {
  border-radius: 0.5rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 1rem;
  font-size: 0.875rem;
  color: #059669;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-error {
  border-radius: 0.5rem;
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.2);
  padding: 1rem;
  font-size: 0.875rem;
  color: #e11d48;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* KPIs */
.kpi-card {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background-color: white;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  height: 100%;
}

.kpi-card-body {
  padding: 1.25rem;
  display: flex;
  align-items: center;
}

.kpi-icon {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
}

.kpi-icon-primary { background: rgba(14, 165, 233, 0.1); color: var(--primary); }
.kpi-icon-success { background: rgba(16, 185, 129, 0.1); color: #059669; }
.kpi-icon-info { background: rgba(99, 102, 241, 0.1); color: #6366f1; }
.kpi-icon-warning { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.kpi-icon-danger { background: rgba(244, 63, 94, 0.1); color: #dc2626; }

.kpi-info {
  flex-grow: 1;
  margin-left: 0.75rem;
}

.kpi-label {
  font-size: 0.8125rem;
  color: #64748b;
  font-weight: 500;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}

/* Steps */
.steps-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.step-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-number {
  display: flex;
  height: 2rem;
  width: 2rem;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
}

.step-number.active {
  background-color: var(--primary);
  color: white;
}

.step-number.completed {
  background-color: #10b981;
  color: white;
}

.step-number.pending {
  background-color: #e2e8f0;
  color: #475569;
}

.step-label {
  font-size: 0.875rem;
  font-weight: 500;
}

.step-label.active {
  color: var(--primary);
}

.step-label.inactive {
  color: #475569;
}

/* Status badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-draft { background: rgba(100, 116, 139, 0.1); color: #475569; }
.badge-active { background: rgba(14, 165, 233, 0.1); color: var(--primary); }
.badge-completed { background: rgba(16, 185, 129, 0.1); color: #059669; }
.badge-cancelled { background: rgba(244, 63, 94, 0.1); color: #dc2626; }

/* Active indicator dot */
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-dot::before {
  content: '';
  display: inline-block;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 9999px;
}

.status-dot.active { color: #10b981; }
.status-dot.active::before { background-color: #10b981; }
.status-dot.inactive { color: #f43f5e; }
.status-dot.inactive::before { background-color: #f43f5e; }

/* Pagination */
.pagination-medtrack {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  background-color: white;
  padding: 1rem 1.5rem;
}

/* Form layout */
.form-section {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.form-hint {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.25rem;
}

/* Bubble backgrounds */
.bg-primary-light { background-color: rgba(14, 165, 233, 0.1); }
.text-primary-dark { color: var(--primary); }

.bg-success-light { background-color: rgba(16, 185, 129, 0.1); }
.text-success-dark { color: #059669; }

.bg-warning-light { background-color: rgba(245, 158, 11, 0.1); }
.text-warning-dark { color: #d97706; }

.bg-danger-light { background-color: rgba(244, 63, 94, 0.1); }
.text-danger-dark { color: #dc2626; }

.bg-info-light { background-color: rgba(99, 102, 241, 0.1); }
.text-info-dark { color: #6366f1; }

/* Space utility */
.space-y-6 > * + * { margin-top: 1.5rem; }
.mt-3 { margin-top: 1rem; }

/* Calendar layout */
.cal-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

@media (max-width: 991.98px) {
  .cal-layout {
    grid-template-columns: 1fr;
  }
}

/* Calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.125rem;
}

.cal-grid-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.125rem;
  margin-bottom: 0.125rem;
}

.cal-cell {
  aspect-ratio: 1;
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.125rem;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cal-cell:hover {
  border-color: #7dd3fc;
  background-color: #f0f9ff;
}

.cal-cell.today {
  border-color: var(--primary);
  background-color: #f0f9ff;
}
.cal-cell.today .day-num {
  background-color: var(--primary);
  color: white;
  border-radius: 9999px;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-cell.today {
  background-color: #f0f9ff;
  border-color: #7dd3fc;
}

.cal-pill {
  font-size: 0.7rem;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
  max-width: 100%;
}

.cal-cell .day-num {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.cal-cell .overflow-text {
  font-size: 0.75rem;
  color: #64748b;
}

.cal-plus {
  font-size: 1.25rem;
  font-weight: 600;
  color: #cbd5e1;
  opacity: 0.5;
}

.cal-cell:hover .cal-plus {
  color: var(--primary);
  opacity: 1;
}

/* Session card in day panel */
.session-card {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  transition: background-color 0.15s;
}

.session-card:hover {
  background-color: #f8fafc;
}

/* Dashed button */
.btn-dashed {
  width: 100%;
  border: 2px dashed #cbd5e1;
  border-radius: 0.5rem;
  padding: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #64748b;
  background: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-dashed:hover {
  border-color: #0ea5e9;
  color: #0ea5e9;
}

/* Toggle buttons */
.btn-toggle {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.15s;
  border: none;
  cursor: pointer;
}

.btn-toggle.active {
  background-color: #0ea5e9;
  color: white;
}

.btn-toggle:not(.active) {
  background-color: #f1f5f9;
  color: #475569;
}

.btn-toggle:not(.active):hover {
  background-color: #e2e8f0;
}
