/* ==========================================================================
   MedCRM — هوية بصرية فاتحة ونظيفة (عيادة / طبي)
   ========================================================================== */

:root {
  --bg: #f5f8fa;
  --bg-alt: #eef3f6;
  --surface: #ffffff;
  --surface-2: #f8fbfc;
  --border: #e2e9ee;
  --border-2: #cfdbe3;

  --ink: #0f2a35;
  --ink-2: #33525f;
  --muted: #6b8494;
  --muted-2: #94a9b5;

  --brand: #0d7f86;
  --brand-2: #0b6b72;
  --brand-soft: #e3f4f4;
  --accent: #7c3aed;
  --accent-soft: #f1e9fe;

  --ok: #12855a;
  --ok-soft: #e2f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --danger: #c53030;
  --danger-soft: #fdeaea;
  --info: #1f6fb2;
  --info-soft: #e6f1fa;

  --shadow-sm: 0 1px 2px rgba(15, 42, 53, .06), 0 1px 3px rgba(15, 42, 53, .04);
  --shadow: 0 2px 6px rgba(15, 42, 53, .07), 0 8px 24px -12px rgba(15, 42, 53, .12);
  --shadow-lg: 0 12px 40px -12px rgba(15, 42, 53, .22);

  --r-sm: 7px;
  --r: 11px;
  --r-lg: 16px;
  --sidebar-w: 244px;
  --font: "Segoe UI", "Noto Kufi Arabic", "Tahoma", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 700; line-height: 1.35; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.03rem; }
p { margin: 0 0 .8em; }
small { color: var(--muted); }
code { background: var(--bg-alt); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------------------------------- App shell ---------------------------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  border-inline-end: none;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 14px; border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 38px;
  background: linear-gradient(145deg, #0d7f86, #14a3a0);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  box-shadow: 0 4px 12px -4px rgba(13, 127, 134, .55);
}
.brand-text strong { display: block; font-size: 15px; }
.brand-text span { display: block; font-size: 11.5px; color: var(--muted); }

.nav { padding: 10px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav__section { font-size: 11px; color: var(--muted-2); font-weight: 700; padding: 12px 10px 4px; letter-spacing: .3px; }
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600; font-size: 13.6px;
  transition: background .13s, color .13s;
}
.nav__item:hover { background: var(--bg-alt); text-decoration: none; color: var(--ink); }
.nav__item.is-active { background: var(--brand-soft); color: var(--brand-2); }
.nav__item .ico { width: 18px; text-align: center; opacity: .85; font-size: 15px; }
.nav__item .badge-n { margin-inline-start: auto; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 59px; flex: 0 0 59px;
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  position: sticky; top: 0; z-index: 40;
}
.topbar__search { flex: 1 1 auto; max-width: 560px; position: relative; }
.topbar__search input {
  width: 100%; padding: 8px 34px 8px 12px; border: 1px solid var(--border-2);
  border-radius: 999px; background: var(--surface-2); font-family: inherit; font-size: 13.5px;
}
.topbar__search input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
.topbar__search .s-ico { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.topbar__actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 20px 22px 60px; max-width: 1560px; width: 100%; }

/* ---------------------------------- Cards ---------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.card__head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card__head h2, .card__head h3 { margin: 0; font-size: 15px; }
.card__head .spacer { margin-inline-start: auto; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__foot { padding: 11px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r) var(--r); }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1080px) { .grid--sidebar { grid-template-columns: 1fr; } }

/* ---------------------------------- KPI ---------------------------------- */
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px 15px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi__label { font-size: 12.3px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi__value { font-size: 25px; font-weight: 800; letter-spacing: -.5px; margin-top: 3px; }
.kpi__sub { font-size: 12px; color: var(--muted); }
.kpi__bar { position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.kpi--ok .kpi__bar { background: var(--ok); }
.kpi--warn .kpi__bar { background: var(--warn); }
.kpi--danger .kpi__bar { background: var(--danger); }
.kpi--accent .kpi__bar { background: var(--accent); }

/* ---------------------------------- Tables ---------------------------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.4px; }
table.tbl th {
  text-align: start; padding: 9px 12px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); font-weight: 700; color: var(--ink-2);
  white-space: nowrap; font-size: 12.6px;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--brand-soft); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl .num { text-align: end; font-variant-numeric: tabular-nums; }
table.tbl .nowrap { white-space: nowrap; }
table.tbl .actions { white-space: nowrap; text-align: end; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; opacity: .35; display: block; margin-bottom: 6px; }

/* ---------------------------------- Badges / chips ---------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.7px; font-weight: 700;
  background: var(--bg-alt); color: var(--ink-2); white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--brand { background: var(--brand-soft); color: var(--brand-2); }
.badge--accent { background: var(--accent-soft); color: var(--accent); }
.badge--dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-n {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 800;
}
.badge-n--soft { background: var(--bg-alt); color: var(--ink-2); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border: 1px solid var(--border-2); border-radius: 999px; background: var(--surface);
  font-size: 12.4px; color: var(--ink-2); font-weight: 600;
}
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------------------------- Forms ---------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 12px 14px; }
.form-grid--wide { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: 12.4px; font-weight: 700; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.field label .req { color: var(--danger); }
.field .hint { font-size: 11.4px; color: var(--muted); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 13.6px; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface); width: 100%;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.field input:disabled, .field select:disabled { background: var(--bg-alt); color: var(--muted); }
.field-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.checkline { display: flex; align-items: center; gap: 7px; font-size: 13.2px; }
.checkline input { width: auto; }

/* ---------------------------------- Buttons ---------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2); font-family: inherit;
  font-size: 13.3px; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--bg-alt); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn--accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--accent:hover { background: #6d28d9; }
.btn--ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn--danger { background: var(--danger-soft); border-color: #f3c7c7; color: var(--danger); }
.btn--danger:hover { background: #fbdcdc; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn--sm { padding: 5px 10px; font-size: 12.4px; }
.btn--xs { padding: 3px 8px; font-size: 11.8px; border-radius: 6px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------- Toolbar / filters ---------------------------------- */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 11px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); margin-bottom: 14px;
}
.toolbar .grow { flex: 1 1 180px; min-width: 150px; }
.toolbar input, .toolbar select {
  font-family: inherit; font-size: 13.3px; padding: 7px 10px;
  border: 1px solid var(--border-2); border-radius: var(--r-sm); background: var(--surface);
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---------------------------------- Timeline ---------------------------------- */
.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 15px; }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: -20px; top: 5px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--brand-soft);
}
.tl-item--warn::before { background: var(--warn); box-shadow: 0 0 0 2px var(--warn-soft); }
.tl-item--danger::before { background: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.tl-item--ok::before { background: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); }
.tl-item__meta { font-size: 11.7px; color: var(--muted); }
.tl-item__body { font-size: 13.3px; }

