@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ======== DARK THEME (default) ======== */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2235;
  --bg-card-hover: #1f2b42;
  --bg-input: #0f1629;
  --border: #2a3550;
  --border-focus: #3b82f6;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gradient-1: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-2: linear-gradient(135deg, #10b981, #3b82f6);
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 240px;
  --transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
  --overlay-bg: rgba(0,0,0,0.6);
  color-scheme: dark;
}

/* ======== LIGHT THEME ======== */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.1);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gradient-1: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-2: linear-gradient(135deg, #10b981, #3b82f6);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
  --overlay-bg: rgba(0,0,0,0.4);
  color-scheme: light;
}

/* ======== BASE ======== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ======== AUTH PAGE ======== */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg-primary);
  background-image: radial-gradient(ellipse at 20% 50%, var(--accent-glow) 0%, transparent 50%),
                    radial-gradient(ellipse at 80% 20%, rgba(139,92,246,0.08) 0%, transparent 50%);
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 {
  font-size: 28px; font-weight: 700;
  background: var(--gradient-1);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 8px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 15px; transition: var(--transition); outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ======== BUTTONS ======== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; transition: var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--gradient-1); color: white; width: 100%; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-secondary { background: var(--bg-card-hover); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-icon {
  padding: 8px; border-radius: var(--radius-sm); background: transparent;
  color: var(--text-secondary); border: 1px solid var(--border);
}
.btn-icon:hover { color: var(--text-primary); border-color: var(--text-muted); }

.auth-switch { text-align: center; margin-top: 24px; color: var(--text-secondary); font-size: 14px; }
.auth-switch a { font-weight: 600; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; display: none; }
.alert-error { background: rgba(239,68,68,0.1); color: #fca5a5; border: 1px solid rgba(239,68,68,0.2); }
.alert-success { background: rgba(16,185,129,0.1); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
[data-theme="light"] .alert-error { color: #dc2626; }
[data-theme="light"] .alert-success { color: #059669; }

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

.sidebar {
  width: var(--sidebar-w); background: var(--bg-secondary);
  border-right: 1px solid var(--border); padding: 20px 12px;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: var(--transition);
}
.sidebar-logo {
  font-size: 18px; font-weight: 700; padding: 0 8px 20px;
  background: var(--gradient-1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  transition: var(--transition); cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-item .icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.user-info { display: flex; align-items: center; gap: 10px; padding: 8px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--gradient-1);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: white; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-email { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; max-width: 140px; }

/* Theme toggle */
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: var(--transition);
}
.theme-toggle:hover { background: var(--bg-card); color: var(--text-primary); }
.theme-toggle .icon { font-size: 18px; width: 22px; text-align: center; }

/* ======== MAIN CONTENT ======== */
.main-content {
  margin-left: var(--sidebar-w); flex: 1; padding: 28px; min-height: 100vh;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }

/* ======== CARDS & STATS ======== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; transition: var(--transition);
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.stat-value { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}
.card-header h3 { font-size: 16px; font-weight: 600; }

/* ======== TABLE ======== */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px;
}
th {
  color: var(--text-muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
td { white-space: nowrap; }
td:nth-child(5), td:nth-child(6) { white-space: normal; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
tr:hover td { background: var(--bg-card-hover); }

.badge {
  display: inline-flex; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: var(--accent-glow); color: var(--accent); }

/* ======== SEARCH ======== */
.search-bar { display: flex; gap: 12px; margin-bottom: 20px; }
.search-bar input {
  flex: 1; padding: 10px 16px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 14px; outline: none; transition: var(--transition);
}
.search-bar input:focus { border-color: var(--border-focus); }

/* ======== CONFIG ======== */
.config-section {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; border-bottom: 1px solid var(--border); gap: 16px; flex-wrap: wrap;
}
.config-section:last-child { border-bottom: none; }
.config-info { flex: 1; min-width: 0; }
.config-info h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.config-info p { font-size: 13px; color: var(--text-secondary); word-break: break-word; }

/* ======== MODAL ======== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--overlay-bg); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  opacity: 0; visibility: hidden; transition: var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 500px; max-height: 85vh; overflow-y: auto;
  transform: scale(0.95); transition: var(--transition); box-shadow: var(--shadow);
}
.modal-overlay.active .modal { transform: scale(1); }
.modal h3 { font-size: 18px; margin-bottom: 20px; }

/* ======== MOBILE NAV & HEADER ======== */
.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-secondary); border-top: 1px solid var(--border);
  padding: 6px 0; z-index: 100;
}
.mobile-nav-items { display: flex; justify-content: space-around; }
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 12px; color: var(--text-muted); font-size: 10px;
  background: none; border: none; cursor: pointer; transition: var(--transition);
}
.mobile-nav-item .icon { font-size: 20px; }
.mobile-nav-item.active { color: var(--accent); }

.mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  padding: 14px 20px; z-index: 100; align-items: center; justify-content: space-between;
}
.mobile-header h1 {
  font-size: 18px;
  background: var(--gradient-1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* Spinner */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text-secondary); margin-bottom: 8px; }

/* ======== PATIENT DETAIL ======== */
.patient-header {
  display: flex; align-items: center; gap: 16px;
  padding: 20px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 24px;
}
.patient-avatar {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--gradient-1); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; flex-shrink: 0;
}
.patient-info h2 { font-size: 20px; margin-bottom: 4px; }
.patient-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.patient-meta span { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }

.breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; margin-bottom: 16px; color: var(--text-muted);
}
.breadcrumb a { color: var(--accent); }

/* ======== FOLDER BROWSER ======== */
.folder-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.folder-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 14px;
}
.folder-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(59,130,246,0.1); }
.folder-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.folder-icon.preop { background: rgba(59,130,246,0.15); }
.folder-icon.surgery { background: rgba(239,68,68,0.15); }
.folder-icon.postop { background: rgba(16,185,129,0.15); }
.folder-icon.other { background: rgba(245,158,11,0.15); }
.folder-details h4 { font-size: 14px; font-weight: 600; }
.folder-details p { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.add-folder-card {
  background: transparent; border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 18px;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  color: var(--text-muted); font-size: 14px; min-height: 80px;
}
.add-folder-card:hover { border-color: var(--accent); color: var(--accent); }

/* ======== PHOTO GALLERY ======== */
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.photo-thumb {
  aspect-ratio: 1; border-radius: var(--radius); overflow: hidden;
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; transition: var(--transition); position: relative;
}
.photo-thumb:hover { border-color: var(--accent); transform: scale(1.03); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: var(--transition); }
.photo-thumb:hover img { transform: scale(1.05); }
.photo-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  padding: 24px 10px 8px; font-size: 11px;
  color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ======== LIGHTBOX ======== */
.lightbox {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.92); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: var(--transition);
}
.lightbox.active { opacity: 1; visibility: visible; }
.lightbox img { max-width: 90vw; max-height: 85vh; border-radius: var(--radius); object-fit: contain; }
.lightbox-close {
  position: absolute; top: 20px; right: 20px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,0.15); border: none;
  color: white; font-size: 24px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,0.1); border: none;
  color: white; font-size: 24px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-nav.prev { left: 20px; }
