/* ═══════════════════════════════════════════════════════
   GastroEMR — style.css
   Design Tokens + Components + Layout
   ═══════════════════════════════════════════════════════ */

/* ── TOKENS ── */
:root {
  --navy:        #0B1F3A;
  --navy-light:  #132845;
  --teal:        #0A7C7C;
  --teal-light:  #0EA5A5;
  --teal-ghost:  #EBF8F8;
  --teal-border: #B2E8E8;
  --slate:       #4A5568;
  --slate-light: #718096;
  --border:      #E2E8F0;
  --bg-page:     #F0F4F8;
  --white:       #FFFFFF;
  --success:     #059669;
  --success-bg:  #ECFDF5;
  --warn:        #D97706;
  --warn-bg:     #FFFBEB;
  --danger:      #DC2626;
  --danger-bg:   #FEF2F2;
  --purple:      #7C3AED;
  --purple-bg:   #F5F3FF;

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.18);
  --font:        'Noto Sans Arabic', 'Segoe UI', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--navy);
  direction: rtl;
  min-height: 100vh;
}

button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); }

/* ══════════════════════════════════════════════
   PAGE SYSTEM
══════════════════════════════════════════════ */
.page        { display: none; }
.page.active { display: flex; }

/* ══════════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════════ */
#page-login {
  min-height: 100vh;
  background: var(--navy);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-wrapper  { width: 100%; max-width: 420px; }

.login-logo     { text-align: center; margin-bottom: 36px; }

.logo-icon {
  width: 72px; height: 72px;
  border-radius: 18px;
  background: var(--teal);
  font-size: 38px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 24px rgba(10,124,124,0.4);
}

.login-title    { color: var(--white); font-size: 28px; font-weight: 800; }
.login-subtitle { color: #64748B; font-size: 13px; margin-top: 6px; }

.login-card {
  background: var(--navy-light);
  border-radius: var(--radius-lg);
  padding: 32px;
  border: 1px solid #1E3A5F;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-security-note {
  text-align: center;
  font-size: 11px;
  color: #64748B;
  background: #0B1F3A;
  border: 1px solid #1E3A5F;
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 4px;
}

/* ══════════════════════════════════════════════
   APP LAYOUT (sidebar + main)
══════════════════════════════════════════════ */
#page-app {
  min-height: 100vh;
  flex-direction: row;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 240px;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 22px 18px;
  border-bottom: 1px solid #1E3A5F;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-app-name { color: var(--white); font-size: 16px; font-weight: 800; }
.sidebar-app-sub  { color: #64748B; font-size: 10px; margin-top: 1px; }

/* Nav items */
.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: #94A3B8;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover         { background: rgba(255,255,255,0.06); color: var(--white); }
.nav-item.active        { background: var(--teal); color: var(--white); }
.nav-icon               { font-size: 18px; }

/* User footer */
.sidebar-user {
  padding: 14px 16px;
  border-top: 1px solid #1E3A5F;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-info { flex: 1; }
.sidebar-user-name { color: var(--white); font-size: 13px; font-weight: 600; }
.sidebar-user-role { color: #64748B; font-size: 11px; }

.btn-icon {
  background: none; border: none;
  color: #64748B; font-size: 18px;
  cursor: pointer; padding: 4px;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--white); }

/* ── MAIN WRAPPER ── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top bar */
.topbar {
  background: var(--white);
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
}

.topbar-breadcrumb { font-size: 13px; color: var(--slate-light); font-weight: 500; }

.topbar-status { display: flex; align-items: center; gap: 8px; }
.status-dot    { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.status-label  { font-size: 12px; color: var(--success); font-weight: 600; }

/* Content area */
.content-area { flex: 1; overflow-y: auto; padding: 28px; }

/* ── SECTIONS ── */
.section        { display: none; }
.section.active { display: block; }

/* ══════════════════════════════════════════════
   COMMON COMPONENTS
══════════════════════════════════════════════ */

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}
.page-title    { font-size: 22px; font-weight: 700; color: var(--navy); }
.page-subtitle { color: var(--slate-light); font-size: 13px; margin-top: 4px; }

/* Card */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card.p0     { padding: 0; }
.card-dark   {
  background: var(--navy);
  color: var(--white);
  border-color: transparent;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--navy); }
.card-dark .card-title { color: var(--white); }

/* Section title */
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 18px;
}

/* Buttons */
.btn {
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.btn-primary   { background: var(--teal); color: var(--white); border-color: var(--teal); }
.btn-primary:hover   { background: var(--teal-light); }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-page); }
.btn-danger    { background: var(--danger); color: var(--white); }
.btn-ghost     { background: transparent; color: var(--teal); border-color: transparent; }
.btn-ghost:hover { background: var(--teal-ghost); }
.btn-full      { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }
.btn-sm        { padding: 6px 14px; font-size: 12px; }
.btn-back {
  background: none; border: none;
  color: var(--teal); font-weight: 600;
  font-size: 14px; margin-bottom: 20px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; padding: 0;
}
.btn-back:hover { color: var(--teal-light); }

/* Badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge-teal    { background: var(--teal-ghost);  color: var(--teal); }
.badge-success { background: var(--success-bg);  color: var(--success); }
.badge-warn    { background: var(--warn-bg);     color: var(--warn); }
.badge-danger  { background: var(--danger-bg);   color: var(--danger); }
.badge-purple  { background: var(--purple-bg);   color: var(--purple); }
.badge-blood   { background: var(--teal-ghost);  color: var(--teal); font-family: monospace; font-weight: 800; }
.badge-chronic { background: var(--danger-bg);   color: var(--danger); }

/* Avatar */
.avatar {
  border-radius: 50%;
  background: var(--teal);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* Forms */
.form-group    { display: flex; flex-direction: column; gap: 6px; }
.form-label    { font-size: 13px; font-weight: 600; color: var(--navy); }
.form-input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--navy);
  outline: none;
  transition: border-color 0.15s;
  background: var(--white);
  direction: rtl;
  width: 100%;
}
.form-input:focus { border-color: var(--teal); }

/* Dark input (login) */
#page-login .form-input {
  background: var(--navy);
  border-color: #1E3A5F;
  color: var(--white);
}
#page-login .form-input:focus { border-color: var(--teal); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-full { grid-column: span 2; }

.required { color: var(--danger); }

/* Error */
.error-msg { font-size: 12px; color: var(--danger); font-weight: 600; margin-top: 4px; }

/* Search bar */
.search-bar {
  background: var(--white);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 18px;
  transition: border-color 0.15s;
}
.search-bar:focus-within { border-color: var(--teal); }
.search-icon    { color: var(--slate-light); font-size: 16px; }
.search-input   { border: none; outline: none; flex: 1; font-size: 14px; color: var(--navy); background: transparent; direction: rtl; }
.search-clear   { background: none; border: none; font-size: 18px; color: var(--slate-light); cursor: pointer; line-height: 1; }

/* Table */
.table-wrapper { background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--border); overflow: hidden; }

.data-table   { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--slate-light);
  text-align: right;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  font-size: 13px;
  color: var(--slate);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--teal-ghost); }
.data-table tr:last-child td { border-bottom: none; }

/* Patient cell */
.patient-cell { display: flex; align-items: center; gap: 10px; }
.patient-name { font-weight: 600; font-size: 14px; color: var(--navy); }
.patient-city { font-size: 11px; color: var(--slate-light); }

/* No results */
.no-results      { padding: 48px; text-align: center; }
.no-results-icon { font-size: 40px; }
.no-results-text { color: var(--slate-light); font-size: 14px; margin-top: 8px; }

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

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-top-width: 4px;
}
.stat-teal    { border-top-color: var(--teal);    }
.stat-purple  { border-top-color: var(--purple);  }
.stat-warn    { border-top-color: var(--warn);     }
.stat-success { border-top-color: var(--success);  }

.stat-value { font-size: 30px; font-weight: 800; }
.stat-teal   .stat-value { color: var(--teal);   }
.stat-purple .stat-value { color: var(--purple); }
.stat-warn   .stat-value { color: var(--warn);   }
.stat-success .stat-value{ color: var(--success);}

.stat-label { font-size: 13px; color: var(--slate); margin-top: 2px; }
.stat-delta { font-size: 11px; color: var(--slate-light); margin-top: 6px; }
.stat-icon  { font-size: 28px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
}
.dashboard-right { display: flex; flex-direction: column; gap: 16px; }

