:root {
  --primary: #D4AF37;
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #e0e0e0;
  --text-dim: #a0a0a0;
  --success: #4caf50;
}

html.theme-light {
  --bg: #f5f5f5;
  --surface: #fff;
  --text: #1a1a1a;
  --text-dim: #666;
}
html.theme-light .library-search,
html.theme-light .intention-item,
html.theme-light .lib-card {
  border-color: rgba(0,0,0,0.08);
}
html.theme-light .bottom-nav {
  border-top-color: rgba(0,0,0,0.08);
}
html.theme-light .stats-card {
  background: linear-gradient(135deg, #fff, #f0f0f0);
}
html.theme-light .dashboard-summary {
  border-color: rgba(0,0,0,0.08);
}
html.theme-light .dashboard-row:not(:last-child) {
  border-bottom-color: rgba(0,0,0,0.08);
}

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

body {
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  background-color: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  z-index: 10;
}

.logo-img {
  height: 36px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  background: var(--surface);
  border: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:focus { outline: none; }
.icon-btn:active { opacity: 0.8; }

main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 20px;
  /* مساحة أسفل المحتوى حتى لا يختفي تحت زر عقد النية ولا تحت الشريط السفلي */
  padding-bottom: 180px;
  min-height: 0;
}

/* Daily message & home actions */
.daily-message {
  text-align: center;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: rgba(212, 175, 55, 0.12);
  border-radius: 12px;
  font-size: 14px;
  color: var(--primary);
  line-height: 1.5;
}
.home-actions { margin-bottom: 16px; }
.btn-secondary {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary:active { opacity: 0.9; }

/* Context Card */
.context-card {
  text-align: center;
  margin-bottom: 24px;
}
.card-icon { font-size: 48px; margin-bottom: 10px; }
.context-card h2 { margin: 0 0 8px 0; font-size: 22px; }
.context-card p { margin: 0; color: var(--text-dim); font-size: 14px; }

/* Intentions List */
.intentions-list { display: flex; flex-direction: column; gap: 12px; }

.intention-item {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}
.intention-item .text { flex: 1; min-width: 0; }
.intention-info-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.intention-info-btn .info-icon {
  font-size: 16px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  color: var(--text-dim);
  line-height: 1;
}
.intention-info-btn:hover,
.intention-info-btn:active {
  background: rgba(212, 175, 55, 0.25);
}
.intention-info-btn:hover .info-icon,
.intention-info-btn:active .info-icon {
  color: var(--primary);
}
.intention-info-btn:focus { outline: none; }

.intention-item.selected {
  background: rgba(212, 175, 55, 0.15);
  border-color: var(--primary);
  transform: scale(1.02);
}

.check-circle {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--text-dim);
  transition: all 0.2s; flex-shrink: 0;
}
.intention-item.selected .check-circle {
  background: var(--primary); border-color: var(--primary);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
}

.text h3 { margin: 0 0 4px 0; font-size: 15px; font-weight: 500; }
.evidence { font-size: 11px; color: var(--text-dim); display: block; }

/* FAB Button - فوق الشريط السفلي حتى لا يغطي المحتوى */
.fab-container {
  position: fixed;
  bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 12px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 40;
}

.btn-commit {
  background: var(--surface); color: var(--text-dim);
  border: none; padding: 16px 32px; border-radius: 50px;
  font-size: 16px; font-family: inherit; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: all 0.3s;
  pointer-events: auto;
  opacity: 0.8;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}

.btn-commit.active {
  background: var(--primary); color: #000;
  transform: translateY(-5px) scale(1.05);
  opacity: 1;
  box-shadow: 0 10px 30px rgba(212, 175, 55, 0.3);
}

.btn-commit small { font-size: 10px; font-weight: 400; opacity: 0.8; }

/* Library */
.library-header { margin-bottom: 20px; }
.library-title { margin: 0 0 12px 0; font-size: 20px; font-weight: 700; }
.library-search {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.library-search::placeholder { color: var(--text-dim); }
.library-search:focus { outline: none; border-color: var(--primary); }
.library-sort {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.favorites-section { margin-bottom: 24px; }
.favorites-section h3 { margin: 0 0 12px 0; font-size: 16px; color: var(--text-dim); }
.lib-card { position: relative; }
.lib-fav-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 32px; height: 32px;
  border: none;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.7;
}
.lib-fav-btn.active, .lib-fav-btn:hover { opacity: 1; }
.loading-placeholder {
  text-align: center;
  padding: 48px 24px;
}
.loading-text { margin: 0 0 8px 0; font-size: 18px; color: var(--primary); }
.loading-placeholder .text-dim { margin: 0 0 16px 0; font-size: 14px; }
.loading-placeholder .btn-secondary { max-width: 200px; margin: 0 auto; }

.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.lib-card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
}

.lib-card:active { transform: scale(0.96); background: rgba(255,255,255,0.05); }

.lib-icon { font-size: 40px; margin-bottom: 12px; filter: drop-shadow(0 0 10px rgba(0,0,0,0.5)); }
.lib-title { font-size: 14px; font-weight: 500; color: var(--text); line-height: 1.4; }

/* Dashboard summary */
.dashboard-summary {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 20px;
  border: 1px solid rgba(255,255,255,0.06);
}
.dashboard-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
}
.dashboard-row:not(:last-child) { border-bottom: 1px solid rgba(255,255,255,0.06); }
.dashboard-label { color: var(--text-dim); }
.dashboard-value { color: var(--text); font-weight: 500; }

