/* ========================================
   رفيق ٩٠ - تصميم عصري
   لوحة ألوان هادئة: كحلي × أخضر مريح
   ======================================== */

:root {
  --primary: #3D5A80;
  --primary-strong: #2C4870;
  --primary-soft: #E8EEF5;
  --accent: #64B5A0;
  --accent-strong: #3E9278;
  --accent-soft: #E2F1EC;
  --amber: #E8A65A;
  --amber-soft: #FCF0E0;
  --red: #D97A6C;
  --red-soft: #FBE9E6;
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --border: #E3E8EF;
  --text: #1F2A37;
  --text-2: #5B6B7C;
  --text-3: #8A98A8;
  --shadow-sm: 0 1px 2px rgba(29, 41, 57, 0.06), 0 1px 3px rgba(29, 41, 57, 0.04);
  --shadow-md: 0 4px 12px rgba(29, 41, 57, 0.08);
  --shadow-lg: 0 12px 32px rgba(29, 41, 57, 0.12);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 999px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ثيمات بديلة */
[data-theme="teal"] {
  --primary: #3E9278;
  --primary-strong: #2E7861;
  --primary-soft: #E2F1EC;
}

[data-theme="indigo"] {
  --primary: #2C4870;
  --primary-strong: #223A5C;
  --primary-soft: #E4EAF3;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Arabic', 'Tahoma', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  direction: rtl;
  padding-bottom: 92px;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ========================================
   Top Progress Bar
   ======================================== */
.top-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--border);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.top-progress.visible { opacity: 1; }

.top-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.4s ease;
  border-radius: 0 0 0 4px;
}

.top-progress-text {
  display: none;
}

/* ========================================
   Bottom Navigation (عائم)
   ======================================== */
.bottom-nav {
  position: fixed;
  bottom: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 6px;
  max-width: 480px;
  margin: 0 auto;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-3);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 48px;
  font-family: inherit;
  position: relative;
}

.nav-btn:hover, .nav-btn:focus { color: var(--primary); outline: none; }

.nav-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.nav-btn.active .nav-icon { transform: translateY(-1px); }

.nav-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.nav-icon { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--transition); }

/* ========================================
   Views
   ======================================== */
.view { display: none; padding: 18px 16px; }

.view.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }

.app-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary-strong);
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-title-mark {
  background: linear-gradient(135deg, var(--primary), var(--accent-strong));
  color: white;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.view-header h1:not(.app-title) { font-size: 1.4rem; font-weight: 800; color: var(--primary-strong); }

.date-display {
  font-size: 0.82rem;
  color: var(--text-2);
  font-weight: 600;
  background: var(--primary-soft);
  padding: 5px 14px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.view-header select {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ========================================
   Challenge Card (بطاقة التحدي)
   ======================================== */
.challenge-card {
  background: linear-gradient(135deg, var(--primary-strong) 0%, var(--primary) 60%, #4A6B8E 100%);
  border-radius: var(--radius-lg);
  padding: 20px;
  color: white;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(44, 72, 112, 0.25);
  position: relative;
  overflow: hidden;
}

.challenge-card::before {
  content: '';
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  top: -60px;
  left: -40px;
}

.challenge-card::after {
  content: '';
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(100, 181, 160, 0.15);
  bottom: -40px;
  right: -20px;
}

.challenge-card.completed {
  background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 100%);
  box-shadow: 0 8px 24px rgba(62, 146, 120, 0.3);
}

.challenge-card-head {
  display: flex;
  align-items: center;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.challenge-ring-wrap { flex-shrink: 0; position: relative; }

.challenge-ring { width: 96px; height: 96px; transform: rotate(-90deg); }

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 8;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

.challenge-card.completed .ring-progress { stroke: #C9F2E3; }

.challenge-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-days {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
}

.ring-label {
  font-size: 0.7rem;
  opacity: 0.85;
}

.challenge-card-info { flex: 1; min-width: 0; }

.challenge-card-info h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.challenge-day-num {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-bottom: 10px;
}

.challenge-progress-line {
  height: 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
  margin-bottom: 12px;
}

.challenge-progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--accent), #8FD4BE);
  transition: width 0.6s ease;
}

.challenge-card-stats {
  display: flex;
  gap: 20px;
}

.challenge-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.challenge-stat-value {
  font-size: 1.3rem;
  font-weight: 800;
}

.challenge-stat-label {
  font-size: 0.75rem;
  opacity: 0.85;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 46px;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  box-shadow: 0 4px 12px rgba(44, 72, 112, 0.25);
}

.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(44, 72, 112, 0.3); }

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }

.btn-danger {
  background: var(--red);
  color: white;
  width: 100%;
}

.btn-danger:hover:not(:disabled) { background: #C76454; }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ========================================
   Day Mood
   ======================================== */
.mood-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.mood-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 10px;
}

.mood-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: all var(--transition);
}

