/* =============================================================================
   Learning (release faadumo44)
   Every rule is scoped to .al-root, so nothing else on the dashboard changes.
   Same tokens as Abdifatah Finance / Alpha Password; light/dark follow the
   dashboard's .dark class on <html>.
   ============================================================================= */

.al-root {
  --al-surface: #ffffff;
  --al-canvas: #f8fafc;
  --al-ink: #0f172a;
  --al-text: #1e293b;
  --al-muted: #64748b;
  --al-faint: #94a3b8;
  --al-line: #e2e8f0;
  --al-line-soft: #f1f5f9;
  --al-brand: #dc2626;
  --al-brand-deep: #b91c1c;
  --al-brand-soft: #fef2f2;
  --al-good: #059669;
  --al-good-strong: #10b981;
  --al-good-soft: #d1fae5;
  --al-mid: #d97706;
  --al-bad: #dc2626;
  --al-bad-soft: #fee2e2;
  --al-track: #e2e8f0;
  --al-heat-0: #f1f5f9;
  --al-heat-1: #d1fae5;
  --al-heat-2: #6ee7b7;
  --al-heat-3: #34d399;
  --al-heat-4: #059669;
  --al-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --al-radius: 16px;

  color: var(--al-text);
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dark .al-root {
  --al-surface: #0f172a;
  --al-canvas: #111c33;
  --al-ink: #f8fafc;
  --al-text: #e2e8f0;
  --al-muted: #94a3b8;
  --al-faint: #64748b;
  --al-line: #1e293b;
  --al-line-soft: #16213a;
  --al-brand: #ef4444;
  --al-brand-deep: #dc2626;
  --al-brand-soft: rgba(239, 68, 68, 0.12);
  --al-good: #34d399;
  --al-good-strong: #10b981;
  --al-good-soft: rgba(52, 211, 153, 0.14);
  --al-mid: #fbbf24;
  --al-bad: #f87171;
  --al-bad-soft: rgba(248, 113, 113, 0.14);
  --al-track: #1e293b;
  --al-heat-0: #16213a;
  --al-heat-1: #064e3b;
  --al-heat-2: #047857;
  --al-heat-3: #059669;
  --al-heat-4: #10b981;
  --al-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.al-root *,
.al-root *::before,
.al-root *::after { box-sizing: border-box; }
.al-root h2,
.al-root h3,
.al-root p,
.al-root ul { margin: 0; }
.al-root ul { padding: 0; list-style: none; }
.al-root button { font: inherit; color: inherit; }

/* ---------- helpers ---------- */
.al-root .al-ico-xs { width: 13px; height: 13px; flex: none; }
.al-root .al-ico-sm { width: 16px; height: 16px; flex: none; }
.al-root .al-ico { width: 20px; height: 20px; flex: none; }
.al-root .al-muted { color: var(--al-muted); }
.al-root .al-faint { color: var(--al-faint); }
.al-root .al-good { color: var(--al-good); font-weight: 700; }
.al-root .al-bad { color: var(--al-bad); font-weight: 700; }
.al-root .al-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.al-root .al-spin { animation: al-spin 0.9s linear infinite; }
@keyframes al-spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.al-root .al-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
.al-root .al-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.al-root .al-btn--sm { height: 32px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.al-root .al-btn--primary { background: var(--al-brand); color: #fff; box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2); }
.al-root .al-btn--primary:hover:not(:disabled) { background: var(--al-brand-deep); }
.al-root .al-btn--ghost { background: var(--al-surface); border-color: var(--al-line); color: var(--al-text); }
.al-root .al-btn--ghost:hover:not(:disabled) { background: var(--al-line-soft); }

.al-root .al-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--al-muted);
  cursor: pointer;
  flex: none;
}
.al-root .al-icon-btn:hover:not(:disabled) { background: var(--al-line-soft); color: var(--al-ink); }
.al-root .al-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.al-root .al-icon-btn--bordered { width: 38px; height: 38px; border: 1px solid var(--al-line); background: var(--al-surface); border-radius: 10px; }
.al-root .al-icon-btn--danger:hover:not(:disabled) { background: var(--al-bad-soft); color: var(--al-bad); }

.al-root button:focus-visible,
.al-root .al-input:focus-visible {
  outline: 2px solid var(--al-brand);
  outline-offset: 2px;
}

/* ---------- header & sub-tabs ---------- */
.al-root .al-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.al-root .al-head-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.al-root .al-head-title h2 { font-size: 20px; font-weight: 800; color: var(--al-ink); letter-spacing: -0.01em; }
.al-root .al-head-title p { font-size: 13px; }
.al-root .al-head-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--al-brand-soft);
  color: var(--al-brand);
  flex: none;
}
.al-root .al-head-actions { display: flex; gap: 8px; }

