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

:root {
  --primary: #632F93;
  --primary-dark: #4a2270;
  --primary-light: #ede4f5;
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #f44336;
  --info: #2196f3;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e4e8ee;
  --border-light: #f0f3f7;
  --text: #1a2332;
  --text-muted: #5a6b7c;
  --text-light: #8a9aab;

  --booked-bg: #d8c9e8;
  --booked-border: #632F93;
  --booked-text: #3a1b5c;

  --first-visit-bg: #ffd180;
  --first-visit-border: #e65100;
  --first-visit-text: #4a1f00;

  --arrived-bg: #a5d6a7;
  --arrived-border: #2e7d32;
  --arrived-text: #0d2e0f;

  --cancelled-bg: #eeeeee;
  --cancelled-border: #757575;
  --cancelled-text: #555;

  --row-height: 100px;
  --time-col-width: 70px;
  --staff-col-width: 175px;
  --header-height: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar .brand-logo {
  height: 38px;
  width: 38px;
  border-radius: 8px;
  object-fit: cover;
  background: white;
  padding: 2px;
}
.topbar .brand-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: white;
  line-height: 1.15;
  max-width: 130px;
}
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a {
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.15s;
}
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,0.2); }
.topbar .user-info { display: flex; align-items: center; gap: 12px; font-size: 13px; }

button, .btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button:disabled { background: #ccc; cursor: not-allowed; }

.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #43a047; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #e53935; }
.btn-warning { background: var(--warning); }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  background: white;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,47,147,0.1);
}

.card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 20px;
}

.toolbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar h2 { font-size: 20px; margin-right: 16px; }
.toolbar .spacer { flex: 1; }

.schedule-layout {
  display: flex;
  height: calc(100vh - 56px - 60px - 40px);
  background: white;
}

.sidebar {
  width: 220px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: white;
  flex-shrink: 0;
}

.sidebar-section { padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar-section h3 { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }

.staff-list { list-style: none; }
.staff-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 2px;
  transition: background 0.15s;
}
.staff-item:hover { background: var(--bg); }
.staff-item.active { background: var(--primary); color: white; }
.staff-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.schedule-grid-container {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #fafbfd;
}

.schedule-grid {
  display: grid;
  grid-template-columns: var(--time-col-width) repeat(var(--staff-count, 1), var(--staff-col-width));
  position: relative;
  width: max-content;
  min-width: 100%;
}

.time-header-cell {
  position: sticky;
  top: 0;
  left: 0;
  background: white;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  height: var(--header-height);
  z-index: 30;
}

.staff-header {
  position: sticky;
  top: 0;
  background: white;
  border-bottom: 2px solid var(--border);
  border-left: 1px solid var(--border-light);
  padding: 6px 4px;
  height: var(--header-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  z-index: 20;
}
.staff-header .staff-avatar { width: 28px; height: 28px; font-size: 11px; }
.staff-header .staff-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.time-slot {
  height: var(--row-height);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  text-align: right;
  background: white;
  position: sticky;
  left: 0;
  z-index: 10;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.slot {
  height: var(--row-height);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border-light);
  position: relative;
  background: white;
}

/* 30-minute marker line inside each slot */
.slot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--border-light);
  pointer-events: none;
}

.appointment-card {
  position: absolute;
  left: 3px;
  right: 3px;
  background: var(--booked-bg);
  border-left: 3px solid var(--booked-border);
  color: var(--booked-text);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
  transition: transform 0.1s, box-shadow 0.1s, z-index 0s;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  line-height: 1.25;
}
.appointment-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  z-index: 10;
}
.appointment-card.first-visit {
  background: var(--first-visit-bg);
  border-left-color: var(--first-visit-border);
  color: var(--first-visit-text);
}
.appointment-card.arrived {
  background: var(--arrived-bg);
  border-left-color: var(--arrived-border);
  color: var(--arrived-text);
}
.appointment-card.cancelled {
  background: var(--cancelled-bg);
  border-left-color: var(--cancelled-border);
  color: var(--cancelled-text);
  opacity: 0.7;
}
.appointment-card.cancelled .name { text-decoration: line-through; }