.mood-btn:hover { border-color: var(--primary); transform: translateY(-2px); }

.mood-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.mood-btn .mood-emoji {
  font-size: 1.4rem;
  line-height: 1;
}

.mood-btn .mood-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-2);
}

.mood-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.mood-btn.active .mood-label { color: var(--primary-strong); }

/* ========================================
   Habits List (اليوم)
   ======================================== */
.habits-list { display: flex; flex-direction: column; gap: 10px; }

.habit-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  animation: slideIn 0.25s ease;
}

@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.habit-item:hover { box-shadow: var(--shadow-md); border-color: var(--primary-soft); }

.habit-item.completed {
  border-color: var(--accent-soft);
  background: linear-gradient(135deg, var(--surface), var(--accent-soft));
}

.habit-item.completed .habit-name { color: var(--accent-strong); text-decoration: line-through; text-decoration-color: rgba(62, 146, 120, 0.4); }

.habit-main { flex: 1; min-width: 0; }

.habit-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }

.habit-name-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }

.habit-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(0,0,0,0.04); }

.habit-name {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}

.habit-target-pill {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}

.habit-meta { display: flex; gap: 6px; margin-top: 2px; }

.habit-reminder-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
}

.habit-input { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Checkbox مخصص */
.habit-check { display: flex; cursor: pointer; }

.habit-checkbox { position: absolute; opacity: 0; pointer-events: none; }

.habit-check-box {
  width: 30px;
  height: 30px;
  border: 2px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  background: var(--surface);
}

.habit-checkbox:checked + .habit-check-box {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: var(--accent);
  transform: scale(1.05);
}

.habit-checkbox:checked + .habit-check-box::after {
  content: '✓';
  color: white;
  font-size: 1rem;
  font-weight: 800;
  animation: popIn 0.25s ease;
}

@keyframes popIn { 0% { transform: scale(0); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }

.habit-checkbox:focus-visible + .habit-check-box { box-shadow: 0 0 0 3px var(--primary-soft); }

/* Stepper للعداد */
.habit-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border-radius: var(--radius-full);
  padding: 3px 6px;
}

.stepper-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--surface);
  color: var(--primary);
  border-radius: 50%;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.stepper-btn:hover:not(:disabled) { background: var(--primary); color: white; }

.stepper-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.stepper-value {
  min-width: 44px;
  text-align: center;
  font-weight: 800;
  color: var(--text);
  font-size: 0.95rem;
}

.stepper-value small { color: var(--text-3); font-size: 0.65rem; font-weight: 600; }

.habit-progress { width: 52px; height: 5px; background: var(--border); border-radius: var(--radius-full); overflow: hidden; flex-shrink: 0; }

.habit-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-strong)); border-radius: var(--radius-full); transition: width 0.3s ease; }

.habit-note-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.habit-note-btn:hover { background: var(--bg); color: var(--primary); }

.habit-note-inline {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  resize: vertical;
  min-height: 56px;
  display: none;
}

.habit-note-inline.visible { display: block; animation: slideDown 0.2s ease; }

@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ========================================
   Habits Management
   ======================================== */
.categories-list { display: flex; flex-direction: column; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

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

.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.icon-btn-sm { width: 32px; height: 32px; padding: 6px; }

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all var(--transition);
  cursor: grab;
}

.habit-row:hover { border-color: var(--border); box-shadow: var(--shadow-sm); background: var(--surface); }

.habit-row.dragging { opacity: 0.4; transform: scale(1.01); box-shadow: var(--shadow-lg); }

.habit-row.drag-over { border-color: var(--primary); background: var(--primary-soft); }

.habit-drag-handle { color: var(--text-3); cursor: grab; padding: 4px; flex-shrink: 0; }

.habit-row-info { flex: 1; min-width: 0; }

.habit-row-name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.habit-row-meta { display: flex; gap: 8px; margin-top: 3px; font-size: 0.7rem; color: var(--text-2); }

.habit-row-type { padding: 2px 8px; border-radius: var(--radius-full); background: var(--surface); font-weight: 600; }

.habit-row-target { color: var(--primary); font-weight: 600; }

