/* main.css — CPPT RS PWA Premium Dark Theme */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0f172a; --surface: #1e293b; --surface2: #334155; --surface3: #475569;
  --text: #f1f5f9; --text2: #94a3b8; --text3: #64748b;
  --primary: #1a73e8; --primary-hover: #1557b0; --primary-light: #1a73e820;
  --success: #22c55e; --warning: #f97316; --error: #ef4444; --info: #3b82f6;
  --blue: #3b82f6; --green: #22c55e; --gray: #6b7280; --orange: #f97316;
  --radius: 12px; --radius-sm: 8px; --radius-xs: 4px;
  --shadow: 0 4px 24px rgba(0,0,0,.3); --shadow-sm: 0 2px 8px rgba(0,0,0,.2);
  --glass: rgba(30,41,59,.7); --glass-border: rgba(148,163,184,.1);
  --transition: .2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, sans-serif; background: var(--bg);
  color: var(--text); line-height: 1.6; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }

/* ─── Typography ─── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.25rem; font-weight: 600; }
h4 { font-size: 1.1rem; font-weight: 500; }

/* ─── Layout ─── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.app-wrapper { min-height: 100vh; display: flex; flex-direction: column; }

/* ─── Header / Navbar ─── */
.navbar {
  background: var(--glass); backdrop-filter: blur(20px); border-bottom: 1px solid var(--glass-border);
  padding: .75rem 1rem; position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
}
.navbar-brand { display: flex; align-items: center; gap: .75rem; font-weight: 700; font-size: 1.1rem; }
.navbar-brand svg { width: 32px; height: 32px; }
.navbar-actions { display: flex; align-items: center; gap: .5rem; }
.navbar-user { font-size: .85rem; color: var(--text2); }
.sync-indicator { display: flex; align-items: center; gap: .25rem; font-size: .75rem; padding: .25rem .5rem; border-radius: 20px; background: var(--surface); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .625rem 1.25rem; border-radius: var(--radius-sm); font-size: .875rem;
  font-weight: 500; border: none; cursor: pointer; transition: all var(--transition);
  text-decoration: none; white-space: nowrap; font-family: inherit;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(26,115,232,.4); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: var(--surface3); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }
.btn-sm { padding: .375rem .75rem; font-size: .8rem; }
.btn-xs { padding: .2rem .5rem; font-size: .7rem; border-radius: var(--radius-xs); }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

/* ─── Form Controls ─── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .85rem; font-weight: 500; color: var(--text2); margin-bottom: .375rem; }
.form-control {
  width: 100%; padding: .625rem .875rem; background: var(--surface); border: 1px solid var(--surface2);
  border-radius: var(--radius-sm); color: var(--text); font-size: .9rem; font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-control::placeholder { color: var(--text3); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2394a3b8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2rem; }

/* Radio & Checkbox */
.radio-group, .checkbox-group { display: flex; flex-wrap: wrap; gap: .75rem; }
.radio-item, .checkbox-item {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem;
  background: var(--surface); border: 1px solid var(--surface2); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); font-size: .85rem;
}
.radio-item:has(input:checked), .checkbox-item:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.radio-item input, .checkbox-item input { accent-color: var(--primary); }

/* ─── Cards ─── */
.card {
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--glass-border); }
.card-title { font-size: 1rem; font-weight: 600; }

