@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Variable.woff2") format("woff2-variations"),
       url("/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #0f1411;
  --surface: #182019;
  --surface-2: #1f2922;
  --primary: #4c9a5f;
  --primary-dark: #2f6b3f;
  --text: #eaf3ea;
  --text-dim: #9fb3a4;
  --danger: #c25b4f;
  --radius: 16px;
  --max-width: 430px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.8;
  direction: rtl;
  text-align: right;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: var(--max-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen { padding: 20px 16px 90px; flex: 1; }
.screen.hidden { display: none; }

.hidden { display: none !important; }

h1, h2, h3 { margin: 0 0 8px; }
p { color: var(--text-dim); line-height: 1.7; margin: 0 0 16px; }

.brand { text-align: center; margin: 32px 0 24px; }
.brand-emoji { font-size: 48px; }

.boot-status { text-align: center; color: var(--text-dim); font-size: 15px; margin-top: 8px; }

.maintenance-copy { text-align: center; margin: 8px 0 28px; }
.maintenance-title { color: var(--text); font-size: 17px; margin-bottom: 12px; }
#screen-maintenance .btn-secondary { width: 100%; }

/* Inline boot hint in index.html — show Home before app.js finishes loading. */
html[data-boot-screen="home"] #screen-boot { display: none !important; }
html[data-boot-screen="home"] #screen-home.hidden { display: block !important; }

.login-help-text { text-align: center; font-size: 13px; margin: 10px 0 6px; }
#login-step-welcome .btn-text, #login-step-phone .btn-text, #login-step-telegram-waiting .btn-text {
  display: block;
  margin: 0 auto;
}

input, textarea {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
  direction: rtl;
}

textarea { min-height: 120px; resize: vertical; font-family: inherit; }

input:disabled, textarea:disabled {
  opacity: 0.6;
  background: var(--surface-2);
  cursor: not-allowed;
}

button {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 12px;
}

.btn-primary { background: var(--primary); color: #08130a; font-weight: 600; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #1a0c0a; }
.btn-text { background: transparent; color: var(--text-dim); text-decoration: underline; }

button.btn-loading { opacity: 0.65; pointer-events: none; cursor: default; }
button:disabled { opacity: 0.65; pointer-events: none; cursor: default; }

.record-button {
  width: 100%;
  padding: 28px;
  font-size: 18px;
  font-weight: 700;
  background: var(--primary);
  color: #08130a;
  border-radius: 20px;
  margin-bottom: 24px;
}

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

.card .meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-dim); }

.status-done { color: var(--primary); }
.status-pending { color: var(--text-dim); }
.status-failed { color: var(--danger); }

/* ---------- Home page ---------- */

.home-greeting { font-size: 22px; font-weight: 700; margin: 8px 0 4px; }
.home-tagline { font-size: 13.5px; color: var(--text-dim); margin-bottom: 20px; }

.stats-summary-card {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: 20px;
  padding: 18px 8px;
  margin-bottom: 16px;
}
.stats-summary-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.stats-summary-item--tappable {
  cursor: pointer;
  border-radius: 12px;
  margin: -6px 0;
  padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
}
.stats-summary-item--tappable:active {
  background: var(--surface-2);
}
.stats-summary-item--tappable:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.stats-summary-icon { font-size: 18px; }
.stats-summary-value { font-size: 20px; font-weight: 700; color: var(--primary); }
.stats-summary-label { font-size: 12px; color: var(--text-dim); }
.stats-divider { width: 1px; align-self: stretch; background: var(--surface-2); margin: 4px 0; }