.habit-row-color { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.habit-row-actions { display: flex; gap: 4px; }

/* فئات العادات (ربنا / أنا / العيلة / المستقبل) */
.category-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.category-icon { font-size: 1.05rem; line-height: 1; }

.category-name { font-weight: 800; color: var(--text); font-size: 0.92rem; }

.category-count {
  margin-right: auto;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--radius-full);
}

.category-body { padding: 6px 10px; }

.category-empty {
  color: var(--text-3);
  font-size: 0.78rem;
  text-align: center;
  padding: 12px;
}

/* ========================================
   Statistics
   ======================================== */
.stats-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }

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

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card.primary { grid-column: span 2; background: linear-gradient(135deg, var(--primary-strong), var(--primary)); color: white; border: none; }

.stat-card.primary .stat-label { color: rgba(255,255,255,0.8); }

.stat-card.primary .stat-value { color: white; }

.stat-label { font-size: 0.72rem; color: var(--text-3); font-weight: 600; }

.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--primary); line-height: 1.2; }

.stat-value.success { color: var(--accent-strong); }

.stat-value.warning { color: var(--amber); }

.chart-container { margin-bottom: 24px; }

.chart-container h2 { font-size: 1.05rem; font-weight: 800; margin-bottom: 12px; color: var(--text); }

.chart-container canvas {
  width: 100%;
  height: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.heatmap-container { margin-bottom: 24px; }

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

.heatmap-header h2 { font-size: 1.05rem; font-weight: 800; color: var(--text); }

.heatmap-header select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
}

.heatmap-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; direction: ltr; }

.heatmap-day {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
  position: relative;
  min-height: 26px;
}

.heatmap-day:hover { transform: scale(1.15); z-index: 10; box-shadow: var(--shadow-md); }

.heatmap-day.level-1 { background: #DCE8F3; }
.heatmap-day.level-2 { background: #B8D0E8; }
.heatmap-day.level-3 { background: #8FAFCF; }
.heatmap-day.level-4 { background: var(--accent); }
.heatmap-day.level-5 { background: var(--accent-strong); }

.heatmap-day.today { outline: 2px solid var(--primary); outline-offset: -2px; }

.heatmap-day.future { opacity: 0.4; }

.heatmap-day.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  pointer-events: none;
  z-index: 20;
}

.heatmap-day.tooltip:hover::after { opacity: 1; visibility: visible; }

.heatmap-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 0.72rem; color: var(--text-3); }

.legend-gradient { flex: 1; height: 6px; border-radius: var(--radius-full); background: linear-gradient(90deg, var(--border), #DCE8F3, #B8D0E8, #8FAFCF, var(--accent), var(--accent-strong)); }

/* التحديات */
.challenges-section { margin-top: 24px; }

.challenges-section h2 { font-size: 1.05rem; font-weight: 800; margin-bottom: 12px; color: var(--text); }

.challenges-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.challenge-card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.challenge-info { flex: 1; }

.challenge-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }

.challenge-date { font-size: 0.8rem; color: var(--text-2); }

.challenge-countdown { font-size: 1.4rem; font-weight: 800; color: var(--primary); text-align: center; min-width: 70px; }

.challenge-countdown.urgent { color: var(--amber); animation: pulse 1.5s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.challenge-countdown.overdue { color: var(--text-3); }

.challenge-countdown.completed { color: var(--accent-strong); }

/* ========================================
   Settings
   ======================================== */
.settings-sections { display: flex; flex-direction: column; gap: 16px; }

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.settings-section h2 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }

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

.setting-row label { font-weight: 600; color: var(--text); }

.setting-row input[type="time"], .setting-row input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.setting-note { font-size: 0.75rem; color: var(--text-3); margin-top: 12px; line-height: 1.6; }

.toggle { position: relative; width: 52px; height: 28px; }

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: var(--radius-full);
  transition: var(--transition);
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--accent-strong); }

.toggle input:checked + .toggle-slider::before { transform: translateX(24px); }

.toggle input:focus-visible + .toggle-slider { box-shadow: 0 0 0 3px var(--accent-soft); }

.app-info { font-size: 0.85rem; color: var(--text-2); margin-bottom: 16px; line-height: 1.6; }

/* ========================================
   Modals
   ======================================== */
.modal {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 92vw;
  width: 100%;
  max-height: 88vh;
  overflow: hidden;
  background: var(--surface);
  padding: 0;
  margin: auto;
}

.modal::backdrop { background: rgba(31, 42, 55, 0.5); backdrop-filter: blur(6px); }

.modal-content { display: flex; flex-direction: column; width: 100%; max-height: 88vh; overflow-y: auto; }

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