.al-root .al-tabs {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px;
  gap: 4px;
  border-radius: 12px;
  background: var(--al-surface);
  border: 1px solid var(--al-line);
}
.al-root .al-tab {
  height: 34px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--al-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.al-root .al-tab.is-active { background: var(--al-brand); color: #fff; box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25); }
.al-root .al-tab:not(.is-active):hover { color: var(--al-ink); }

/* ---------- states ---------- */
.al-root .al-state,
.al-root .al-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 16px;
  border-radius: var(--al-radius);
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  color: var(--al-muted);
  font-weight: 600;
  text-align: center;
}
.al-root .al-state--empty { flex-direction: column; border-style: dashed; }
.al-root .al-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--al-bad-soft);
  color: var(--al-bad);
  font-weight: 600;
  font-size: 13px;
}
.al-root .al-error span { flex: 1; }
.al-root .al-empty-line { font-size: 13px; }

/* ---------- shared blocks ---------- */
.al-root .al-view { display: flex; flex-direction: column; gap: 14px; }
.al-root .al-card {
  padding: 16px;
  border-radius: var(--al-radius);
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  box-shadow: var(--al-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.al-root .al-section-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--al-muted); }
.al-root .al-big { font-size: 26px; font-weight: 800; color: var(--al-ink); font-variant-numeric: tabular-nums; }
.al-root .al-bar { height: 8px; border-radius: 999px; background: var(--al-track); overflow: hidden; }
.al-root .al-bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.al-root .al-bar-fill--good { background: var(--al-good-strong); }
.al-root .al-bar-fill--mid { background: var(--al-mid); }
.al-root .al-bar-fill--low { background: var(--al-bad); }

.al-root .al-pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.al-root .al-pager-label { display: flex; flex-direction: column; min-width: 170px; text-align: center; line-height: 1.25; }
.al-root .al-pager-label strong { font-size: 15px; font-weight: 800; color: var(--al-ink); }
.al-root .al-pager-label span { font-size: 12px; font-weight: 600; }

.al-root .al-cheer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--al-brand-soft);
  color: var(--al-brand);
  font-weight: 700;
}
.al-root .al-cheer.is-done { background: var(--al-good-soft); color: var(--al-good); }