/* ─── Tables ─── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--glass-border); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead { background: var(--surface); }
th { padding: .75rem; text-align: left; font-weight: 600; color: var(--text2); white-space: nowrap; border-bottom: 2px solid var(--surface2); }
td { padding: .75rem; border-bottom: 1px solid var(--glass-border); vertical-align: top; }
tr { transition: background var(--transition); }
tbody tr:hover { background: var(--primary-light); cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }

/* ─── Tabs ─── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--surface2); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn {
  padding: .75rem 1.25rem; font-size: .85rem; font-weight: 500; color: var(--text3);
  background: none; border: none; cursor: pointer; white-space: nowrap; position: relative;
  transition: color var(--transition); font-family: inherit;
}
.tab-btn::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 100%; height: 2px; background: var(--primary); transform: scaleX(0); transition: transform .3s ease; }
.tab-btn.active { color: var(--primary); }
.tab-btn.active::after { transform: scaleX(1); }
.tab-btn:hover { color: var(--text); }
.tab-content { display: none; padding: 1rem 0; animation: fadeIn .3s ease; }
.tab-content.active { display: block; }

/* ─── Badge ─── */
.badge {
  display: inline-flex; align-items: center; padding: .2rem .6rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.sync-badge { font-size: .9rem; }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  opacity: 0; transition: opacity .3s ease; padding: 1rem;
}
.modal-overlay.active { opacity: 1; }
.modal {
  background: var(--surface); border: 1px solid var(--glass-border); border-radius: var(--radius);
  width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow); transform: translateY(20px) scale(.95); transition: transform .3s ease;
}
.modal-overlay.active .modal { transform: translateY(0) scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--glass-border); }
.modal-title { font-size: 1.1rem; font-weight: 600; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; background: var(--surface2); border: none; color: var(--text); font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--error); }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--glass-border); display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-lg { max-width: 900px; }

/* ─── Toast ─── */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; max-width: 360px; }
.toast {
  display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem;
  background: var(--surface); border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: .85rem; transform: translateX(120%); transition: transform .3s ease, opacity .3s ease;
  min-width: 280px;
}
.toast-show { transform: translateX(0); }
.toast-hide { transform: translateX(120%); opacity: 0; }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 1.1rem; padding: 0 .25rem; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--info); }

/* ─── Spinner ─── */
.spinner-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 3000;
  opacity: 0; transition: opacity .3s ease; pointer-events: none;
}
.spinner-overlay.active { opacity: 1; pointer-events: all; }
.spinner-content { text-align: center; }
.spinner-ring {
  width: 48px; height: 48px; border: 3px solid var(--surface2); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 1rem;
}
.spinner-text { color: var(--text2); font-size: .9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Empty State ─── */
.empty-state { display: flex; flex-direction: column; align-items: center; padding: 3rem 1rem; color: var(--text3); }
.empty-state-text { margin-top: 1rem; font-size: .95rem; }

/* ─── Photo Gallery ─── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .5rem; margin-top: .75rem; }
.photo-thumb {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  cursor: pointer; border: 2px solid var(--surface2); transition: border-color var(--transition);
}
.photo-thumb:hover { border-color: var(--primary); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb-actions {
  position: absolute; top: 4px; right: 4px; display: flex; gap: 2px;
  opacity: 0; transition: opacity var(--transition);
}
.photo-thumb:hover .photo-thumb-actions { opacity: 1; }
.photo-thumb-btn {
  width: 24px; height: 24px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: .65rem;
  background: rgba(0,0,0,.7); color: #fff;
}
.photo-thumb-btn.delete:hover { background: var(--error); }
.photo-upload-area {
  border: 2px dashed var(--surface2); border-radius: var(--radius-sm); padding: 1.5rem;
  text-align: center; cursor: pointer; transition: border-color var(--transition), background var(--transition);
}
.photo-upload-area:hover, .photo-upload-area.dragover { border-color: var(--primary); background: var(--primary-light); }

/* ─── Lightbox ─── */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 4000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .3s ease; cursor: zoom-out;
}
.lightbox-overlay.active { opacity: 1; }
.lightbox-content { position: relative; max-width: 95vw; max-height: 95vh; }
.lightbox-img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: var(--radius-sm); }
.lightbox-close {
  position: absolute; top: -40px; right: 0; width: 36px; height: 36px;
  border-radius: 50%; background: rgba(255,255,255,.15); border: none; color: #fff;
  font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.lightbox-caption { text-align: center; color: var(--text2); margin-top: .5rem; font-size: .85rem; }

/* ─── Timeline / Edit History ─── */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: var(--surface2); }
.timeline-item { position: relative; margin-bottom: 1rem; padding-left: .75rem; }
.timeline-item::before {
  content: ''; position: absolute; left: -1.5rem; top: 6px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary); border: 2px solid var(--surface);
}
.timeline-item-time { font-size: .75rem; color: var(--text3); }
.timeline-item-user { font-weight: 600; font-size: .85rem; }
.timeline-item-content { font-size: .85rem; color: var(--text2); margin-top: .25rem; }