.modal-header h2 { font-size: 1.1rem; font-weight: 800; color: var(--text); }

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  color: var(--text-2);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.modal-close:hover { background: var(--primary-soft); color: var(--primary); }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.form-group { margin-bottom: 18px; }

.form-group label { display: block; font-weight: 700; color: var(--text); margin-bottom: 8px; font-size: 0.9rem; }

.form-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-3);
  margin-inline-start: 4px;
}

.form-note {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.5;
}

.form-group input[type="text"], .form-group input[type="number"], .form-group input[type="date"], .form-group textarea, .form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: all var(--transition);
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: all var(--transition);
  font-size: 0.9rem;
  font-weight: 600;
  flex: 1;
  min-width: 130px;
}

.radio-option:hover { border-color: var(--primary); }

.radio-option input { position: absolute; opacity: 0; pointer-events: none; }

.radio-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  position: relative;
  transition: all var(--transition);
  flex-shrink: 0;
}

.radio-option input:checked + .radio-custom { border-color: var(--primary); background: var(--primary-soft); }

.radio-option input:checked + .radio-custom::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 9px;
  height: 9px;
  background: var(--primary);
  border-radius: 50%;
}

.radio-option input:checked ~ span:last-child { color: var(--primary); }

.category-selector { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.category-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.category-btn:hover { border-color: var(--primary); }

.category-btn.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 700; }

.category-btn .cat-icon { font-size: 1.1rem; line-height: 1; }

.color-palette { display: flex; gap: 8px; flex-wrap: wrap; }

.color-option {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-option:hover { transform: scale(1.12); }

.color-option.active {
  border-color: var(--surface);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

.color-option.color-inherit { background: conic-gradient(from 0deg, #3D5A80, #64B5A0, #E8A65A, #D97A6C, #3D5A80); }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem; color: var(--text); }

.checkbox-label input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent-strong); }

.confirm-modal .modal-body { text-align: center; padding: 24px 20px; }

.confirm-modal #confirm-message { margin-bottom: 16px; color: var(--text-2); }

/* ========================================
   Toasts
   ======================================== */
.toast-container {
  position: fixed;
  bottom: 92px;
  left: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 460px;
  margin: 0 auto;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  max-width: 100%;
}

@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.toast.celebration { border-right: 4px solid var(--accent); background: linear-gradient(135deg, var(--surface), var(--accent-soft)); }

.toast.info { border-right: 4px solid var(--primary); }

.toast.warning { border-right: 4px solid var(--amber); }

.toast.error { border-right: 4px solid var(--red); }

.toast-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.9rem;
}

.toast.celebration .toast-icon { background: var(--accent); color: white; }

.toast.info .toast-icon { background: var(--primary); color: white; }

.toast.warning .toast-icon { background: var(--amber); color: white; }

.toast.error .toast-icon { background: var(--red); color: white; }

.toast-content { flex: 1; min-width: 0; }

.toast-title { font-weight: 800; color: var(--text); margin-bottom: 2px; font-size: 0.92rem; }

.toast-message { font-size: 0.82rem; color: var(--text-2); line-height: 1.4; }

.toast-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
}

.toast-close:hover { background: var(--bg); color: var(--text); }

/* ========================================
   Empty States
   ======================================== */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-3); }

.empty-icon { font-size: 3rem; margin-bottom: 12px; display: block; }

.empty-state h3 { font-size: 1.1rem; font-weight: 800; color: var(--text); margin-bottom: 6px; }

.empty-state p { font-size: 0.88rem; max-width: 260px; margin: 0 auto 18px; line-height: 1.6; }

/* ========================================
   PWA Install Button
   ======================================== */
.pwa-install-btn {
  position: fixed;
  bottom: 92px;
  right: 16px;
  z-index: 60;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  border: none;
  border-radius: var(--radius-full);
  padding: 12px 18px;
  font-size: 0.88rem;
  font-weight: 700;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  animation: toastIn 0.3s ease;
  direction: rtl;
}

.pwa-install-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(44, 72, 112, 0.35); }

.pwa-install-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

/* ========================================
   Day Editor (الخريطة الحرارية)
   ======================================== */