/* Stats */
.stats-card {
  background: linear-gradient(135deg, var(--surface), #252525);
  padding: 30px; border-radius: 24px; text-align: center;
  margin-bottom: 30px;
}
.big-score { font-size: 64px; font-weight: 700; color: var(--primary); line-height: 1; margin: 10px 0; }
.stats-sub { margin: 0 0 8px 0; font-size: 14px; color: var(--text-dim); }
.streak, .most-used { margin: 8px 0 0 0; font-size: 13px; color: var(--text-dim); }
.stats-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.stats-actions .btn-secondary { width: auto; flex: 1; min-width: 120px; }
.history-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--surface);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.filter-btn.active {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
}

/* رسم 7 أيام */
.chart-7days { margin-bottom: 24px; }
.chart-7days h3 { margin: 0 0 12px 0; font-size: 16px; color: var(--text-dim); }
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 80px;
  padding: 8px 0;
}
.chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.chart-bar {
  width: 100%;
  max-width: 32px;
  min-height: 4px;
  background: var(--primary);
  border-radius: 6px 6px 0 0;
  transition: height 0.3s;
}
.chart-label { font-size: 10px; color: var(--text-dim); }

/* قواعد التذكير */
.ifthen-section { margin-bottom: 24px; }
.ifthen-section h3 { margin: 0 0 8px 0; font-size: 16px; }
.ifthen-section .text-dim { margin: 0 0 12px 0; font-size: 13px; color: var(--text-dim); }
.ifthen-rule {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: 12px;
  font-size: 14px;
}
.ifthen-rule button { margin-right: auto; }

/* رسالة الرفيق وتذكير القاعدة */
.companion-message, .ifthen-reminder {
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}
.companion-message { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08); }
.ifthen-reminder { background: rgba(212, 175, 55, 0.12); border: 1px solid rgba(212, 175, 55, 0.2); color: var(--primary); }

/* نموذج إضافة نية / قاعدة */
.custom-intention-form {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  max-width: 95%;
  width: 360px;
  border: 1px solid rgba(255,255,255,0.1);
}
.custom-intention-form h3 { margin: 0 0 16px 0; }
.custom-intention-form label { display: block; margin: 12px 0 6px 0; font-size: 14px; color: var(--text-dim); }
.custom-intention-form .library-search { margin-bottom: 0; }
.custom-intention-form textarea { resize: vertical; min-height: 60px; }

/* المكتبة تصنيفات */
.library-category { margin-bottom: 24px; }
.category-title { margin: 0 0 12px 0; font-size: 15px; color: var(--text-dim); font-weight: 600; }
.library-body { min-height: 120px; }
.btn-add-intention { margin-top: 12px; }
.lib-card-custom { border-color: rgba(212, 175, 55, 0.3); }

.history-item {
  display: flex; justify-content: space-between; padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 14px;
}
.history-item .score { color: var(--success); font-weight: 600; }

