/* ── NORA Mini App Styles ────────────────────────────── */
:root {
  --bg: var(--tg-theme-bg-color, #1a1a2e);
  --fg: var(--tg-theme-text-color, #e0e0e0);
  --hint: var(--tg-theme-hint-color, #8a8a9a);
  --link: var(--tg-theme-link-color, #6c63ff);
  --btn-bg: var(--tg-theme-button-color, #6c63ff);
  --btn-fg: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #252540);
  --accent-green: #4caf50;
  --accent-orange: #ff9800;
  --accent-red: #f44336;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

#app { max-width: 480px; margin: 0 auto; padding: 12px 16px 80px; }

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
}
header h1 { font-size: 1.4rem; font-weight: 700; }
#streak-badge {
  font-size: 0.9rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--secondary-bg);
  white-space: nowrap;
}

/* ── Navigation ──────────────────────────────────────── */
nav {
  display: flex;
  gap: 4px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.nav-btn {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--hint);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn.active {
  background: var(--btn-bg);
  color: var(--btn-fg);
}

/* ── Views ───────────────────────────────────────────── */
.view { transition: opacity 0.2s; }
.hidden { display: none !important; }

/* ── Loading ─────────────────────────────────────────── */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 40%;
  gap: 12px;
  color: var(--hint);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--btn-bg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress Bar ────────────────────────────────────── */
#progress-bar-wrap {
  position: relative;
  height: 28px;
  background: var(--secondary-bg);
  border-radius: 14px;
  margin-bottom: 16px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  border-radius: 14px;
  background: linear-gradient(90deg, var(--accent-green), #81c784);
  transition: width 0.4s ease;
  width: 0%;
}
#progress-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ── Checklist Items ─────────────────────────────────── */
#checklist-items { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }

.time-group-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--hint);
  padding: 8px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
  user-select: none;
  -webkit-user-select: none;
}
.item-row:active { transform: scale(0.98); }
.item-row.done { opacity: 0.6; }
.item-row.paused { opacity: 0.4; pointer-events: none; }
.item-row.critical:not(.done) { border-left: 3px solid var(--accent-orange); }
.critical-badge { font-size: 0.75rem; }

.item-check {
  width: 24px; height: 24px;
  border: 2px solid var(--hint);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  font-size: 0.85rem;
}
.item-row.done .item-check {
  background: var(--accent-green);
  border-color: var(--accent-green);
}

.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 0.95rem; font-weight: 500; }
.item-streak {
  font-size: 0.7rem;
  color: var(--accent-orange);
  margin-left: 4px;
  white-space: nowrap;
}
.item-detail {
  font-size: 0.75rem;
  color: var(--hint);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Action Buttons ──────────────────────────────────── */
#checklist-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.action-btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.action-btn:active { opacity: 0.8; }
.action-btn.secondary {
  background: var(--secondary-bg);
  color: var(--fg);
}
.action-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ── Stats ───────────────────────────────────────────── */
.stats-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.stats-card h3 { font-size: 0.9rem; color: var(--hint); margin-bottom: 8px; }
.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.9rem;
}
.stats-row .label { color: var(--hint); }
.stats-bar-bg {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
}
.stats-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent-green);
  transition: width 0.4s ease;
}

/* ── Settings ────────────────────────────────────────── */
.settings-section {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.settings-section h3 {
  font-size: 0.85rem;
  color: var(--hint);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#style-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.style-chip {
  padding: 8px 16px;
  border: 2px solid var(--hint);
  border-radius: 20px;
  background: transparent;
  color: var(--fg);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.style-chip.active {
  border-color: var(--btn-bg);
  background: var(--btn-bg);
  color: var(--btn-fg);
}

#quiet-hours-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
#quiet-hours-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--hint);
}
#quiet-hours-form input {
  width: 60px;
  padding: 8px;
  border: 1px solid var(--hint);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  text-align: center;
}
#quiet-hours-form .action-btn { flex: 0; min-width: auto; padding: 8px 16px; }

#profile-info { font-size: 0.9rem; line-height: 1.6; }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 20px;
  background: var(--secondary-bg);
  color: var(--fg);
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
}
.toast.show { opacity: 1; }

/* ── Item Spinner (in-flight) ────────────────────────── */
.item-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--hint);
  border-top-color: var(--btn-bg);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Loading Button State ────────────────────────────── */
.action-btn.loading {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}
.action-btn.loading::after {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

/* ── Paused Label ────────────────────────────────────── */
.paused-label { color: var(--accent-orange); font-style: italic; }

/* ── Time Slot Rows ──────────────────────────────────── */
.ts-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.ts-row:last-child { border-bottom: none; }
.ts-label {
  text-transform: capitalize;
  font-size: 0.9rem;
}
.ts-input {
  padding: 6px 10px;
  border: 1px solid var(--hint);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
  width: 100px;
}

/* ── Item Manager ────────────────────────────────────── */
.im-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.im-row:last-child { border-bottom: none; }
.im-row.paused .im-name { opacity: 0.5; text-decoration: line-through; }
.im-name { font-size: 0.9rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 8px;
  transition: all 0.2s;
}
.im-btn.pause {
  background: rgba(255,152,0,0.15);
  color: var(--accent-orange);
}
.im-btn.resume {
  background: rgba(76,175,80,0.15);
  color: var(--accent-green);
}

/* ── Toggle Row ──────────────────────────────────────── */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  cursor: pointer;
}
.toggle-row input[type="checkbox"] {
  width: 20px; height: 20px;
  accent-color: var(--btn-bg);
}

/* ── Feedback Form ───────────────────────────────────── */
.feedback-form { display: flex; flex-direction: column; gap: 8px; }
.feedback-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--hint);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  min-height: 60px;
}
.feedback-form .action-btn { align-self: flex-end; min-width: auto; flex: 0; }

/* ── Hint Text ───────────────────────────────────────── */
.hint-text { color: var(--hint); font-size: 0.85rem; font-style: italic; padding: 4px 0; }
