/* ======================================
   THEME VARIABLES
====================================== */
:root {
  --bg: #f8fafc;
  --fg: #1e293b;
  --nav-bg: #1e293b;
  --nav-text: #ffffff;
  --link: #334155;
  --link-hover: #0f172a;
  --pill-bg: #334155;
  --button-bg: #1e293b;
  --button-hover: #334155;
}

body.dark {
  --bg: #0f172a;
  --fg: #e2e8f0;
  --nav-bg: #0b1120;
  --nav-text: #f8fafc;
  --link: #cbd5e1;
  --link-hover: #f8fafc;
  --pill-bg: #1e293b;
  --button-bg: #334155;
  --button-hover: #475569;
}

/* ======================================
   BASE STYLES
====================================== */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Navbar */
.navbar {
  background: var(--nav-bg);
  padding: 0.5rem 1rem;
  color: var(--nav-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.navbar a {
  color: var(--nav-text);
  text-decoration: none;
  margin-right: 0.75rem;
  transition: opacity 0.2s ease;
}
.navbar a:hover { opacity: 0.8; }

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

/* Right side uses gap instead of per-link margins for crisp spacing */
.nav-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;               /* consistent spacing */
}
.nav-right a { margin-right: 0; }

.brand { font-weight: bold; margin-right: 1rem; }

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: none;
  color: var(--nav-text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.theme-toggle:hover { transform: rotate(20deg); opacity: 0.85; }

/* Team pill */
.team-pill {
  background: var(--pill-bg);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.9rem;
  line-height: 1;
}

/* User identity: avatar + username */
.user-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--nav-text);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 6px;
}
.user-link:hover { background: rgba(148,163,184,0.15); }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #334155;
  display: inline-block;
}
.avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--nav-text);
}
.username { font-weight: 600; }

/* Logout button styled like a link chip */
.logout-form {
  display: inline;
  margin: 0;
}

.logout-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--nav-text);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 6px;
  margin: 0;
}
.logout-btn:hover {
  background: rgba(148,163,184,0.15);
}

/* Page layout */
.page-content {
  padding: 1.5rem;
  max-width: 1000px;
  margin: 0 auto;
}

/* Buttons */
button, input[type=submit] {
  background: var(--button-bg);
  color: var(--nav-text);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
}
button:hover, input[type=submit]:hover { background: var(--button-hover); }

/* Generic button utility for links (used in docs + grading) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
}
.btn:hover {
  background: var(--button-hover);
  text-decoration: none;
}

/* Form elements */
form { margin-top: 1rem; }
input[type=text], input[type=password], input[type=email], textarea, select {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  box-sizing: border-box;
}

/* Typography & links */
h1, h2, h3 { color: var(--fg); }
a { color: var(--link); }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* =========================
   Auth pages
========================= */
.auth-card {
  max-width: 460px;
  margin: 2rem auto;
  background: var(--bg);
  color: var(--fg);
}

.auth-card h1 { margin: 0 0 1rem 0; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1rem 0;
}
.auth-divider .line {
  flex: 1;
  height: 1px;
  background: rgba(148, 163, 184, 0.4); /* slate-400 @ 40% */
}
.auth-divider span {
  color: #94a3b8; /* slate-400 */
  font-size: .9rem;
}

/* Details/toggle */
.auth-details summary {
  cursor: pointer;
  color: var(--link);
  font-size: .95rem;
  list-style: none;
}
.auth-details summary::-webkit-details-marker { display: none; }
.auth-details summary::after { content: " ▾"; opacity: .7; }
.auth-details[open] summary::after { content: " ▴"; opacity: .7; }
.details-body { margin-top: 1rem; }

/* ======================================
   Discord Primary Sign-In Button
====================================== */
.btn-discord {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  max-width: 400px;
  margin: 1.5rem auto;
  background-color: #5865F2; /* Discord blurple */
  color: #fff;
  font-weight: 600;
  padding: 1rem 1.25rem;
  border-radius: 0.6rem;
  text-decoration: none;
  font-size: 1.05rem;
  line-height: 1.2;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.2s ease;
}

.btn-discord:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.btn-discord:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* For theme consistency */
body.dark .btn-discord {
  background-color: #5865F2;
  color: #fff;
}
body.dark .btn-discord:hover {
  filter: brightness(1.2);
}