.home-today-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.home-last-reflection { margin-bottom: 16px; }
.home-last-reflection-card {
  display: block;
  width: 100%;
  text-align: right;
  background: var(--surface);
  border: none;
  border-radius: 20px;
  padding: 18px 20px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.home-last-reflection-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.home-last-reflection-meta { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.home-last-reflection-preview {
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.home-last-reflection-cta { font-size: 13px; color: var(--primary); }
.home-today-card-inner { display: flex; flex-direction: column; gap: 12px; }
.home-today-header { font-size: 15px; font-weight: 600; }
.home-today-sun { font-size: 15px; }
.home-today-body { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.home-today-text { text-align: right; flex: 1; }
.home-today-text p { margin: 0; font-size: 15px; color: var(--text); }

.home-today-ring-wrap { position: relative; width: 70px; height: 70px; flex-shrink: 0; }
.home-today-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.home-today-ring-track { fill: none; stroke: var(--surface-2); stroke-width: 6; }
.home-today-ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease-out;
}
.home-today-ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.home-today-divider {
  height: 1px;
  background: var(--surface-2);
}

.home-today-last {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.home-today-last-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.home-today-last-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--bg);
  border-radius: 12px;
  text-align: right;
}

.home-today-last-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.home-today-last-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.home-today-last-category {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.home-today-last-time {
  font-size: 12px;
  color: var(--text-dim);
}

.home-today-view-all {
  background: transparent;
  color: var(--text-dim);
  text-decoration: underline;
  padding: 0;
  font-size: 13px;
  text-align: center;
  margin: 0;
  width: auto;
}
.home-today-view-all::after {
  content: "‹";
  margin-inline-start: 4px;
  text-decoration: none;
  opacity: 0.6;
  font-size: 15px;
  vertical-align: middle;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}

.section-label {
  font-size: 13px;
  color: var(--text-dim);
  margin: 24px 0 8px;
  font-weight: 600;
}

.section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 8px;
}
.section-label-row .section-label { margin: 0; }
.section-label-row button { width: auto; margin-bottom: 0; padding: 0; }

/* ---------- Timeline (moments) ---------- */

.timeline-date-group { margin-bottom: 22px; }
.timeline-date-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 10px;
  padding-right: 4px;
}
.timeline-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.timeline-card .timeline-icon { font-size: 20px; flex-shrink: 0; }
.timeline-card .timeline-body { flex: 1; min-width: 0; }
.timeline-card .timeline-type { font-size: 12px; color: var(--text-dim); margin-bottom: 2px; }
.timeline-card .timeline-category { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.timeline-card .timeline-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.timeline-card .timeline-status { font-size: 12.5px; margin-top: 8px; }
.timeline-pending-hint {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
}
.timeline-pending-error { margin-top: 4px; color: var(--danger); }
.timeline-pending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.timeline-pending-actions .btn-secondary {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  font-size: 13px;
}
.timeline-pending-actions .btn-text {
  width: auto;
  margin: 0;
  padding: 8px 4px;
  font-size: 13px;
}

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; }
.status-dot.yellow { background: #d4a93a; }
.status-dot.green { background: var(--primary); }
.status-dot.red { background: var(--danger); }

/* ---------- Reflections ---------- */

.reflection-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 14px;
}
.reflection-card h3 { font-size: 17px; margin-bottom: 4px; }
.reflection-card .reflection-meta { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.reflection-card p { font-size: 15px; line-height: 1.8; margin-bottom: 14px; }
.reflection-card button { margin-bottom: 0; }
.reflection-light-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 2px 8px;
  margin-right: 6px;
}

.reflection-content { line-height: 1.9; }
.reflection-content h3 { font-size: 17px; margin: 22px 0 8px; color: var(--primary); }
.reflection-content h3:first-child { margin-top: 0; }
.reflection-content p { margin: 0 0 16px; }
.reflection-content ul, .reflection-content ol {
  margin: 0 0 16px;
  padding-right: 22px;
  padding-left: 0;
}
.reflection-content li { margin-bottom: 6px; }

/* ---------- Profile ---------- */

.profile-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary-dark);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  flex-shrink: 0;
}
.profile-name { font-size: 19px; font-weight: 700; }
.profile-username { font-size: 14px; color: var(--text-dim); }
.profile-since { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: auto;
  margin: 0;
  padding: 4px 6px;
}

.nav-item.active { color: var(--primary); }
.nav-item .icon { font-size: 20px; }

.fab {
  position: fixed;
  /* Bottom-left of the (centered, max-width) app card — not the raw viewport edge, so this
     still sits in the right spot on wide screens, not just on a phone-width viewport. */
  bottom: calc(64px + 22px + env(safe-area-inset-bottom));
  left: max(24px, calc(50% - (var(--max-width) / 2) + 24px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #08130a;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  z-index: 60;
}

.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 70;
}

.bottom-sheet {
  width: 100%;
  max-width: var(--max-width);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 250ms ease-out;
}

.bottom-sheet.open { transform: translateY(0); }

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  margin: 0 auto 14px;
}

.bottom-sheet h3 { text-align: center; margin: 0 0 14px; }

.bottom-sheet-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: none;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  text-align: right;
}

