/* ── Reset & base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
*::-webkit-scrollbar { display: none; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f2f5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Screens ── */
.screen { min-height: 100vh; min-height: 100dvh; }
.screen.hidden { display: none; }

.inner {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

/* ── Quote block ── */
#quote-block {
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  height: 148px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#quote-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}

#quote-lang-toggle { display: flex; gap: 6px; }

.lang-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: #f0f2f5;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.15s;
}
.lang-btn.active { border-color: #6c63ff; }

#quote-nav { display: flex; gap: 4px; }

#quote-nav button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #f0f2f5;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #555;
  transition: background 0.15s;
}
#quote-nav button:hover:not(:disabled) { background: #e0deff; color: #6c63ff; }
#quote-nav button:disabled { opacity: 0.3; cursor: default; }

#quote-text {
  font-size: 14px;
  font-style: italic;
  color: #444;
  line-height: 1.5;
  margin-bottom: 6px;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
}

#quote-author {
  font-size: 12px;
  color: #888;
  font-weight: 500;
  flex-shrink: 0;
}

/* ── Habit cards ── */
#habits-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.habit-card {
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.13);
  cursor: pointer;
  transition: background-color 0.3s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.habit-card:active { transform: scale(0.975); }

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

.habit-title {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
}

.streak {
  font-size: 13px;
  color: rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.15);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.days-indicators {
  display: flex;
  gap: 5px;
  margin-bottom: 14px;
  flex-wrap: nowrap;
}

.day-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
}
.day-dot.active { background: rgba(255,255,255,0.5); color: #333; }
.day-dot.today  { outline: 2px solid rgba(255,255,255,0.9); color: #fff; }
.day-dot.done   { background: #4caf50; color: #fff; }

.complete-btn {
  padding: 10px 22px;
  border: 2px solid rgba(255,255,255,0.75);
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.complete-btn:hover { background: rgba(255,255,255,0.2); }

/* ── FAB buttons ── */
#fab-btn, #stats-fab-btn {
  position: fixed;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(108,99,255,0.45);
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  background: #6c63ff;
}
#fab-btn { right: 24px; font-size: 30px; line-height: 1; }
#stats-fab-btn { left: 24px; font-size: 22px; }
#fab-btn:active, #stats-fab-btn:active { transform: scale(0.93); }

/* ── Form screen ── */
#form-screen .inner { padding-bottom: 40px; }

#back-btn, #stats-back-btn {
  background: none;
  border: none;
  font-size: 16px;
  color: #6c63ff;
  cursor: pointer;
  padding: 0;
  margin-bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}
#back-btn:hover, #stats-back-btn:hover { opacity: 0.75; }

.form-block {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-block h2 { font-size: 20px; color: #222; }

.form-block input[type="text"],
.form-block input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-block input[type="text"]:focus,
.form-block input[type="number"]:focus { border-color: #6c63ff; }

.form-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: #555;
}

.days-row { display: flex; gap: 8px; flex-wrap: wrap; }

.day-pick { cursor: pointer; user-select: none; }
.day-pick input[type="checkbox"] { display: none; }
.day-pick span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.day-pick input[type="checkbox"]:checked ~ span {
  background: #6c63ff;
  border-color: #6c63ff;
  color: #fff;
}

#save-btn {
  padding: 14px;
  background: #6c63ff;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
#save-btn:hover { background: #574fd6; }

#undo-btn {
  padding: 14px;
  background: transparent;
  color: #f5a623;
  border: 2px solid #f5a623;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
#undo-btn:hover { background: #f5a623; color: #fff; }

#delete-btn {
  padding: 14px;
  background: transparent;
  color: #e53935;
  border: 2px solid #e53935;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
#delete-btn:hover { background: #e53935; color: #fff; }

/* ── Stats / Chart ── */
#stats-screen .inner { padding-bottom: 40px; }

.chart-container {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.chart-title {
  font-size: 17px;
  font-weight: 600;
  color: #222;
  margin-bottom: 14px;
}

.stats-dates {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stats-dates label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #555;
}
.stats-dates input[type="date"] {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  color: #333;
}
.stats-dates input[type="date"]:focus { border-color: #6c63ff; }

.chart-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  margin-bottom: 8px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 6px 6px 0 0;
  overflow: hidden;
  transition: height 0.4s ease;
  min-height: 4px;
  background: #f0f2f5;
  cursor: pointer;
}
.bar-col:hover { opacity: 0.85; }

.bar-missed { background: #ef5350; }
.bar-done   { background: #4caf50; }

.bar-col.bar-today { outline: 2px solid #6c63ff; border-radius: 6px 6px 0 0; }

.chart-labels {
  display: flex;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  margin-bottom: 16px;
}

.bar-label {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: #888;
}
.bar-label.bar-today { color: #6c63ff; font-weight: 700; }

.chart-legend {
  display: flex;
  gap: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #555;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-dot.done   { background: #4caf50; }
.legend-dot.missed { background: #ef5350; }

/* ── Confirm modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none !important; }

.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 320px;
  width: calc(100% - 40px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-box p {
  font-size: 16px;
  color: #333;
  line-height: 1.5;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-actions button {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  transition: opacity 0.15s;
}
.modal-actions button:hover { opacity: 0.8; }
#modal-cancel { background: #f0f2f5; color: #555; }
#modal-ok     { background: #6c63ff; color: #fff; }

/* ── Offline toast ── */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Stats details ── */
#stats-details {
  background: #fff;
  border-radius: 16px;
  padding: 0;
  margin-top: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  overflow: hidden;
  transition: all 0.2s;
}
#stats-details:empty { display: none; }

.details-date {
  font-size: 15px;
  font-weight: 600;
  color: #222;
  padding: 16px 18px 10px;
  border-bottom: 1px solid #f0f2f5;
}

.details-group { padding: 12px 18px; }
.details-group + .details-group { border-top: 1px solid #f0f2f5; }

.details-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #555;
}

.details-group ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.details-group ul li {
  font-size: 14px;
  color: #333;
  padding: 6px 10px;
  border-radius: 8px;
}

.done-group ul li { background: rgba(76,175,80,0.1); color: #2e7d32; }
.missed-group ul li { background: rgba(239,83,80,0.1); color: #c62828; }

.details-empty {
  padding: 16px 18px;
  font-size: 14px;
  color: #aaa;
}

/* ── Mobile tweaks ── */
@media (max-width: 400px) {
  .days-indicators { gap: 3px; }
  .day-dot { height: 30px; font-size: 9px; }
  .habit-card { padding: 14px 14px; }
}
