:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e6ea;
  --border-strong: #cbd2d9;
  --text: #16181d;
  --muted: #5c6670;
  --accent: #18181b;
  --accent-hover: #2f3136;
  --ok-bg: #eef7f1;
  --ok-text: #14532d;
  --err-bg: #fef2f2;
  --err-text: #991b1b;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  padding: 20px 14px 48px;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 640px;
  margin: 0 auto;
}

header {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

header p {
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

label.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text);
}

/* خط 16px يمنع التكبير التلقائي في متصفحات الهاتف */
input[type="text"],
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

/* شبكة الأيام */
.days-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.day-btn {
  font-family: inherit;
  font-size: 14px;
  min-height: 44px;
  padding: 8px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.08s;
}

.day-btn:active {
  transform: scale(0.97);
}

.day-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 500;
}

/* قسم كل يوم مختار */
.day-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 12px;
  background: #fafbfc;
}

.day-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.day-section-title {
  font-weight: 600;
  font-size: 15px;
}

.add-slot-btn {
  font-family: inherit;
  font-size: 13px;
  min-height: 36px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--text);
}

.add-slot-btn:hover {
  background: #f0f2f4;
}

.slot-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.slot-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slot-field span {
  font-size: 12px;
  color: var(--muted);
}

.remove-slot-btn {
  font-family: inherit;
  width: 42px;
  height: 44px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.remove-slot-btn:hover {
  color: var(--err-text);
  border-color: #f5c2c7;
  background: var(--err-bg);
}

.submit-btn {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  min-height: 48px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
}

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

.submit-btn:active {
  transform: scale(0.99);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.msg {
  padding: 13px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
  display: none;
}

.msg.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  display: block;
}

.msg.err {
  background: var(--err-bg);
  color: var(--err-text);
  display: block;
}

.empty-hint {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

/* ===== صفحة النتائج والإحصائيات (?results) ===== */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.refresh-btn {
  font-family: inherit;
  font-size: 13px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.refresh-btn:hover {
  background: #f0f2f4;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-highlight {
  border-color: #86efac;
  background: #f4fbf6;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.stat-sub {
  font-size: 13px;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-high { background: #16a34a; }
.dot-mid  { background: #d97706; }
.dot-low  { background: #9ca3af; }

.best-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fcfcfd;
  gap: 8px 12px;
}

.best-title {
  font-weight: 600;
  font-size: 14px;
}

.best-item.level-high {
  border-right: 4px solid #16a34a;
  background: #f4fbf6;
}

.best-item.level-mid {
  border-right: 4px solid #d97706;
  background: #fffbeb;
}

.best-item.level-low {
  border-right: 4px solid #9ca3af;
  background: #f9fafb;
}

.badge {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
}

.badge.level-high { background: #16a34a; }
.badge.level-mid  { background: #d97706; }
.badge.level-low  { background: #6b7280; }

/* شريط إحصائيات الأيام */
.day-stat-row {
  margin-bottom: 12px;
}

.day-stat-row:last-child {
  margin-bottom: 0;
}

.day-stat-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}

.progress-track {
  width: 100%;
  height: 9px;
  background: #eceff2;
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.3s ease;
}

.progress-fill.level-high { background: #16a34a; }
.progress-fill.level-mid  { background: #d97706; }
.progress-fill.level-low  { background: #9ca3af; }

.member-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.member-row:last-child {
  border-bottom: none;
}

.member-name {
  font-weight: 600;
  margin-bottom: 3px;
}

.member-times {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

footer {
  margin-top: 28px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ===== تحسينات شاشات الهاتف ===== */
@media (max-width: 540px) {
  body {
    padding: 16px 12px 40px;
  }

  .card {
    padding: 15px;
  }

  .days-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

  select {
    padding: 8px 8px;
    font-size: 15px;
  }
}

/* شاشات الهواتف الصغيرة جداً (أقل من 360px) */
@media (max-width: 360px) {
  .days-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}