/* Animations */
.animate-up { animation: slideUp 0.5s ease-out; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.overlay.active { opacity: 1; pointer-events: all; }
.onboarding-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 28px;
  max-width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.onboarding-card h2 { margin: 0 0 16px 0; color: var(--primary); }
.onboarding-card p { margin: 0 0 12px 0; line-height: 1.6; color: var(--text); }
.onboarding-card .btn-copy-dua { margin-top: 16px; }

/* لحظة وميض */
.flash-moment-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 24px;
  max-width: 95%;
  width: 360px;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.flash-title { margin: 0 0 8px 0; font-size: 22px; color: var(--primary); text-align: center; }
.flash-sub { margin: 0 0 20px 0; font-size: 15px; color: var(--text-dim); text-align: center; }
.flash-intentions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash-intention-item {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}
.flash-intention-item.selected {
  background: rgba(212, 175, 55, 0.2);
  border-color: var(--primary);
}
.flash-actions { display: flex; flex-direction: column; gap: 10px; }
.flash-actions .btn-copy-dua { width: 100%; }

.overlay .intention-detail-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  max-width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.intention-detail-card h3 { margin: 0 0 16px 0; font-size: 18px; color: var(--primary); }
.intention-detail-card .detail-desc {
  margin: 0 0 12px 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}
.intention-detail-card .detail-evidence {
  margin: 0 0 20px 0;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
}
.detail-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-copy-dua, .btn-close-detail {
  padding: 12px 20px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.btn-copy-dua {
  background: var(--primary);
  color: #000;
}
.btn-close-detail {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}
.toast {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--primary);
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.celebration { text-align: center; color: var(--primary); }
.score-pop { font-size: 80px; font-weight: 700; animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

/* Nav - ثابت أسفل الشاشة على الموبايل مع دعم safe-area */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  z-index: 50;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.nav-item.active { color: var(--primary); }
.nav-item .icon { font-size: 22px; }

/* ===== Auth ===== */
.auth-card {
  background: var(--surface);
  border-radius: 1.4rem;
  padding: 0;
  width: min(340px, 92vw);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  border: 1px solid rgba(212,175,55,0.15);
}

.auth-card-header {
  background: linear-gradient(135deg, #1a1500 0%, #2a2000 100%);
  padding: 1.5rem 1.5rem 1.2rem;
  text-align: center;
  border-bottom: 1px solid rgba(212,175,55,0.2);
}

.auth-card-icon {
  font-size: 2rem;
  margin-bottom: 0.4rem;
}

.auth-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #D4AF37;
  margin: 0;
}

.auth-card-body {
  padding: 1.2rem 1.4rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 0.7rem;
  padding: 3px;
  gap: 3px;
  margin-bottom: 0.3rem;
}

.auth-tab {
  flex: 1;
  padding: 0.45rem;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: #D4AF37;
  color: #111;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(212,175,55,0.3);
}

.auth-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1.5px solid rgba(212,175,55,0.15);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: #D4AF37;
  box-shadow: 0 0 0 3px rgba(212,175,55,0.1);
}

.auth-input::placeholder {
  color: var(--text-dim);
  font-size: 0.88rem;
}

.auth-error {
  color: #ef5350;
  font-size: 0.82rem;
  margin: 0;
  min-height: 1em;
  text-align: center;
  background: rgba(239,83,80,0.08);
  border-radius: 0.4rem;
  padding: 0.2rem 0.5rem;
  display: none;
}
.auth-error:not(:empty) { display: block; }

.btn-auth-submit {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #D4AF37, #b8941f);
  color: #111;
  border: none;
  border-radius: 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 3px 12px rgba(212,175,55,0.25);
  margin-top: 0.2rem;
}
.btn-auth-submit:active { transform: scale(0.98); opacity: 0.9; }

.auth-divider {
  border: none;
  border-top: 1px solid rgba(212,175,55,0.1);
  margin: 0.2rem 0;
}

.btn-auth-secondary {
  width: 100%;
  padding: 0.7rem;
  background: transparent;
  color: var(--text-dim);
  border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-auth-secondary:hover { border-color: rgba(212,175,55,0.3); color: var(--text); }

.btn-auth-danger {
  width: 100%;
  padding: 0.7rem;
  background: transparent;
  color: #ef5350;
  border: 1.5px solid rgba(239,83,80,0.2);
  border-radius: 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-auth-danger:hover { background: rgba(239,83,80,0.08); }

.auth-user-avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #D4AF37, #b8941f);
  color: #111;
  font-size: 1.3rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.5rem;
  box-shadow: 0 3px 12px rgba(212,175,55,0.3);
}

.auth-user-email {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  word-break: break-all;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.auth-user-badge {
  text-align: center;
  font-size: 0.75rem;
  color: #D4AF37;
  background: rgba(212,175,55,0.1);
  border-radius: 1rem;
  padding: 0.2rem 0.7rem;
  display: inline-block;
  margin: 0 auto 0.8rem;
}

/* User button logged-in state */
#btn-user.logged-in {
  background: linear-gradient(135deg, #D4AF37, #b8941f);
  color: #111;
  font-weight: 800;
  font-size: 0.8rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(212,175,55,0.3);
}
