:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #e0e7ff;
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-soft: 0 10px 40px -10px rgba(0,0,0,0.08);
  --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.05);
  --danger: #ef4444;
  --danger-bg: #fef2f2;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-page: #0f172a;
  --bg-surface: #1e293b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary-light: rgba(79, 70, 229, 0.2);
  --danger-bg: rgba(239, 68, 68, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary-light: rgba(79, 70, 229, 0.2);
    --danger-bg: rgba(239, 68, 68, 0.1);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-family: 'IRANSans', system-ui, sans-serif; }

body.app-shell {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  direction: rtl;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

.app-container {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 80px;
}

.admin-container {
  max-width: 800px; /* Wider for admin */
}

/* Header & Theme Toggle */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.brand h1 { margin: 0; font-size: 1.5rem; font-weight: 900; color: var(--text-main); }
.brand p { margin: 4px 0 0; font-size: 0.9rem; color: var(--text-muted); }

.theme-toggle {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.2rem;
  box-shadow: var(--shadow-card);
}
[data-theme="dark"] .dark-icon { display: none; }
[data-theme="dark"] .light-icon { display: block; }
:root:not([data-theme="dark"]) .light-icon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dark-icon { display: none; }
  :root:not([data-theme="light"]) .light-icon { display: block; }
}

/* General UI Elements */
.notification, .badge-msg {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  padding: 14px; border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px; border: 1px solid rgba(16, 185, 129, 0.2);
  font-weight: bold; font-size: 0.9rem;
}

.nav-tabs {
  display: flex; background: var(--bg-surface); padding: 6px;
  border-radius: 99px; box-shadow: var(--shadow-card); margin-bottom: 24px;
}
.nav-item {
  flex: 1; border: none; background: none; padding: 12px;
  border-radius: 99px; font-family: inherit; font-weight: bold;
  color: var(--text-muted); cursor: pointer; transition: all 0.2s;
}
.nav-item.active { background: var(--primary); color: white; }

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

.section { margin-bottom: 32px; }
.section-title { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; color: var(--text-main); }

/* Service & Date Cards */
.service-scroller { display: flex; flex-direction: column; gap: 10px; }
.service-card {
  display: flex; align-items: center; padding: 16px;
  background: var(--bg-surface); border: 2px solid transparent;
  border-radius: var(--radius-md); text-decoration: none; color: var(--text-main);
  box-shadow: var(--shadow-card); cursor: pointer;
}
.service-card.active { border-color: var(--primary); background: var(--primary-light); }
.service-icon { width: 40px; height: 40px; background: var(--primary-light); color: var(--primary); border-radius: 12px; display: flex; align-items: center; justify-content: center; margin-left: 12px; }
.service-info { flex: 1; }
.service-name { display: block; font-weight: bold; font-size: 0.95rem; }
.service-meta { display: block; font-size: 0.8rem; color: var(--text-muted); }

.date-scroller { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.date-pill {
  flex: 0 0 70px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 12px 4px; text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; cursor: pointer;
}
.date-pill.active { background: var(--primary); color: white; border-color: var(--primary); transform: translateY(-4px); }
.day-name { font-size: 0.75rem; } .day-number { font-size: 1.4rem; font-weight: 900; } .month-name { font-size: 0.7rem; }

/* Time Grid & Forms */
.time-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 10px; margin-bottom: 24px; }
.time-radio input { display: none; }
.time-badge {
  display: block; padding: 10px 0; text-align: center; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: 12px; font-weight: bold; cursor: pointer;
}
.time-radio input:checked + .time-badge { background: var(--primary); color: white; border-color: var(--primary); }

.empty-state { text-align: center; color: var(--text-muted); padding: 30px; background: var(--bg-surface); border-radius: var(--radius-lg); border: 1px dashed var(--border); }
.empty-state i { font-size: 2rem; color: var(--border); display: block; margin-bottom: 10px; }

.form-group-wrapper, .admin-card {
  background: var(--bg-surface); padding: 20px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); margin-bottom: 20px; border: 1px solid var(--border);
}
.input-group { position: relative; margin-bottom: 12px; width: 100%; }
.input-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; font-weight: bold; }
.input-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.input-field, .input-select {
  width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 14px;
  font-family: inherit; font-size: 1rem; background: var(--bg-page); color: var(--text-main);
}
.input-field[placeholder] { padding-right: 44px; } /* Icon spacing */

.btn-primary, .btn-secondary {
  width: 100%; border: none; padding: 16px; border-radius: 18px; font-size: 1rem; font-weight: 900;
  font-family: inherit; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }

/* Appointments List */
.appointments-list { display: flex; flex-direction: column; gap: 12px; }
.appt-card { background: var(--bg-surface); padding: 16px; border-radius: var(--radius-md); border: 1px solid var(--border); }
.appt-header { display: flex; justify-content: space-between; margin-bottom: 8px; font-weight: bold; }
.appt-details { font-size: 0.9rem; color: var(--text-muted); line-height: 1.8; }
.status-confirmed { color: #10b981; background: rgba(16,185,129,0.1); padding: 2px 8px; border-radius: 8px; font-size: 0.8rem; }
.status-canceled { color: var(--danger); background: var(--danger-bg); padding: 2px 8px; border-radius: 8px; font-size: 0.8rem; }

.app-footer { text-align: center; margin-top: 40px; color: var(--text-muted); font-size: 0.8rem; }
.app-footer a { color: var(--text-muted); text-decoration: none; font-weight: bold; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* -- 1. افقی کردن لیست خدمات -- */
.service-scroller {
  display: flex;
  flex-direction: row; /* تغییر از عمودی به افقی */
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 15px;
  scrollbar-width: none; /* مخفی کردن خط اسکرول */
}
.service-scroller::-webkit-scrollbar {
  display: none;
}

.service-card {
  flex: 0 0 160px; /* عرض ثابت برای هر کارت تا کنار هم قرار بگیرند */
  flex-direction: column; /* آیکون و متن زیر هم باشند */
  text-align: center;
  justify-content: center;
  padding: 16px 10px;
  position: relative;
}

.service-icon {
  margin-left: 0;
  margin-bottom: 12px;
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
}

.check-icon {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* -- 2. محدود کردن ارتفاع لیست ساعت‌ها (باکس اسکرول‌دار) -- */
#time-grid-container {
  max-height: 250px; /* حداکثر ارتفاع باکس */
  overflow-y: auto; /* فعال کردن اسکرول عمودی داخل باکس */
  padding: 5px;
  padding-left: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-page);
  margin-bottom: 24px;
}

/* زیباسازی اسکرول‌بار مرورگر برای ساعت‌ها */
#time-grid-container::-webkit-scrollbar {
  width: 6px;
}
#time-grid-container::-webkit-scrollbar-track {
  background: transparent;
}
#time-grid-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}