.appointment-card .time {
  font-weight: 600;
  font-size: 10px;
  opacity: 0.85;
  white-space: nowrap;
}
.appointment-card .name {
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appointment-card .treatment {
  font-size: 10px;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appointment-card .badge-row {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}
.appointment-card .icon-badge {
  background: rgba(0,0,0,0.18);
  padding: 0 5px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.4;
}

/* Card variants by height */
.appointment-card.size-xs {
  padding: 2px 6px;
  font-size: 10px;
}
.appointment-card.size-xs .time { display: none; }
.appointment-card.size-xs .treatment { display: none; }
.appointment-card.size-xs .badge-row { display: none; }
.appointment-card.size-xs .name { font-size: 11px; }

.appointment-card.size-sm .treatment { display: none; }
.appointment-card.size-sm .badge-row { display: none; }

.appointment-card.size-md .badge-row { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 18px; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}
.close-btn {
  background: none;
  color: var(--text-muted);
  font-size: 24px;
  padding: 0 8px;
  line-height: 1;
}
.close-btn:hover { background: none; color: var(--text); }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.whatsapp-preview {
  background: #e5ddd5;
  border-radius: 8px;
  padding: 24px 16px;
  max-height: 400px;
  overflow-y: auto;
}
.whatsapp-bubble {
  background: #dcf8c6;
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 90%;
  margin-left: auto;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #111;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.whatsapp-bubble .time-stamp {
  font-size: 10px;
  color: #999;
  text-align: right;
  margin-top: 4px;
}

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
}
.alert-warning { background: #fff8e1; color: #f57c00; border-left: 3px solid #ff9800; }
.alert-danger { background: #ffebee; color: #c62828; border-left: 3px solid #f44336; }
.alert-success { background: #e8f5e9; color: #2e7d32; border-left: 3px solid #4caf50; }
.alert-info { background: #e3f2fd; color: #1565c0; border-left: 3px solid #2196f3; }

.patient-info {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.patient-info .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.patient-info .details strong { display: block; font-size: 15px; }
.patient-info .details span { font-size: 12px; color: var(--text-muted); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  font-size: 14px;
  animation: slideIn 0.3s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}
table th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table tr:hover td { background: var(--bg); }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-badge.sent { background: #e8f5e9; color: #2e7d32; }
.status-badge.failed { background: #ffebee; color: #c62828; }
.status-badge.pending { background: #fff8e1; color: #f57c00; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; }

.legend {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 12px;
  padding: 8px 24px;
  background: white;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border-left-width: 3px;
  border-left-style: solid;
}

.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 4px;
}
.tab {
  padding: 10px 20px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.template-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.template-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.template-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(99,47,147,0.15); }
.template-card .category {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  background: var(--bg);
  border-radius: 10px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.template-card h4 { font-size: 14px; margin-bottom: 6px; }
.template-card p {
  font-size: 12px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 60px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(99,47,147,0.05);
}
.dropzone-icon { font-size: 48px; color: var(--text-light); margin-bottom: 12px; }
.dropzone h3 { font-size: 16px; margin-bottom: 6px; }
.dropzone p { font-size: 13px; color: var(--text-muted); }

@media (max-width: 768px) {
  .topbar { padding: 0 12px; height: 50px; }
  .topbar h1 { font-size: 16px; }
  .topbar nav a { padding: 6px 10px; font-size: 12px; }
  .sidebar { display: none; }
  :root {
    --time-col-width: 55px;
    --staff-col-width: 140px;
  }
}

/* ============================================================
   Green topbar (matches the Inbox + KB redesign #1FA67A).
   Appended last so it overrides the purple .topbar rules above.
   ============================================================ */
.topbar {
  background: linear-gradient(100deg, #178060 0%, #1FA67A 100%);
  box-shadow: 0 2px 10px rgba(23,128,96,0.25);
}
.topbar nav a {
  color: rgba(255,255,255,0.92);
  font-weight: 500;
}
.topbar nav a:hover { background: rgba(255,255,255,0.16); }
.topbar nav a.active {
  background: rgba(255,255,255,0.22);
  font-weight: 600;
}


/* RESPONSIVE-TOPBAR-V1 */
/* ============================================================
   Responsive topbar (mobile/tablet). Appended last so it wins.
   CSS-only: no class names, HTML, or JS touched.
   ============================================================ */
@media (max-width: 768px) {
  .topbar {
    height: auto;
    min-height: 50px;
    flex-wrap: wrap;
    padding: 6px 12px;
    gap: 6px 10px;
    row-gap: 6px;
  }
  .topbar .brand { gap: 8px; flex: 0 0 auto; }
  .topbar .brand-logo { height: 32px; width: 32px; }
  .topbar .brand-text { display: none; }
  /* nav: scroll horizontally instead of breaking onto many lines */
  .topbar nav {
    order: 3;
    flex: 1 0 100%;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a {
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .topbar .user-info { gap: 8px; font-size: 12px; flex: 0 0 auto; margin-left: auto; }
  .topbar .user-info .status-btn { padding: 4px 8px; font-size: 12px; }
}


/* HAMBURGER-V1 */
.nav-toggle { display: none; background: transparent; border: none;
  color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px; margin-right: 4px; border-radius: 6px; }
.nav-toggle:hover { background: rgba(255,255,255,0.16); }
@media (max-width: 768px) {
  .nav-toggle { display: inline-flex; align-items: center; }
  /* الروابط مخفية افتراضياً، تنسدل عمودياً عند فتح ☰ */
  .topbar nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch;
    background: #178060; padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.22);
    max-height: none; overflow: visible; gap: 2px; z-index: 200;
  }
  .topbar.nav-open nav { display: flex; }
  .topbar nav a { padding: 12px 14px; font-size: 15px; border-radius: 8px;
    flex: 0 0 auto; white-space: normal; }
}


/* HAMBURGER-BARFIX-V1 */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 8px;
  }
  .topbar .brand { flex: 0 0 auto; }
  /* الحالة + Logout مدفوعة لأقصى اليمين */
  .topbar .user-info { margin-left: auto; gap: 8px; }
  /* اسم المستخدم الطويل مخفي على الموبايل لتوفير المساحة */
  .topbar .user-info #userInfo { display: none; }
}


/* LOGOUTMENU-V1 */
/* رابط Logout داخل القائمة يظهر على الموبايل فقط */
.topbar nav a.nav-logout { display: none; }
@media (max-width: 768px) {
  /* أخفِ زر Logout الأصلي من البار */
  .topbar .user-info > button { display: none; }
  /* أظهر رابط Logout داخل القائمة المنسدلة */
  .topbar nav a.nav-logout { display: block; color: #fff;
    border-top: 1px solid rgba(255,255,255,0.18); margin-top: 4px; padding-top: 14px; }
}
