/* Restore Purity — App Styles */

:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #3730a3;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-success: #22c55e;
  --color-error: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.subtitle {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--color-text-muted);
}

.field input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--color-surface);
}

.field input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:active {
  opacity: 0.8;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.status-indicator {
  text-align: center;
  padding: 1rem;
  color: var(--color-text-muted);
}

.option-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.option-item:hover {
  background: var(--color-bg);
}

.option-item input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
}

.hint {
  margin-top: 1rem;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  padding: 2rem;
}

blockquote {
  font-size: 1.25rem;
  font-style: italic;
  color: var(--color-primary);
  border-left: 4px solid var(--color-primary);
  padding-left: 1rem;
  margin: 1rem 0;
}

.tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.tags span {
  background: var(--color-bg);
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ──────────────────────────────────────────────
   Admin page
   ────────────────────────────────────────────── */

.admin-page {
  max-width: 640px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-inline .hint {
  margin-top: 0;
  text-align: left;
}

.form-group input[type="email"],
.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--color-bg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
  background: var(--color-surface);
}

.form-divider {
  height: 1px;
  background: var(--color-border);
  margin: 0.25rem 0;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
}

.form-check input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--color-primary);
  flex-shrink: 0;
}

.form-check label {
  margin-bottom: 0;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.875rem;
  color: var(--color-text);
  cursor: pointer;
}

.admin-form .btn {
  width: 100%;
  padding: 0.7rem;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.lecturer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lecturer-row:last-child {
  border-bottom: none;
}

.lecturer-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.lecturer-email {
  font-weight: 600;
  font-size: 0.9rem;
}

.lecturer-name {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.lecturer-badges {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-super {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-disabled {
  background: #fef2f2;
  color: #991b1b;
}

.lecturer-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-warning {
  background: #f59e0b;
  color: white;
}

.btn-warning:hover {
  background: #d97706;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  width: 90%;
  max-width: 400px;
}

.modal-content h3 {
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.template-picker-item:hover {
  background: var(--color-surface-2);
}

.alert-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ──────────────────────────────────────────────
   Responsive Navbar
   ────────────────────────────────────────────── */

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 56px;
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
  white-space: nowrap;
}

.navbar-brand:hover {
  color: var(--color-primary-dark);
}

.navbar-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
}

.navbar-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.navbar-toggle.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.navbar-toggle.open span:nth-child(2) {
  opacity: 0;
}

.navbar-toggle.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.nav-link.active {
  color: var(--color-primary);
  background: rgba(79,70,229,0.08);
}

.nav-link-logout {
  color: var(--color-error);
}

.nav-link-logout:hover {
  background: #fef2f2;
  color: var(--color-error);
}

#content {
  padding-top: 0.5rem;
}

/* Mobile responsive */
@media (max-width: 640px) {
  .navbar-toggle {
    display: flex;
  }

  .navbar-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 4px 6px rgba(0,0,0,0.06);
    padding: 0.5rem 1rem 1rem;
    gap: 0.125rem;
  }

  .navbar-links.open {
    display: flex;
  }

  .nav-link {
    width: 100%;
    padding: 0.625rem 0.75rem;
  }
}

/* ──────────────────────────────────────────────
   Admin tabs
   ────────────────────────────────────────────── */

.admin-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
}

.tab {
  flex: 1;
  padding: 0.625rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--color-text);
}

.tab.tab-active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-bg);
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.tab-content textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
  background: var(--color-surface);
}

.encouragement-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  gap: 0.5rem;
}

.encouragement-row:last-child {
  border-bottom: none;
}

.encouragement-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  flex: 1;
}

.encouragement-text {
  font-size: 0.9rem;
  line-height: 1.5;
}

.encouragement-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.encouragement-tags {
  font-size: 0.75rem;
  color: var(--color-primary);
}

.encouragement-date {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.badge-deleted {
  background: #fef2f2;
  color: #991b1b;
}

.encouragement-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
  align-items: center;
}

/* Quill editor sizing */
.quill-editor {
  min-height: 120px;
}

.quill-editor .ql-editor {
  min-height: 100px;
  font-size: 0.95rem;
  font-family: inherit;
}

/* Encouragement preview HTML rendering */
blockquote p {
  margin: 0.25rem 0;
}

blockquote ul, blockquote ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.encouragement-text p {
  margin: 0.15rem 0;
}

.encouragement-text ul, .encouragement-text ol {
  margin: 0.25rem 0;
  padding-left: 1.25rem;
}

/* Resize Quill container for edit modal */
#enc-modal .quill-editor {
  min-height: 150px;
}

#enc-modal .ql-editor {
  min-height: 130px;
}

/* ──────────────────────────────────────────────
   Online Content
   ────────────────────────────────────────────── */

.nav-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--color-success);
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.online-content-page {
  max-width: 640px;
}

.content-card {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

.content-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.content-thumb {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--color-bg);
}

.content-card-text {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.content-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.content-desc {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin: 0;
}

.content-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* Article overlay */
.article-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--color-surface);
  overflow-y: auto;
}

