/* ── 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 ───────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── View Transitions (slide left/right) ─────────────── */
#views-container {
  position: relative;
  overflow: hidden;
}
.view-page {
  display: none;
}
.view-page.active-page {
  display: block;
  position: relative;
}
/* Incoming page overlays during slide */
.view-page.sliding-in {
  display: block;
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  z-index: 2;
}
/* Active page being slid out */
.view-page.active-page.slide-out-left,
.view-page.active-page.slide-out-right {
  position: relative;  /* keep container height */
  z-index: 1;
}
.view-page.slide-in-right {
  animation: slideInRight var(--slide-duration, 0.35s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.view-page.slide-in-left {
  animation: slideInLeft var(--slide-duration, 0.35s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.view-page.slide-out-right {
  animation: slideOutRight var(--slide-duration, 0.35s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.view-page.slide-out-left {
  animation: slideOutLeft var(--slide-duration, 0.35s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0.3; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideInLeft {
  from { transform: translateX(-100%); opacity: 0.3; }
  to   { transform: translateX(0);     opacity: 1; }
}
@keyframes slideOutRight {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}
@keyframes slideOutLeft {
  from { transform: translateX(0);     opacity: 1; }
  to   { transform: translateX(-100%); opacity: 0; }
}

/* ── Prompt Modal ─────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 20px;
  width: min(90vw, 360px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
}
.modal-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--hint);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
}
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-actions .action-btn {
  min-width: 0;
  flex: 1;
  padding: 10px 8px;
  font-size: 0.82rem;
}

/* ── Iris Loading Overlay ────────────────────────────── */
#iris-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg, #1a1a2e);
}
#iris-overlay.open {
  pointer-events: none;
}
#iris-overlay.done {
  display: none;
}
#iris-logo {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--btn-bg, #6c63ff);
  letter-spacing: 6px;
  animation: irisPulse 1.2s ease-in-out infinite;
}
#iris-overlay.open #iris-logo {
  animation: irisLogoFade 0.25s ease-out forwards;
}

/* The app gets revealed through an expanding circle clip */
#app.iris-revealing {
  clip-path: circle(0% at 50% 40%);
  animation: irisReveal 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes irisPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.05); }
}
@keyframes irisLogoFade {
  to { opacity: 0; transform: scale(1.4); }
}
@keyframes irisReveal {
  0%   { clip-path: circle(0% at 50% 40%); }
  100% { clip-path: circle(100% at 50% 40%); }
}

/* ── 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.danger {
  background: #d32f2f;
  color: #fff;
}
.action-btn.danger:active { background: #b71c1c; }
.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, #reminder-profile-picker { display: flex; flex-direction: column; gap: 8px; }
.option-card {
  padding: 10px 14px;
  border: 2px solid var(--hint);
  border-radius: var(--radius);
  background: var(--secondary-bg);
  cursor: pointer;
  transition: all 0.2s;
}
.option-card.active {
  border-color: var(--btn-bg);
  background: color-mix(in srgb, var(--btn-bg) 18%, var(--secondary-bg));
}
.option-label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 2px;
}
.option-card.active .option-label { color: var(--btn-bg); }
.option-desc {
  font-size: 0.75rem;
  color: var(--hint);
  line-height: 1.35;
}

#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; }

/* ── Admin Panel ─────────────────────────────────────── */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.admin-tab {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--hint);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.admin-tab.active {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-color: var(--btn-bg);
}
.admin-panel { min-height: 60px; }
.admin-user-list, .admin-msg-list { display: flex; flex-direction: column; gap: 2px; }
.admin-user-row, .admin-msg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.admin-user-row:last-child, .admin-msg-row:last-child { border-bottom: none; }
.admin-user-name { font-weight: 600; font-size: 0.9rem; }
.admin-user-meta { font-size: 0.8rem; color: var(--hint); }
.admin-msg-key { font-size: 0.9rem; font-family: monospace; }
.admin-textarea {
  width: 100%;
  min-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--hint);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-family: monospace;
  font-size: 0.8rem;
  resize: vertical;
  margin-top: 8px;
}
.admin-editor { display: flex; flex-direction: column; gap: 8px; }
.admin-editor-actions { display: flex; gap: 8px; justify-content: flex-end; }
.admin-system { display: flex; flex-direction: column; }
.admin-user-row.clickable { cursor: pointer; border-radius: var(--radius); padding: 10px 8px; transition: background 0.15s; }
.admin-user-row.clickable:hover, .admin-user-row.clickable:active { background: rgba(255,255,255,0.06); }
.admin-detail { display: flex; flex-direction: column; gap: 2px; }
.admin-detail-header { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.admin-actions .action-btn { font-size: 0.78rem; padding: 6px 10px; }
.admin-sys-output { max-height: 300px; overflow-y: auto; }
.admin-log-pre { font-size: 0.7rem; line-height: 1.3; white-space: pre-wrap; word-break: break-all; background: rgba(0,0,0,0.2); padding: 8px; border-radius: var(--radius); max-height: 280px; overflow-y: auto; }
.admin-access-row { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.admin-access-row:last-child { border-bottom: none; }
.admin-feedback-list { display: flex; flex-direction: column; gap: 2px; }
.admin-feedback-row { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.admin-feedback-row:last-child { border-bottom: none; }
.admin-feedback-text { font-size: 0.85rem; margin-top: 2px; opacity: 0.9; }
.admin-history { display: flex; flex-wrap: wrap; align-items: center; }
