:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --primary-hover: #1d4ed8;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #ba1a1a;
  --danger-bg: #ffdad6;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 18px;
}

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

html,
body {
  font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

/* Login Screen */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-brand img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1px solid rgba(37, 99, 235, 0.2);
  object-fit: contain;
  padding: 4px;
}

.login-brand h1 {
  font-size: 20px;
  font-weight: 700;
}

.login-brand p {
  font-size: 13px;
  color: var(--text-muted);
}

.demo-hint {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* App Shell */
.portal-shell {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}

.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.sidebar-brand img {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(37, 99, 235, 0.2);
  object-fit: contain;
  padding: 3px;
}

.sidebar-clinic-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-clinic-sub {
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 600;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.nav-item:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.nav-item.active {
  background: rgba(219, 234, 254, 0.65);
  border-color: rgba(37, 99, 235, 0.24);
  color: var(--primary);
  font-weight: 700;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

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

.topbar {
  height: 66px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title h2 {
  font-size: 18px;
  font-weight: 700;
}

.menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content-wrap {
  padding: 22px 24px 40px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
  color: var(--text);
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 600;
  margin-top: 2px;
}

.icon-box {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(219, 234, 254, 0.65);
  border: 1px solid rgba(37, 99, 235, 0.16);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Card & Toolbar */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 18px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

/* Forms & Buttons */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input,
.select,
.textarea {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.14s ease;
}

.textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 9px;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-soft {
  background: rgba(219, 234, 254, 0.7);
  color: var(--primary);
}

.btn-soft:hover {
  background: var(--primary-soft);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-subtle);
}

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

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

/* Badges & Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.pill-confirmed,
.pill-completed {
  background: var(--success-bg);
  color: var(--success);
}

.pill-pending,
.pill-rescheduled {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--amber-border);
}

.pill-cancelled,
.pill-rejected {
  background: var(--danger-bg);
  color: var(--danger);
}

.pill-morning {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--amber-border);
}

.pill-evening {
  background: rgba(219, 234, 254, 0.65);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.18);
}

/* Table */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: right;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Grid Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.slot-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.slot-chip.blocked {
  background: var(--surface-subtle);
  opacity: 0.72;
}

.slot-chip.booked {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(219, 234, 254, 0.25);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 22px;
  background: var(--text);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  z-index: 90;
}

.toast.error {
  background: var(--danger);
}

.empty-box {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    right: -280px;
    top: 0;
    z-index: 50;
    transition: right 0.2s ease;
  }

  .sidebar.open {
    right: 0;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .topbar {
    padding: 0 14px;
  }

  .content-wrap {
    padding: 16px 14px 32px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}
