/* CareLog — Main Stylesheet */
:root {
  --cl-primary: #0d6efd;
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --shadow-md: 0 4px 24px rgba(0,0,0,.12);
  --transition: .2s ease;
}

/* Fonts */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  margin: 0;
  overflow-x: hidden;
}
code, .mono { font-family: 'DM Mono', monospace; }

/* ===================== LIGHT / DARK ===================== */
[data-bs-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface2: #f0f2f5;
  --border: #e2e6ea;
  --text: #1a1d23;
  --text-muted: #6c757d;
  --sidebar-bg: #0f172a;
  --sidebar-text: rgba(255,255,255,.75);
  --sidebar-active-bg: rgba(255,255,255,.1);
  --sidebar-active-text: #fff;
  --sidebar-label: rgba(255,255,255,.3);
}
[data-bs-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --sidebar-bg: #010409;
  --sidebar-text: rgba(230,237,243,.7);
  --sidebar-active-bg: rgba(255,255,255,.08);
  --sidebar-active-text: #e6edf3;
  --sidebar-label: rgba(255,255,255,.25);
}

body { background: var(--bg); color: var(--text); }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform var(--transition), width var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  min-height: var(--topbar-h);
}
.brand-icon {
  width: 40px; height: 40px;
  background: var(--cl-primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px;
  flex-shrink: 0;
}
.brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; flex-shrink: 0; }
.brand-text { overflow: hidden; }
.brand-name { display: block; color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-tag { display: block; color: rgba(255,255,255,.4); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-menu { flex: 1; padding: 12px 8px; }
.menu-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sidebar-label); padding: 16px 10px 4px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: all var(--transition); margin-bottom: 2px;
}
.menu-item:hover { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.menu-item.active { background: var(--cl-primary); color: #fff; }
.menu-item i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }

.sidebar-footer { padding: 8px; border-top: 1px solid rgba(255,255,255,.06); }

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.sidebar-toggle { border: none; background: none; color: var(--text); padding: 6px; }
.topbar-title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--cl-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.topbar-user { background: none; border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px; color: var(--text); }
.topbar-user:hover { background: var(--surface2); }

/* Content area */
.content-area { padding: 24px; flex: 1; }

/* ===================== CARDS ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-weight: 600;
  font-size: 14px;
}
.card-body { padding: 20px; }

/* Stat cards */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue  { background: rgba(13,110,253,.12); color: #0d6efd; }
.stat-icon.green { background: rgba(25,135,84,.12); color: #198754; }
.stat-icon.amber { background: rgba(255,193,7,.12); color: #e6a800; }
.stat-icon.red   { background: rgba(220,53,69,.12); color: #dc3545; }
.stat-icon.teal  { background: rgba(13,202,240,.12); color: #0dcaf0; }
.stat-num { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Badges */
.badge-status { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px; }
.badge-active   { background: rgba(25,135,84,.12); color: #198754; }
.badge-completed { background: rgba(13,110,253,.12); color: #0d6efd; }
.badge-cancelled { background: rgba(108,117,125,.12); color: #6c757d; }

/* Tables */
.table { --bs-table-bg: transparent; color: var(--text); }
.table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--surface2); }
.table-responsive { border-radius: var(--radius); overflow: hidden; }

/* Forms */
.form-control, .form-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
  padding: 8px 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
  background: var(--surface);
  border-color: var(--cl-primary);
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
}
.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.input-group-text { background: var(--surface2); border-color: var(--border); color: var(--text-muted); }

/* Buttons */
.btn { font-weight: 500; border-radius: var(--radius-sm); font-size: 13.5px; }
.btn-primary { background: var(--cl-primary); border-color: var(--cl-primary); }

/* Page header */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin: 0; }
.page-header p { color: var(--text-muted); margin: 4px 0 0; font-size: 13px; }

/* QR Scanner */
#reader { border-radius: var(--radius); overflow: hidden; }
.scan-overlay {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.scan-animation {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 260px;
  display: flex; align-items: center; justify-content: center;
}
.scan-line {
  position: absolute;
  width: 80%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cl-primary), transparent);
  animation: scanMove 2s ease-in-out infinite;
  left: 10%;
}
@keyframes scanMove {
  0%, 100% { top: 15%; }
  50% { top: 85%; }
}
.scan-corner {
  position: absolute;
  width: 30px; height: 30px;
  border-color: var(--cl-primary); border-style: solid;
}
.scan-corner.tl { top: 10%; left: 10%; border-width: 3px 0 0 3px; }
.scan-corner.tr { top: 10%; right: 10%; border-width: 3px 3px 0 0; }
.scan-corner.bl { bottom: 10%; left: 10%; border-width: 0 0 3px 3px; }
.scan-corner.br { bottom: 10%; right: 10%; border-width: 0 3px 3px 0; }

/* Visit form preview */
.patient-preview {
  background: linear-gradient(135deg, var(--cl-primary), color-mix(in srgb, var(--cl-primary) 60%, #000));
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
}
.patient-preview .avatar-lg {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
}

/* Alert toast */
.toast-container { position: fixed; top: 70px; right: 20px; z-index: 9999; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .content-area { padding: 16px; }
  .stat-num { font-size: 22px; }
}

/* Overlay for mobile */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
}
.sidebar-backdrop.show { display: block; }

/* Misc */
.text-primary { color: var(--cl-primary) !important; }
.border-primary { border-color: var(--cl-primary) !important; }
.progress { border-radius: 20px; background: var(--surface2); }

/* Print */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #dee2e6; }
}