.day-editor-habit {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.day-editor-habit:last-child { border-bottom: none; }

.day-editor-habit label { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }

.day-editor-habit .habit-day-note {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  resize: vertical;
  min-height: 54px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.day-editor-habit .habit-day-note::placeholder { color: var(--text-3); }

.day-editor-habit .habit-day-note:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.day-editor-habit .habit-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.day-editor-habit .habit-value-input {
  width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  text-align: center;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.day-editor-habit .habit-value-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 480px) {
  .view { padding: 14px 12px; }
  .app-title { font-size: 1.3rem; }
  .challenge-ring { width: 84px; height: 84px; }
  .challenge-card { padding: 16px; }
  .ring-days { font-size: 1.6rem; }
  .stat-value { font-size: 1.4rem; }
  .btn { padding: 11px 16px; font-size: 0.88rem; }
  .habit-item { padding: 12px 14px; }
  .heatmap-day { min-height: 22px; }
}

@media (min-width: 600px) {
  .stats-cards { grid-template-columns: repeat(4, 1fr); }
  .stat-card.primary { grid-column: span 2; }
  .modal { max-width: 480px; }
  .view { max-width: 560px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

:focus:not(:focus-visible) { outline: none; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

::selection { background: var(--primary); color: white; }

/* ========================================
   بطاقة مواقيت الصلاة (شاشة اليوم)
   ======================================== */
.prayer-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

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

.prayer-card-title { font-weight: 800; font-size: 0.95rem; }

.prayer-next { font-size: 0.75rem; opacity: 0.92; font-weight: 600; }

.prayer-times-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.prayer-time-cell {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.prayer-time-cell.next {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.prayer-time-cell .prayer-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}
.prayer-time-cell.next .prayer-name { color: rgba(255, 255, 255, 0.9); }
.prayer-time-cell .prayer-time { font-size: 1rem; font-weight: 800; color: #fff; }

/* ========================================
   إعدادات الصلاة
   ======================================== */
.setting-group-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-2);
  margin: 14px 0 8px;
}

.prayer-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 8px;
  background: var(--bg);
  border-radius: var(--radius-md);
}

.prayer-times-preview { margin-top: 14px; }

.prayer-preview-title {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-2);
}

.prayer-times-preview .prayer-times-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.prayer-times-preview .prayer-time-cell {
  background: var(--bg);
  color: var(--text);
}

.prayer-times-preview .prayer-time-cell .prayer-name { color: var(--text-2); }
.prayer-times-preview .prayer-time-cell .prayer-time { color: var(--text); }

.prayer-times-preview .prayer-time-cell.next {
  background: var(--primary);
  color: #fff;
}

.prayer-times-preview .prayer-time-cell.next .prayer-name { color: rgba(255, 255, 255, 0.85); }
.prayer-times-preview .prayer-time-cell.next .prayer-time { color: #fff; }

/* ========================================
   شاشة التقدم: كروت شبكة 90 يوم لكل عادة
   نظام محايد هادي + لون تمييز واحد (أخضر) للمكتمل
   ======================================== */
.progress-habits { display: flex; flex-direction: column; gap: 14px; }

.habit-progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.habit-progress-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.habit-progress-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px var(--border);
}

.habit-progress-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-strong);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.4;
}

/* الشبكة: 10 أعمدة × 9 صفوف */
.habit-progress-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  direction: rtl;
}

.progress-cell {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--grid-border, #D9DFE7);
  border-radius: 3px;
  background: var(--grid-empty, #EDF0F4);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.progress-cell:hover { transform: scale(1.15); }

.progress-cell:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* جزئي (عداد) — درجات أفتح من نفس الأخضر */
.progress-cell.level-1 { background: #E2F1EC; border-color: #BFDCD3; }
.progress-cell.level-2 { background: #C5E4D9; border-color: #9FD3C2; }
.progress-cell.level-3 { background: #8FCAB8; border-color: #77BBA5; }

/* مكتمل — الأخضر القوي (لون التمييز الوحيد) */
.progress-cell.level-4 { background: var(--accent); border-color: var(--accent-strong); }

/* اليوم الحالي — بلون مختلف قليلاً */
.progress-cell.today.level-0 {
  background: #DCE6F0;
  border: 2px solid var(--primary);
}

.progress-cell.today.level-4 { border: 2px solid var(--primary-strong); }
.progress-cell.today.level-1,
.progress-cell.today.level-2,
.progress-cell.today.level-3 { border: 2px solid var(--accent-strong); }

/* المستقبل — أفتح قليلاً */
.progress-cell.future { opacity: 0.45; }

/* شريط التقدم ورقم الأيام تحت الشبكة */
.habit-progress-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.habit-progress-bar {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--border);
  overflow: hidden;
}

.habit-progress-fill {
  height: 100%;
  background: var(--accent-strong);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.habit-progress-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
}