/* ---------------------------------- Stat rows ---------------------------------- */
.stat-list { display: flex; flex-direction: column; gap: 9px; }
.stat-row { display: flex; align-items: center; gap: 10px; font-size: 13.2px; }
.stat-row__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row__bar { flex: 0 0 96px; height: 7px; background: var(--bg-alt); border-radius: 99px; overflow: hidden; }
.stat-row__bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.stat-row__val { flex: 0 0 auto; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 42px; text-align: end; }

/* ---------------------------------- Tabs ---------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 14px; font-size: 13.4px; font-weight: 700; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.is-active { color: var(--brand-2); border-bottom-color: var(--brand); }

/* ---------------------------------- Alerts ---------------------------------- */
.alert { padding: 10px 14px; border-radius: var(--r-sm); font-size: 13.3px; margin-bottom: 14px; border: 1px solid; }
.alert--ok { background: var(--ok-soft); border-color: #bfe6d3; color: #0b5c40; }
.alert--warn { background: var(--warn-soft); border-color: #f2ddb4; color: #7d5310; }
.alert--danger { background: var(--danger-soft); border-color: #f3c7c7; color: #96201f; }
.alert--info { background: var(--info-soft); border-color: #c4dcf0; color: #14527f; }

/* ---------------------------------- Modal ---------------------------------- */
dialog.modal {
  border: 0; border-radius: var(--r-lg); padding: 0; box-shadow: var(--shadow-lg);
  width: min(720px, 94vw); max-height: 92vh; background: var(--surface); color: var(--ink);
}
dialog.modal::backdrop { background: rgba(15, 42, 53, .34); backdrop-filter: blur(2px); }
dialog.modal .card__head { position: sticky; top: 0; background: var(--surface); z-index: 2; border-radius: var(--r-lg) var(--r-lg) 0 0; }
dialog.modal .card__foot { position: sticky; bottom: 0; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------------------------------- Voice input ---------------------------------- */
.voice-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 9px; border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--surface); font-size: 12px; font-weight: 700; color: var(--ink-2); cursor: pointer;
}
.voice-btn.is-live { background: var(--danger-soft); border-color: #f0b4b4; color: var(--danger); animation: pulse 1.3s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(197,48,48,.35); } 50% { box-shadow: 0 0 0 6px rgba(197,48,48,0); } }
.voice-wrap { position: relative; }
.voice-wrap textarea { padding-bottom: 30px; }
.voice-wrap .voice-btn { position: absolute; inset-inline-end: 7px; bottom: 7px; }

/* ---------------------------------- Notifications ---------------------------------- */
.notif-panel {
  position: absolute; inset-inline-end: 0; top: 46px; width: 360px; max-height: 460px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-lg); z-index: 60;
}
.notif-item { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.1px; display: flex; gap: 9px; }
.notif-item:hover { background: var(--bg-alt); }
.notif-item.is-unread { background: var(--brand-soft); }
.notif-item__ico { flex: 0 0 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); }
.notif-item__body { min-width: 0; }
.notif-item__time { font-size: 11.4px; color: var(--muted); }

/* ---------------------------------- Search dropdown ---------------------------------- */
.search-results {
  position: absolute; top: 44px; inset-inline-start: 0; inset-inline-end: 0; max-height: 460px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-lg); z-index: 50;
}
.sr-group { padding: 8px 13px 3px; font-size: 11.4px; font-weight: 800; color: var(--muted-2); }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 8px 13px; font-size: 13.3px; }
.sr-item:hover, .sr-item.is-sel { background: var(--brand-soft); text-decoration: none; }
.sr-item .sr-main { min-width: 0; }
.sr-item .sr-main strong { display: block; font-size: 13.4px; font-weight: 700; color: var(--ink); }
.sr-item .sr-main span { font-size: 11.8px; color: var(--muted); }