/* Appointment row */
.appt-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.appt-row:last-child { border-bottom: none; }
.appt-row.done { background: #FAFAFA; }

.appt-time {
  min-width: 54px;
  text-align: center;
  background: var(--teal-ghost);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
}
.appt-name { font-weight: 600; font-size: 14px; color: var(--navy); }
.appt-type { font-size: 12px; color: var(--slate-light); margin-top: 2px; }

/* KPI card */
.kpi-label         { font-size: 13px; color: #94A3B8; margin-bottom: 4px; }
.kpi-value         { font-size: 36px; font-weight: 800; color: var(--teal-light); }
.kpi-sub           { font-size: 12px; color: #64748B; margin-top: 8px; }
.kpi-progress-label{ font-size: 11px; color: #64748B; margin-top: 6px; }

/* Progress bars */
.progress-bar-track { height: 6px; background: #1E3A5F; border-radius: 999px; margin-top: 14px; }
.card:not(.card-dark) .progress-bar-track { background: var(--border); margin-top: 4px; }
.progress-bar-fill  { height: 100%; background: var(--teal); border-radius: 999px; transition: width 0.6s; }
.bg-teal   { background: var(--teal); }
.bg-purple { background: var(--purple); }
.bg-warn   { background: var(--warn); }

/* Endoscopy rows */
.endo-row  { margin-bottom: 14px; }
.endo-info { display: flex; justify-content: space-between; font-size: 12px; color: var(--slate); margin-bottom: 4px; }
.endo-name { }
.endo-count{ font-weight: 700; }

/* ══════════════════════════════════════════════
   PATIENT PROFILE
══════════════════════════════════════════════ */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.profile-info    { flex: 1; }
.profile-name    { font-size: 22px; font-weight: 700; color: var(--navy); margin-bottom: 8px; }
.profile-meta    { display: flex; gap: 20px; flex-wrap: wrap; }
.profile-meta span { font-size: 13px; color: var(--slate); }
.profile-conditions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.profile-actions { display: flex; gap: 10px; }

/* Tabs */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 4px;
  border: 1px solid var(--border);
  width: fit-content;
  margin-bottom: 16px;
}
.tab-btn {
  padding: 8px 22px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--slate);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn.active { background: var(--teal); color: var(--white); }

.tab-panel        { display: none; }
.tab-panel.active { display: block; }

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.info-cell {
  background: var(--bg-page);
  border-radius: var(--radius-md);
  padding: 14px;
}
.info-cell-label { font-size: 11px; color: var(--slate-light); margin-bottom: 4px; }
.info-cell-value { font-size: 14px; font-weight: 600; color: var(--navy); }

/* Consultation row */
.consult-row   { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.consult-row:last-child { border-bottom: none; }
.consult-top   { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.consult-left  { display: flex; gap: 10px; align-items: center; }
.consult-date  { background: var(--teal-ghost); color: var(--teal); font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 8px; }
.consult-grid  { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.consult-cell  { background: var(--bg-page); border-radius: 8px; padding: 12px; }
.consult-cell-label { font-size: 11px; color: var(--slate-light); margin-bottom: 4px; }
.consult-cell-value { font-size: 13px; color: var(--navy); }
.icd-badge     { background: var(--purple-bg); color: var(--purple); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }

/* Document row */
.doc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.doc-row:last-child { border-bottom: none; }
.doc-icon  { font-size: 28px; flex-shrink: 0; }
.doc-info  { flex: 1; }
.doc-title { font-weight: 600; font-size: 14px; color: var(--navy); }
.doc-meta  { font-size: 12px; color: var(--slate-light); margin-top: 2px; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--teal-border);
  border-radius: var(--radius-lg);
  padding: 36px;
  text-align: center;
  background: var(--teal-ghost);
  margin-bottom: 16px;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone.dragover { border-color: var(--teal); background: #D1F5F5; }
.upload-icon { font-size: 36px; margin-bottom: 10px; }
.upload-text { font-weight: 600; font-size: 14px; color: var(--navy); margin-bottom: 10px; }
.upload-hint { font-size: 11px; color: var(--slate-light); margin-top: 10px; }

/* Schedule row */
.schedule-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.schedule-row:last-child { border-bottom: none; }
.schedule-row.free { background: #FAFAFA; }
.schedule-time {
  min-width: 64px;
  text-align: center;
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 700;
}
.schedule-time.busy  { background: var(--teal-ghost); color: var(--teal); }
.schedule-time.free  { background: var(--border);     color: var(--slate-light); }
.schedule-free-label { color: var(--slate-light); font-size: 13px; font-style: italic; }

/* ══════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,31,58,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 620px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
.modal-title  { font-size: 17px; font-weight: 700; color: var(--navy); }
.modal-close  { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--slate-light); line-height: 1; }
.modal-body   { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ══════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════ */
.toast {
  position: fixed;
  top: 24px; left: 50%; transform: translateX(-50%);
  padding: 13px 28px;
  border-radius: 12px;
  font-weight: 600; font-size: 14px;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  white-space: nowrap;
}
.toast-success { background: var(--success); color: var(--white); }
.toast-error   { background: var(--danger);  color: var(--white); }

@keyframes toastIn {
  from { opacity: 0; top: 8px; }
  to   { opacity: 1; top: 24px; }
}

/* ══════════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════════ */
.hidden { display: none !important; }
.flex   { display: flex; }
.gap-2  { gap: 8px; }
.mt-1   { margin-top: 4px; }
.mt-2   { margin-top: 8px; }

/* ══════════════════════════════════════════════
   RESPONSIVE (tablets)
══════════════════════════════════════════════ */
@media (max-width: 960px) {
  .stats-grid           { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid       { grid-template-columns: 1fr; }
  .consult-grid         { grid-template-columns: 1fr; }
  .form-grid            { grid-template-columns: 1fr; }
  .form-full            { grid-column: span 1; }
  .info-grid            { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .sidebar              { display: none; }
  .stats-grid           { grid-template-columns: 1fr 1fr; }
  .content-area         { padding: 16px; }
}
