/* MediCore Enterprise Responsive Healthcare Design System */
:root {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --secondary: #0f766e;
  --secondary-light: #ccfbf1;
  --accent: #6366f1;
  --surface: #ffffff;
  --background: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --radius: 0.75rem;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Cairo", "Tajawal", sans-serif;
  background-color: var(--background);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 15px;
}

/* Directional layouts */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}
[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

/* Layout structure */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background-color: #0f172a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #38bdf8;
}

.sidebar-subbrand {
  font-size: 0.75rem;
  color: #94a3b8;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: #94a3b8;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.15s ease-in-out;
}

.nav-item:hover, .nav-item.active {
  color: #ffffff;
  background-color: #1e293b;
  border-inline-start: 4px solid var(--primary);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.top-bar {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: #ffffff;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: #f1f5f9;
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}

.content-body {
  padding: 1.5rem;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background-color: var(--surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}

.kpi-title {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Cards & Tables */
.card {
  background-color: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.card-body {
  padding: 1.25rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: inherit;
}

th {
  background-color: #f8fafc;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.85rem 1rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

tr:hover td {
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 9999px;
}

.badge-success { background-color: var(--success-bg); color: var(--success); }
.badge-warning { background-color: var(--warning-bg); color: var(--warning); }
.badge-danger { background-color: var(--danger-bg); color: var(--danger); }
.badge-info { background-color: var(--primary-light); color: var(--primary); }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background-color: #ffffff;
  color: var(--text-main);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Timeline */
.timeline {
  position: relative;
  padding-inline-start: 1.5rem;
  border-inline-start: 2px solid var(--border);
  margin-inline-start: 0.5rem;
}

.timeline-item {
  position: relative;
  margin-bottom: 1.5rem;
}

.timeline-dot {
  position: absolute;
  inset-inline-start: -1.95rem;
  top: 0.25rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--primary);
  border: 3px solid #ffffff;
}

.timeline-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.timeline-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

/* Printable Prescription */
@media print {
  .sidebar, .top-bar, .no-print, .btn {
    display: none !important;
  }
  .app-container {
    display: block;
  }
  .main-content {
    margin: 0;
    padding: 0;
  }
  .printable-prescription {
    border: 2px solid #000;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    font-size: 13pt;
  }
}

/* ---------------------------------------------------------------- v1.1 additions */
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.35rem 0.6rem; font-size: 1.1rem; cursor: pointer; }
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-info { background: var(--primary-light); color: var(--primary-dark); }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: mc-spin .7s linear infinite; vertical-align: middle; }
@keyframes mc-spin { to { transform: rotate(360deg); } }
.btn[disabled] { opacity: .6; cursor: wait; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.week-day { display: block; text-align: center; padding: .6rem .25rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; color: var(--text-main); font-size: .8rem; }
.week-day.active { border-color: var(--primary); background: var(--primary-light); font-weight: 700; }
.week-day .count { display: block; font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.filters .form-group { margin: 0; min-width: 160px; }
.user-box a { color: #38bdf8; text-decoration: none; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--background); }
.login-card { width: 100%; max-width: 400px; }
dialog.mc-dialog { border: none; border-radius: var(--radius); padding: 1.25rem; width: min(440px, 92vw); box-shadow: var(--card-shadow); }
dialog.mc-dialog::backdrop { background: rgb(15 23 42 / .45); }

@media (max-width: 900px) {
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar-nav, .sidebar .user-box { display: none; }
  .sidebar.open .sidebar-nav, .sidebar.open .user-box { display: block; }
  .sidebar-header { justify-content: space-between; padding: .75rem 1rem; }
  .menu-toggle { display: inline-block; color: #f8fafc; border-color: #334155; }
  .top-bar { flex-wrap: wrap; gap: .5rem; padding: .75rem 1rem; }
  .page-title { font-size: 1.05rem; }
  .content-body { padding: 1rem; }
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .week-strip { grid-template-columns: repeat(7, minmax(44px, 1fr)); overflow-x: auto; }
  .filters .form-group { min-width: 100%; }
  table { font-size: .8rem; }
  th, td { padding: .5rem .6rem; }
}

/* notifications + field errors (v1.1.1) */
#mcToasts { position: fixed; top: 1rem; inset-inline: 0; margin-inline: auto; width: min(560px, calc(100vw - 2rem)); z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; }
.mc-toast { display: flex; align-items: flex-start; gap: .75rem; padding: .85rem 1rem; border-radius: var(--radius);
  box-shadow: 0 10px 25px -5px rgb(0 0 0 / .25); font-size: .9rem; font-weight: 600; animation: mc-in .2s ease-out; }
.mc-toast-msg { flex: 1; white-space: pre-line; }
.mc-toast-success { background: #16a34a; color: #fff; }
.mc-toast-error { background: #dc2626; color: #fff; }
.mc-toast-info { background: #0369a1; color: #fff; }
.mc-toast-link { color: #fff; text-decoration: underline; white-space: nowrap; }
.mc-toast-close { background: none; border: none; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; }
@keyframes mc-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.form-control.is-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-bg); }

/* date-range filter bar, sorting, pagination, empty states (v1.2) */
.mc-filterbar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; }
.mc-filterbar .form-group { margin: 0; min-width: 150px; flex: 0 1 auto; }
.mc-filter-dates, .mc-filter-extra { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.mc-filter-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.mc-filter-summary { flex-basis: 100%; font-size: .85rem; color: var(--text-main); }
.mc-filter-error { flex-basis: 100%; color: var(--danger); background: var(--danger-bg); border-radius: var(--radius); padding: .5rem .75rem; font-weight: 600; font-size: .85rem; }
.mc-filter-error[hidden] { display: none; }
.mc-hint { color: var(--text-muted); font-size: .78rem; font-weight: 400; }
input[type=date].form-control { min-width: 150px; }
.mc-sort { color: inherit; text-decoration: none; white-space: nowrap; }
.mc-sort.active { color: var(--primary); }
.mc-pager { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.mc-pager-links { display: flex; gap: .35rem; align-items: center; }
.mc-perpage select { margin-inline-start: .35rem; padding: .2rem; border: 1px solid var(--border); border-radius: 6px; }
.mc-empty { text-align: center; color: var(--text-muted); padding: 2rem 1rem !important; }
.mc-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.mc-chip { display: inline-flex; gap: .4rem; align-items: center; padding: .35rem .7rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: .8rem; text-decoration: none; color: var(--text-main); }
.mc-chip.active { border-color: var(--primary); background: var(--primary-light); font-weight: 700; }
.mc-chip b { color: var(--primary); }
.mc-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.mc-tabs a { padding: .6rem 1rem; text-decoration: none; color: var(--text-muted); border-bottom: 3px solid transparent; font-weight: 600; }
.mc-tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.mc-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.mc-total { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; }
.mc-total .v { font-size: 1.2rem; font-weight: 800; }
.mc-total .l { font-size: .75rem; color: var(--text-muted); }
.mc-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mc-notice { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .88rem; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.btn.is-loading { opacity: .7; pointer-events: none; }
.btn.is-loading::after { content: ""; display: inline-block; width: .8em; height: .8em; margin-inline-start: .4em; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: mc-spin .7s linear infinite; vertical-align: -.1em; }
@keyframes mc-spin { to { transform: rotate(360deg); } }
.mc-bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: .5rem 0; direction: ltr; }
.mc-bars .bar { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 1px; position: relative; }
.mc-bars .bar:hover { opacity: .8; }
@media (max-width: 900px) {
  .mc-filterbar { padding: .75rem; }
  .mc-filter-dates { width: 100%; }
  .mc-filterbar .form-group { min-width: calc(50% - .5rem); flex: 1 1 calc(50% - .5rem); }
  .mc-filter-dates .form-group:first-child { flex-basis: 100%; }
  .mc-filter-actions { width: 100%; }
  .mc-filter-actions .btn { flex: 1; justify-content: center; }
  .mc-pager { justify-content: center; }
}

/* unified date input + multi-period search (v1.4) */
.mc-date { position: relative; display: inline-flex; align-items: center; width: 100%; min-width: 150px; }
.mc-date .mc-date-text { width: 100%; padding-inline-end: 2.2rem; font-variant-numeric: tabular-nums; }
.mc-date .mc-date-btn { position: absolute; inset-inline-end: .3rem; background: none; border: none; cursor: pointer; font-size: 1rem; padding: .2rem; }
.mc-date .mc-date-native { position: absolute; inset-inline-end: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.mc-periods { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.mc-periods[hidden] { display: none; }
.mc-chip-x { background: none; border: none; cursor: pointer; font-size: 1rem; line-height: 1; color: var(--danger); padding: 0 .15rem; }
.mc-pdot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; }
.mc-pdot.p0, .mc-pbar.p0 { background: #0284c7; } .mc-pdot.p1, .mc-pbar.p1 { background: #7c3aed; } .mc-pdot.p2, .mc-pbar.p2 { background: #059669; }
.mc-pdot.p3, .mc-pbar.p3 { background: #d97706; } .mc-pdot.p4, .mc-pbar.p4 { background: #db2777; } .mc-pdot.p5, .mc-pbar.p5 { background: #475569; }
.mc-cal-period { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; background: var(--surface); }
.mc-cal-period > header { display: flex; gap: .5rem; align-items: center; padding: .6rem .9rem; border-bottom: 1px solid var(--border); font-weight: 700; }
.mc-cal-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; padding: .75rem; }
.mc-cal-day { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mc-cal-day > .h { display: flex; justify-content: space-between; padding: .35rem .6rem; background: var(--primary-light); font-weight: 700; font-size: .8rem; }
.mc-cal-day ul { list-style: none; margin: 0; padding: .3rem .5rem; font-size: .78rem; }
.mc-cal-day li { padding: .2rem 0; border-bottom: 1px dashed var(--border); display: flex; gap: .4rem; }
.mc-cal-day li:last-child { border-bottom: 0; }
.mc-pbar { display: inline-block; width: 4px; align-self: stretch; border-radius: 2px; }
.mc-viewtoggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mc-viewtoggle a { padding: .4rem .8rem; text-decoration: none; color: var(--text-main); font-size: .85rem; }
.mc-viewtoggle a.active { background: var(--primary); color: #fff; }
.mc-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.mc-month-head { text-align: center; font-weight: 700; font-size: .8rem; color: var(--text-muted); padding: .3rem 0; }
.mc-month-cell { min-height: 74px; border: 1px solid var(--border); border-radius: 8px; padding: .3rem .4rem; background: var(--surface);
  text-decoration: none; color: var(--text-main); display: flex; flex-direction: column; gap: .1rem; font-size: .8rem; }
.mc-month-cell.empty { background: transparent; border-style: dashed; opacity: .4; }
.mc-month-cell.has { border-color: var(--primary); }
.mc-month-cell.today { box-shadow: 0 0 0 2px var(--primary) inset; }
.mc-month-cell .d { font-weight: 700; } .mc-month-cell .n { font-size: 1.15rem; font-weight: 800; color: var(--primary); }
@media (max-width: 600px) { .mc-month-cell { min-height: 54px; padding: .2rem; font-size: .7rem; } .mc-month-cell .n { font-size: .95rem; } }

/* v1.4b unified date + time */
.mc-datetime { position: relative; display: flex; gap: .4rem; align-items: center; width: 100%; }
.mc-datetime .mc-date { flex: 1 1 auto; min-width: 140px; }
.mc-datetime > .mc-date-native { position: absolute; inset-inline-end: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.mc-datetime .mc-time-text { flex: 0 0 5.2rem; width: 5.2rem; text-align: center; font-variant-numeric: tabular-nums; }