/* ---------- week grid ---------- */
.al-root .al-grid-card { padding: 8px; }
.al-root .al-grid-scroll { overflow-x: auto; }
.al-root .al-grid { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.al-root .al-grid th,
.al-root .al-grid td { padding: 0; text-align: center; }
.al-root .al-grid .al-grid-habit {
  width: 34%;
  max-width: 220px;
  padding: 0 8px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--al-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.al-root .al-grid thead .al-grid-habit { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--al-faint); }
.al-root .al-grid-day {
  padding: 6px 0 !important;
  border-radius: 10px;
  color: var(--al-muted);
}
.al-root .al-grid-day.is-today { background: var(--al-brand); color: #fff; }
.al-root .al-grid-dow { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.al-root .al-grid-num { display: block; font-size: 15px; font-weight: 800; }
.al-root .al-grid td.is-today { background: var(--al-brand-soft); border-radius: 10px; }

.al-root .al-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 56px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid var(--al-line);
  background: var(--al-surface);
  color: var(--al-faint);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, transform 0.08s;
}
.al-root .al-cell:active:not(:disabled) { transform: scale(0.94); }
.al-root .al-cell--missed:hover { border-color: var(--al-good-strong); }
.al-root .al-cell--done { background: var(--al-good-strong); border-color: var(--al-good-strong); color: #fff; }
.al-root .al-cell--done .al-ico { width: 24px; height: 24px; stroke-width: 3; }
.al-root .al-cell--future,
.al-root .al-cell--before { background: var(--al-line-soft); border-style: dashed; cursor: not-allowed; opacity: 0.7; }
.al-root .al-cell.is-pending { opacity: 0.6; }
.al-root .al-cell-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--al-line); }

/* ---------- week summary ---------- */
.al-root .al-summary-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.al-root .al-habit-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.al-root .al-habit-stats li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--al-canvas);
  border: 1px solid var(--al-line-soft);
}
.al-root .al-habit-name { flex: 1; min-width: 0; font-weight: 700; color: var(--al-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.al-root .al-habit-count { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--al-ink); }
.al-root .al-streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--al-line-soft);
  color: var(--al-muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.al-root .al-streak.is-on { background: #fff7ed; color: #ea580c; }
.dark .al-root .al-streak.is-on { background: rgba(234, 88, 12, 0.15); color: #fb923c; }

/* ---------- KPI cards ---------- */
.al-root .al-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.al-root .al-kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.al-root .al-kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: var(--al-radius);
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  box-shadow: var(--al-shadow);
  min-width: 0;
}
.al-root .al-kpi--main { border-color: var(--al-brand); box-shadow: 0 0 0 1px var(--al-brand); }
.al-root .al-kpi .al-bar { margin-top: 6px; }
.al-root .al-kpi-label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--al-muted); }
.al-root .al-kpi-value { font-size: 24px; font-weight: 800; color: var(--al-ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.al-root .al-kpi-value--sm { font-size: 17px; }
.al-root .al-kpi-value.is-up { color: var(--al-good); }
.al-root .al-kpi-value.is-down { color: var(--al-bad); }
.al-root .al-kpi-sub { font-size: 12px; color: var(--al-muted); }

/* ---------- month per-habit ---------- */
.al-root .al-habit-bars { display: flex; flex-direction: column; gap: 12px; }
.al-root .al-habit-bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.al-root .al-habit-pct { white-space: nowrap; font-variant-numeric: tabular-nums; }
.al-root .al-habit-pct strong { color: var(--al-ink); }

/* ---------- heatmap calendar ---------- */
.al-root .al-heat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.al-root .al-legend { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--al-faint); font-weight: 600; }
.al-root .al-legend i { width: 14px; height: 14px; border-radius: 4px; }
.al-root .al-heat { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; max-width: 560px; }
.al-root .al-heat-dow { text-align: center; font-size: 11px; font-weight: 800; color: var(--al-faint); text-transform: uppercase; }
.al-root .al-heat-day {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--al-ink);
}
.al-root .al-heat-day.is-off { background: transparent; border: 1px dashed var(--al-line); color: var(--al-faint); }
.al-root .al-heat-day.is-today { box-shadow: 0 0 0 2px var(--al-brand); }
.al-root .al-heat-0 { background: var(--al-heat-0); }
.al-root .al-heat-1 { background: var(--al-heat-1); }
.al-root .al-heat-2 { background: var(--al-heat-2); }
.al-root .al-heat-3 { background: var(--al-heat-3); color: #fff; }
.al-root .al-heat-4 { background: var(--al-heat-4); color: #fff; }
.al-root .al-heat-day.al-heat-3,
.al-root .al-heat-day.al-heat-4 { color: #fff; }

/* ---------- quarter table ---------- */
.al-root .al-q-table { display: flex; flex-direction: column; }
.al-root .al-q-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 64px 64px 92px;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-top: 1px solid var(--al-line-soft);
  font-variant-numeric: tabular-nums;
}
.al-root .al-q-row--head { border-top: 0; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--al-faint); }
.al-root .al-q-row > span:not(:first-child) { text-align: center; }
.al-root .al-chevron { transition: transform 0.15s; }
.al-root .al-chevron.is-open { transform: rotate(180deg); }
.al-root .al-dates { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 10px; }
.al-root .al-date-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--al-line-soft);
  color: var(--al-text);
  font-size: 12px;
  font-weight: 600;
}
.al-root .al-date-chip--bad { background: var(--al-bad-soft); color: var(--al-bad); }