.bottom-sheet-icon { font-size: 26px; flex-shrink: 0; }

.bottom-sheet-option-text { display: flex; flex-direction: column; gap: 2px; }
.bottom-sheet-option-text strong { font-size: 15px; }
.bottom-sheet-option-text span:last-child { font-size: 12.5px; color: var(--text-dim); }

.toast {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 50;
}

.toast.show { opacity: 1; }

.app-update-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: calc(100% - 32px);
  max-width: calc(var(--max-width) - 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 14px;
  z-index: 55;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.app-update-banner-text { flex: 1; line-height: 1.5; }

.app-update-banner-btn {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--primary);
  color: #08130a;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.timer { text-align: center; font-size: 32px; font-weight: 700; margin: 16px 0 4px; }

.record-hint { text-align: center; font-size: 13px; margin-bottom: 20px; }

.record-dial {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 28px auto 4px;
}

.record-dial-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.record-dial-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 6;
}

.record-dial-progress {
  fill: none;
  stroke: var(--danger);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292;
  transition: stroke-dashoffset 1s linear;
}

.record-dial-button {
  position: absolute;
  inset: 14px;
  width: auto;
  height: auto;
  margin: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #08130a;
  font-size: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}

.record-dial-button:active { transform: scale(0.96); }

.record-dial.recording .record-dial-button {
  background: var(--danger);
  animation: record-pulse 1.6s ease-out infinite;
}

@keyframes record-pulse {
  0% { box-shadow: 0 0 0 0 rgba(194, 91, 79, 0.5); }
  70% { box-shadow: 0 0 0 18px rgba(194, 91, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(194, 91, 79, 0); }
}

.success-overlay {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(15, 20, 17, 0.92);
  z-index: 100;
  color: var(--text);
  font-size: 16px;
}

.success-overlay.show { display: flex; }

.success-checkmark { width: 88px; height: 88px; }
.success-checkmark svg { width: 100%; height: 100%; }

.success-checkmark-circle {
  fill: none;
  stroke: var(--primary);
  stroke-width: 3;
  stroke-dasharray: 145;
  stroke-dashoffset: 145;
  animation: success-circle 0.5s ease-out forwards;
}

.success-checkmark-check {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: success-check 0.35s 0.45s ease-out forwards;
}

@keyframes success-circle {
  to { stroke-dashoffset: 0; }
}

@keyframes success-check {
  to { stroke-dashoffset: 0; }
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 16px;
}

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-dim); }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.admin-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.admin-card .value { font-size: 22px; font-weight: 700; }
.admin-card .label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.admin-card-clickable { cursor: pointer; }
.admin-card-clickable:active { opacity: 0.7; }

.admin-search-input { width: 100%; margin-bottom: 8px; }

#admin-memory-detail { margin-bottom: 16px; }

.admin-health-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.health-chip {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}

.health-chip.health-healthy { color: var(--primary); }
.health-chip.health-warning { color: #d8a657; }
.health-chip.health-critical { color: var(--danger); }

.admin-chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.admin-chart-card .chart-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }

.admin-activity-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-2);
  color: var(--text-dim);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

.admin-settings-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.admin-settings-form label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.admin-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.pull-refresh {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  z-index: 40;
  transition: top 0.2s ease-out;
}

#pull-refresh-icon { display: inline-block; transition: transform 0.15s ease-out; }
.pull-refresh.armed #pull-refresh-icon { transform: rotate(180deg); }
.pull-refresh.spinning #pull-refresh-icon { animation: pull-refresh-spin 0.7s linear infinite; }

@keyframes pull-refresh-spin {
  to { transform: rotate(360deg); }
}

.star-rating { display: inline-flex; gap: 2px; }
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--surface-2);
  padding: 0;
  line-height: 1;
}
.star-btn.filled { color: gold; }

.admin-scroll-list {
  max-height: 420px;
  overflow-y: auto;
  border-radius: 12px;
}

.reflection-feedback-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin: 14px 0;
}

.reflection-feedback-title {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.reflection-feedback-actions {
  display: flex;
  gap: 8px;
}

.reflection-feedback-actions button {
  margin-bottom: 0;
}

.reflection-feedback-confirmation {
  font-size: 14px;
  color: var(--text);
}

.reflection-feedback-reason.selected {
  background: var(--primary);
  color: #08130a;
  font-weight: 600;
}