/* ─── Collapsible ─── */
.collapsible-toggle { cursor: pointer; display: flex; align-items: center; gap: .5rem; }
.collapsible-toggle::before { content: '▶'; font-size: .7rem; transition: transform .2s; }
.collapsible-toggle.open::before { transform: rotate(90deg); }
.collapsible-content { max-height: 0; overflow: hidden; transition: max-height .3s ease; }
.collapsible-content.open { max-height: 2000px; }

/* ─── Filter Bar ─── */
.filter-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem;
  padding: 1rem; background: var(--surface); border-radius: var(--radius); margin-bottom: 1rem;
  border: 1px solid var(--glass-border);
}
.filter-bar .form-control { font-size: .8rem; padding: .5rem .75rem; }

/* ─── SOAP Card ─── */
.soap-card {
  background: var(--surface); border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: .75rem; transition: all var(--transition);
}
.soap-card:hover { border-color: var(--primary); transform: translateX(4px); }
.soap-card-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.soap-card-title { font-weight: 600; font-size: .95rem; }
.soap-card-meta { font-size: .8rem; color: var(--text3); }
.soap-section { margin-bottom: .5rem; }
.soap-section-label { font-size: .75rem; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }
.soap-section-content { font-size: .85rem; color: var(--text2); white-space: pre-wrap; }

/* ─── SOAP Detail in Modal ─── */
.soap-detail-grid { display: grid; gap: 1rem; }
.soap-detail-field { padding: .75rem; background: var(--bg); border-radius: var(--radius-sm); }
.soap-detail-label { font-size: .75rem; font-weight: 600; color: var(--primary); text-transform: uppercase; margin-bottom: .25rem; letter-spacing: .5px; }
.soap-detail-value { font-size: .9rem; white-space: pre-wrap; }

/* ─── Login Page ─── */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%); }
.login-card { width: 100%; max-width: 400px; padding: 2rem; background: var(--glass); backdrop-filter: blur(20px); border: 1px solid var(--glass-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { background: linear-gradient(135deg, var(--primary), #60a5fa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.login-logo p { color: var(--text3); font-size: .85rem; margin-top: .5rem; }

/* ─── View Toggle (Patient List / Input) ─── */
.view-toggle { display: flex; background: var(--surface); border-radius: var(--radius-sm); padding: 3px; gap: 3px; margin-bottom: 1rem; }
.view-toggle-btn {
  flex: 1; padding: .5rem; border: none; background: transparent; color: var(--text3);
  border-radius: 6px; cursor: pointer; font-size: .85rem; font-weight: 500; transition: all var(--transition); font-family: inherit;
}
.view-toggle-btn.active { background: var(--primary); color: #fff; }

/* ─── Avatars ─── */
.avatar-stack { display: flex; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: .65rem; font-weight: 700;
  border: 2px solid var(--surface); margin-left: -8px;
}
.avatar:first-child { margin-left: 0; }

/* ─── Load More ─── */
.load-more { text-align: center; padding: 1rem; }

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease; }
.slide-up { animation: slideUp .3s ease; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  h1 { font-size: 1.35rem; }
  .navbar { padding: .5rem .75rem; }
  .modal { max-height: 95vh; border-radius: var(--radius-sm); }
  .modal-overlay { padding: .5rem; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .table-wrapper { font-size: .8rem; }
  th, td { padding: .5rem; }
  .modal-lg { max-width: 100%; }
}
@media (max-width: 480px) {
  .filter-bar { grid-template-columns: 1fr; }
  .radio-group { flex-direction: column; }
  .view-toggle { flex-direction: row; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }
}
@media (min-width: 1024px) {
  .container { padding: 0 2rem; }
}