.article-topbar {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1rem;
}

.article-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.article-content h1 {
  margin-bottom: 1rem;
}

.article-hero {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.article-body {
  font-size: 1.05rem;
  line-height: 1.75;
}

.article-body img {
  max-width: 100%;
  border-radius: var(--radius);
}

.article-body h1,
.article-body h2,
.article-body h3 {
  margin: 1.5rem 0 0.5rem;
}

.article-body p {
  margin: 0.75rem 0;
}

.article-body ul,
.article-body ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.article-body blockquote {
  border-left: 4px solid var(--color-primary);
  padding-left: 1rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Admin: content rows */
.content-admin-note {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.content-admin-toggle {
  padding: 0 0 0.25rem;
}

.content-admin-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.content-admin-row:last-child {
  border-bottom: none;
}

.content-admin-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--color-bg);
}

.content-admin-thumb-empty {
  border: 1px dashed var(--color-border);
}

.content-admin-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1;
}

.content-admin-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.content-admin-meta {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.content-admin-order {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.content-admin-audit {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.content-admin-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.badge-published {
  background: #dcfce7;
  color: #166534;
}

.badge-draft {
  background: #f1f5f9;
  color: #475569;
}

.badge-unsorted {
  background: #fef3c7;
  color: #92400e;
}

.form-group input[type="file"] {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

#content-modal .quill-editor {
  min-height: 200px;
}

#content-modal .ql-editor {
  min-height: 180px;
}

/* Visual / HTML source tabs for the article editor */
.editor-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  width: fit-content;
}

.editor-tab {
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.editor-tab + .editor-tab {
  border-left: 1px solid var(--color-border);
}

.editor-tab.editor-tab-active {
  background: var(--color-primary);
  color: #fff;
}

/* Dark source view. The selector is `textarea.html-source` so it outranks the
   generic `.tab-content textarea` rule above, which would otherwise paint the
   textarea white while leaving the light text colour in place. */
textarea.html-source {
  width: 100%;
  min-height: 200px;
  padding: 0.75rem;
  border: 1px solid #334155;
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  background: #1e293b;
  color: #f1f5f9;
  caret-color: #f1f5f9;
  resize: vertical;
}

textarea.html-source::placeholder {
  color: #94a3b8;
  opacity: 1;
}

textarea.html-source::selection {
  background: #4f46e5;
  color: #fff;
}

textarea.html-source:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #1e293b;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.35);
}

/* Responsive embeds inside rendered articles */
.article-body iframe,
.ql-editor iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius);
  margin: 1rem 0;
}

/* Loading slider shown behind an embed until its document paints over it.
   The iframe's own background sits behind the embedded page, so once the
   iframe loads, the page's background hides the animation. */
.article-body iframe,
.ql-editor iframe {
  background-color: var(--color-border);
  background-image: linear-gradient(
    90deg,
    transparent 0%,
    var(--color-primary) 20%,
    var(--color-primary) 80%,
    transparent 100%
  );
  background-repeat: no-repeat;
  background-size: 35% 100%;
  animation: iframe-loading-slide 1.2s ease-in-out infinite;
}

@keyframes iframe-loading-slide {
  from {
    background-position: -40% 0;
  }
  to {
    background-position: 140% 0;
  }
}

.article-body iframe.embed-loaded,
.ql-editor iframe.embed-loaded {
  animation: none;
  background-color: transparent;
  background-image: none;
}

@media (prefers-reduced-motion: reduce) {
  .article-body iframe,
  .ql-editor iframe {
    animation: none;
    background-image: none;
  }
}

/* Audio players inside rendered articles and the visual editor */
.article-body audio,
.ql-editor audio {
  display: block;
  width: 100%;
  margin: 1rem 0;
}

/* ──────────────────────────────────────────────
   Premium page
   ────────────────────────────────────────────── */

.premium-message {
  min-height: 1.25em;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #b91c1c;
}

.premium-loading {
  padding: 2rem 0;
}

.premium-sections {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.premium-section-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 16px;
  text-align: left;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
}

.premium-section-card:hover {
  border-color: #c7d2fe;
}

.premium-section-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: #1e293b;
}

.premium-section-desc {
  font-size: 0.9rem;
  color: #64748b;
}

.premium-section-title {
  margin: 12px 0;
}

.premium-content-row {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 10px 0;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}

.premium-content-thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.premium-content-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.premium-content-title {
  font-weight: 600;
  color: #1e293b;
}

.premium-content-desc {
  font-size: 0.9rem;
  color: #64748b;
}

.premium-footer {
  margin-top: 24px;
  padding-bottom: 24px;
  text-align: center;
}

.premium-code-value {
  margin: 12px 0;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  text-align: center;
  word-break: break-all;
  background: #f1f5f9;
  border-radius: 8px;
  user-select: all;
}

#pm-code-sections {
  display: grid;
  gap: 6px;
}

#pm-code-sections .form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.premium-toast {
  margin-bottom: 12px;
}