.lightbox-nav.next { right: 20px; }
.lightbox-counter { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,0.6); font-size: 14px; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius);
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ======== RESPONSIVE — TABLET (768-1024px) ======== */
@media (max-width: 1024px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; padding: 24px 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .patient-header { flex-wrap: wrap; }
  .patient-header > div:last-child { margin-left: 0; width: 100%; }
}

/* ======== RESPONSIVE — MOBILE (<=768px) ======== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 68px 16px 80px; }
  .mobile-nav { display: block; }
  .mobile-header { display: flex; }
  .page-header h2 { font-size: 18px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .auth-card { padding: 24px; }
  .search-bar { flex-direction: column; }
  .config-section { flex-direction: column; align-items: flex-start; }
  .config-section .btn { width: 100%; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .folder-grid { grid-template-columns: 1fr; }
  .patient-header { flex-direction: column; align-items: flex-start; }
  .patient-header > div:last-child { margin-left: 0; }
  .modal { padding: 20px; margin: 12px; }
  .card { padding: 16px; }
  th, td { padding: 8px 10px; font-size: 13px; }
}

/* ======== RESPONSIVE — SMALL MOBILE (<=480px) ======== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 11px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { width: 100%; }
  .photo-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .folder-grid { grid-template-columns: 1fr; }
  .breadcrumb { font-size: 13px; }
}