/* Discord logo inside button */
.btn-discord img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  filter: brightness(1.1);
}

/* ======================================
   Auth Page Centering
====================================== */
.auth-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  text-align: center;
}

.auth-center h1 {
  margin-bottom: 1.5rem;
  font-size: 1.8rem;
}

/* Ensure details/secondary forms look good centered */
.auth-center details {
  max-width: 400px;
  width: 100%;
  margin-top: 1rem;
  text-align: left;
}

/* Errors + small help text */
.auth-error { color: #ef4444; margin: .25rem 0 .75rem; }
.auth-help { margin-top: .5rem; font-size: .9rem; }
.auth-foot { margin-top: 1rem; font-size: .9rem; }

.messages {
  margin-bottom: 1rem;
}

.message {
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}
.message.success { background: #dcfce7; color: #166534; }
.message.error { background: #fee2e2; color: #b91c1c; }
.message.info { background: #e0f2fe; color: #075985; }

/* =========================
   Markdown Editor Layout
========================= */

.md-editor {
  display: flex;
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.md-editor-main,
.md-preview {
  flex: 1;
  min-width: 0;
}

/* Toolbar */
.md-toolbar {
  display: flex;
  gap: 0.25rem;
  margin: 0.25rem 0 0.5rem 0;
}

.md-toolbar button {
  background: var(--button-bg);
  color: var(--nav-text);
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.02s ease;
}

.md-toolbar button:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
}

/* Textarea – make it fill the column */
#id_body {
  width: 100%;
  min-height: 300px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  resize: vertical;
}

/* Preview panel */
.md-preview {
  background: rgba(15, 23, 42, 0.03);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.5rem;
  overflow: auto;
}

body.dark .md-preview {
  background: rgba(15, 23, 42, 0.6);
  border-color: #475569;
}

.md-preview-inner {
  font-size: 0.95rem;
}

/* Autosave status */
.autosave-status {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.25rem;
}

/* Mobile: stack editor & preview */
@media (max-width: 900px) {
  .md-editor {
    flex-direction: column;
  }
}

.md-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.md-preview-toggle {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(148, 163, 184, 0.7);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
}

body.dark .md-preview-toggle {
  color: var(--fg);
  border-color: #64748b;
}

.md-preview-toggle:hover {
  background: var(--button-bg);
  color: var(--nav-text);
}

.alert {
  position: relative;
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  background: rgba(59, 130, 246, 0.1); /* default info */
  color: var(--fg);
}

/* Variants based on Django message tags */
.alert-success {
  background: rgba(34, 197, 94, 0.12);
}

.alert-error,
.alert-danger {
  background: rgba(239, 68, 68, 0.12);
}

.alert-warning {
  background: rgba(234, 179, 8, 0.12);
}

.alert-info {
  background: rgba(59, 130, 246, 0.1);
}

.alert-close {
  position: absolute;
  right: 0.5rem;
  top: 0.3rem;
  border: none;
  background: none;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
}

.alert-close:hover {
  opacity: 0.7;
}

/* =========================
   Milestone list (grading)
========================= */

.milestone-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.milestone-item {
  background: var(--bg);
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

body.dark .milestone-item {
  border-color: #334155;
}

.milestone-title {
  font-size: 1.05rem;
}

.milestone-due {
  color: #64748b;
  font-size: 0.9rem;
  margin-left: 0.35rem;
}

/* small badge for "Submitted" state */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-success {
  background: #16a34a;
  color: #ffffff;
}

/* small buttons used next to milestones */
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.8rem;
  border: none;
  cursor: pointer;
  margin-left: 0.4rem;
  transition: background 0.2s ease;
}

.btn-sm:hover {
  background: var(--button-hover);
  text-decoration: none;
}

.btn-staff {
  background: #475569;
}

.btn-staff:hover {
  background: #1f2933;
}

/* Optional: nicer spacing for rendered Markdown blocks */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin-top: 1.2rem;
  margin-bottom: 0.5rem;
}

.markdown-body p {
  margin: 0.4rem 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.5rem 0 0.5rem 1.25rem;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: rgba(148, 163, 184, 0.25);
  padding: 0 0.2rem;
  border-radius: 3px;
}

.markdown-body pre {
  background: #0f172a10;
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
}

body.dark .markdown-body pre {
  background: rgba(15, 23, 42, 0.8);
}