/* ---------- manage panel ---------- */
.al-root .al-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}
.al-root .al-dialog {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  background: var(--al-surface);
  border: 1px solid var(--al-line);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  overflow: hidden;
}
.al-root .al-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--al-line); }
.al-root .al-dialog-title { font-size: 16px; font-weight: 800; color: var(--al-ink); }
.al-root .al-dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 16px 18px; overflow-y: auto; }
.al-root .al-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--al-line); background: var(--al-canvas); }
.al-root .al-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--al-line);
  background: var(--al-surface);
  color: var(--al-text);
  font: inherit;
  font-size: 14px;
  outline: 0;
}
.al-root .al-input:focus { border-color: var(--al-brand); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.al-root .al-input--inline { height: 38px; font-weight: 600; }
.al-root .al-input--select,
.al-root .al-input--date { width: auto; min-width: 150px; height: 38px; color-scheme: light; }
.dark .al-root .al-input--select,
.dark .al-root .al-input--date { color-scheme: dark; }
.al-root .al-add { display: flex; gap: 8px; }
.al-root .al-manage-list { display: flex; flex-direction: column; gap: 6px; }
.al-root .al-manage-row { display: flex; align-items: center; gap: 6px; }
.al-root .al-order {
  width: 26px;
  height: 26px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--al-line-soft);
  color: var(--al-muted);
  font-size: 12px;
  font-weight: 800;
}
.al-root .al-manage-archived,
.al-root .al-settings { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--al-line); }
.al-root .al-manage-row--archived { justify-content: space-between; padding: 6px 4px; }
.al-root .al-archived-name { color: var(--al-muted); font-weight: 600; text-decoration: line-through; }
.al-root .al-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.al-root .al-setting-hint { font-size: 12px; }

/* ---------- toasts ---------- */
.al-root .al-toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 210;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
}
.al-root .al-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border-radius: 12px;
  background: var(--al-ink);
  color: var(--al-surface);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  animation: al-toast-in 0.18s ease-out;
}
.al-root .al-toast .al-icon-btn { color: inherit; opacity: 0.7; width: 26px; height: 26px; }
.al-root .al-toast--success svg:first-child { color: #34d399; }
.al-root .al-toast--error svg:first-child { color: #f87171; }
@keyframes al-toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .al-root .al-kpis,
  .al-root .al-kpis--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .al-root .al-kpi--main { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .al-root .al-head-actions { width: 100%; }
  .al-root .al-head-actions .al-btn { flex: 1; }
  .al-root .al-tabs { align-self: stretch; }
  .al-root .al-tab { flex: 1; padding: 0 8px; }
  .al-root .al-pager-label { min-width: 0; flex: 1; }
  /* Phone: habit name on its own line above its 7 tick buttons, so each button gets ~1/7 of the width. */
  .al-root .al-grid-card { padding: 8px; }
  .al-root .al-grid,
  .al-root .al-grid thead,
  .al-root .al-grid tbody { display: block; }
  .al-root .al-grid tr { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
  .al-root .al-grid thead tr { position: sticky; top: 0; margin-bottom: 4px; }
  .al-root .al-grid thead .al-grid-habit { display: none; }
  .al-root .al-grid tbody tr { padding: 6px 0 8px; border-top: 1px solid var(--al-line-soft); }
  .al-root .al-grid tbody .al-grid-habit { grid-column: 1 / -1; width: auto; max-width: none; padding: 0 2px 2px; font-size: 13px; }
  .al-root .al-grid td { display: flex; justify-content: center; }
  .al-root .al-grid-dow { font-size: 10px; }
  .al-root .al-grid-num { font-size: 13px; }
  .al-root .al-cell { max-width: none; height: 46px; border-radius: 10px; }
  .al-root .al-q-row { grid-template-columns: minmax(0, 1fr) 44px 48px 44px 76px; gap: 4px; font-size: 13px; }
  .al-root .al-overlay { align-items: flex-end; padding: 0; }
  .al-root .al-dialog { max-width: none; max-height: 92vh; border-radius: 18px 18px 0 0; }
  .al-root .al-setting { flex-direction: column; align-items: stretch; gap: 6px; }
  .al-root .al-input--select,
  .al-root .al-input--date { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .al-root .al-spin,
  .al-root .al-toast,
  .al-root .al-bar-fill,
  .al-root .al-cell { animation: none; transition: none; }
}