/* ---------------------------------- Avatar ---------------------------------- */
.avatar {
  width: 32px; height: 32px; border-radius: 9px; display: inline-grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 12.5px; flex: 0 0 32px;
}
.avatar--sm { width: 26px; height: 26px; flex-basis: 26px; font-size: 11px; border-radius: 8px; }
.avatar--lg { width: 46px; height: 46px; flex-basis: 46px; font-size: 16px; border-radius: 13px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--border); }
.user-chip:hover { background: var(--bg-alt); text-decoration: none; }

/* ---------------------------------- Misc ---------------------------------- */
.muted { color: var(--muted); }
.tiny { font-size: 11.8px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: end; }
.center { text-align: center; }
.strong { font-weight: 700; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.mt0 { margin-top: 0; } .mt1 { margin-top: 8px; } .mt2 { margin-top: 16px; }
.mb0 { margin-bottom: 0; } .mb1 { margin-bottom: 8px; } .mb2 { margin-bottom: 16px; }
.pill-live { display: inline-flex; align-items: center; gap: 5px; font-size: 11.6px; color: var(--ok); font-weight: 700; }
.pill-live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 5px 12px; font-size: 13.3px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.hstack { display: flex; gap: 14px; flex-wrap: wrap; }
.vstack { display: flex; flex-direction: column; gap: 12px; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.scroll-y { max-height: 420px; overflow-y: auto; }
.tag-src { font-size: 11.5px; color: var(--muted); }

/* ---------------------------------- Login ---------------------------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1100px 460px at 82% -8%, #dff3f2 0%, transparent 62%),
    radial-gradient(900px 420px at 8% 108%, #eae4fb 0%, transparent 58%),
    var(--bg);
}
.login-card { width: min(925px, 100%); display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--border); }
.login-side { padding: 30px 28px; background: linear-gradient(160deg, #0d7f86 0%, #0b6b72 55%, #0a5b62 100%); color: #eafcfb; }
.login-side h2 { color: #fff; }
.login-side ul { padding-inline-start: 18px; margin: 0; font-size: 13.4px; line-height: 1.95; opacity: .95; }
.login-form { padding: 30px 28px; }
.quick-user { display: flex; align-items: center; gap: 9px; width: 100%; text-align: start; padding: 7px 9px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-family: inherit; font-size: 13px; }
.quick-user:hover { background: var(--brand-soft); border-color: var(--brand); }
@media (max-width: 780px) { .login-card { grid-template-columns: 1fr; } .login-side { display: none; } }

/* ---------------------------------- Print ---------------------------------- */
@media print {
  .sidebar, .topbar, .toolbar, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
}
