/* =====================================
   Professional Blogging App Styles
   Fully Responsive – Card Fix
   ===================================== */

/* ----- Light & Dark Variables ----- */
:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary-color: #64748b;
  --accent-color: #0ea5e9;
  --light-bg: #f8fafc;
  --dark-bg: #1e293b;
  --text-dark: #0f172a;
  --text-muted: #475569;
  --border-light: #e2e8f0;
  --card-bg: #ffffff;
  --body-bg: #ffffff;
  --navbar-bg: rgba(255, 255, 255, 0.95);
  --toggler-icon: #0f172a;
  --toggler-border: #0f172a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --secondary-color: #94a3b8;
  --accent-color: #38bdf8;
  --light-bg: #0f172a;
  --dark-bg: #020617;
  --text-dark: #f1f5f9;
  --text-muted: #cbd5e1;
  --border-light: #334155;
  --card-bg: #1e293b;
  --body-bg: #0f172a;
  --navbar-bg: rgba(30, 41, 59, 0.95);
  --toggler-icon: #f1f5f9;
  --toggler-border: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);
}

body {
  font-family: var(--font-sans);
  color: var(--text-dark);
  background-color: var(--body-bg);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.2s ease;
}

/* ----- Navbar (brand & nav left, toggle right) ----- */
.navbar {
  background-color: var(--navbar-bg) !important;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-light);
  position: relative;
  z-index: 999;
}

.navbar-toggler {
  border: 2px solid var(--border-light) !important;
  background-color: transparent !important;
}

.navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23000' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
}

[data-theme="dark"] .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23fff' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--primary-color) !important;
  margin-right: 1rem;
}

.navbar-nav .nav-link {
  font-weight: 500;
  color: var(--text-dark) !important;
  padding: 0.5rem 1rem !important;
}

.navbar-nav .nav-link:hover {
  color: var(--primary-color) !important;
}

/* Theme toggle button (right side) */
.theme-toggle {
  border: 2px solid var(--border-light);
  background: transparent;
  color: var(--text-dark);
  font-size: 1.2rem;
  padding: 0.25rem 0.75rem;
  border-radius: 2rem;
  transition: all 0.2s ease;
  margin-left: 1rem;
}

.theme-toggle:hover {
  background: var(--border-light);
  transform: scale(1.05);
}

.navbar-collapse {
  justify-content: space-between;
}

/* Mobile adjustments for navbar */
@media (max-width: 991px) {
  .navbar-collapse {
    flex-direction: column;
    align-items: flex-start;
    margin-top: 1rem;
  }
  .theme-toggle {
    margin-left: 0;
    margin-top: 0.5rem;
    align-self: flex-start;
  }
  .navbar-nav {
    width: 100%;
  }
  .nav-item {
    width: 100%;
  }
  .dropdown-menu {
    position: static !important;
    float: none;
    width: 100%;
    margin-top: 0.5rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-light);
  }
}

/* ----- Dropdown (fix z-index) ----- */
.dropdown-menu {
  z-index: 1050 !important;
  position: absolute !important;
  top: 100%;
  right: 0;
  left: auto;
}

/* ========== CARDS – FIXED RESPONSIVE ========== */

.card {
  border: none;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
  height: 100%;
  background: var(--card-bg);
  width: 100% !important;     /* let the column control width, not the card */
  margin: 0 auto !important;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-img-top {
  height: 200px;
  object-fit: cover;
  width: 100%;
}

.card-body {
  padding: 1.25rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-dark);
  word-break: break-word;
  hyphens: manual;            /* ← was "auto" — this was causing the ugly syllable breaks */
  line-height: 1.4;
}

/* Give each column vertical spacing */
.row-cols-1 .col,
.row-cols-2 .col,
.row-cols-3 .col {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

/* MOBILE: < 576px — 1 card per row, full width */
@media (max-width: 575.98px) {
  .row-cols-3 > .col {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .card-img-top { height: 180px; }
  .card-title { font-size: 1rem; }
}

/* TABLET: 576px–767px — 2 cards per row */
@media (min-width: 576px) and (max-width: 767.98px) {
  .row-cols-3 > .col {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    width: 50% !important;
  }
  .card-title { font-size: 1rem; }
}

/* DESKTOP: ≥ 768px — 3 cards per row */
@media (min-width: 768px) {
  .row-cols-3 > .col {
    flex: 0 0 33.3333% !important;
    max-width: 33.3333% !important;
    width: 33.3333% !important;
  }
}

/* ========== END CARDS ========== */

/* ----- Blog Post Card (auto‑detect container with title, image, and pre) ----- */
body > .container.mt-3:has(h1):has(img):has(pre) {
  background: var(--card-bg) !important;
  border-radius: 1.5rem !important;
  padding: 2rem !important;
  box-shadow: var(--shadow-md) !important;
  margin-bottom: 2rem !important;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body > .container.mt-3:has(h1):has(img):has(pre) h1 {
  margin-top: 0 !important;
  font-size: 2.5rem !important;
  color: var(--text-dark) !important;
  word-wrap: break-word;
}

body > .container.mt-3:has(h1):has(img):has(pre) img {
  border-radius: 1rem !important;
  max-width: 100% !important;
  height: auto !important;
  margin: 1.5rem 0 !important;
  box-shadow: var(--shadow-sm) !important;
}

body > .container.mt-3:has(h1):has(img):has(pre) pre {
  background-color: var(--light-bg) !important;
  padding: 1.5rem !important;
  border-radius: 1rem !important;
  border: 1px solid var(--border-light) !important;
  margin: 0 !important;
  color: var(--text-dark) !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  font-family: inherit !important;
  font-size: 1rem !important;
  line-height: 1.6 !important;
  width: 100%;
  box-sizing: border-box;
}

/* Fallback if you also use the class .blog-post */
.blog-post {
  background: var(--card-bg) !important;
  border-radius: 1.5rem !important;
  padding: 2rem !important;
  box-shadow: var(--shadow-md) !important;
  margin-bottom: 2rem !important;
}

.blog-post h1 {
  margin-top: 0 !important;
  font-size: 2.5rem !important;
  color: var(--text-dark) !important;
  word-wrap: break-word;
}

.blog-post img {
  border-radius: 1rem !important;
  max-width: 100% !important;
  height: auto !important;
  margin: 1.5rem 0 !important;
  box-shadow: var(--shadow-sm) !important;
}

.blog-post pre {
  background-color: var(--light-bg) !important;
  padding: 1.5rem !important;
  border-radius: 1rem !important;
  border: 1px solid var(--border-light) !important;
  margin: 0 !important;
  color: var(--text-dark) !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  font-family: inherit !important;
  font-size: 1rem !important;
  line-height: 1.6 !important;
  width: 100%;
  box-sizing: border-box;
}

/* ----- Forms ----- */
.form-control, .form-select {
  border: 2px solid var(--border-light);
  border-radius: 0.75rem;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  background-color: var(--card-bg);
  color: var(--text-dark);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
  outline: none;
}

label {
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text-dark);
}

/* ----- Author info (simple, no box) ----- */
.container.mt-4:has(img) {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  background: transparent;
  border: none;
  box-shadow: none;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.container.mt-4 img {
  border-radius: 50%;
  width: 48px;
  height: 48px;
  object-fit: cover;
  border: 2px solid var(--primary-color);
  padding: 2px;
  background: var(--card-bg);
}

.container.mt-4 span:last-child {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-left: 0.5rem;
}

/* ----- Comment Section ----- */
.container.mt-3 h3 {
  font-size: 1.6rem;
  margin: 1rem 0 1rem;
  border-bottom: 2px solid var(--border-light);
  padding-bottom: 0.5rem;
  color: var(--text-dark);
}

/* Comment form */
form[action^="/blog/comment/"] {
  display: flex;
  gap: 0.75rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

form[action^="/blog/comment/"] input {
  flex: 1 1 200px;
  min-width: 200px;
}

/* Individual comment cards */
.comment {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
  overflow: visible;
  width: 100%;
}

.comment:hover {
  box-shadow: var(--shadow-md);
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.comment-header img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-color);
  padding: 2px;
  background: var(--card-bg);
}

.comment-author {
  font-weight: 600;
  color: var(--text-dark);
  margin-right: auto;
}

.comment-date {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* FIX: remove inner box from comment body */
pre.comment-body {
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0.75rem 0 0 0 !important;
  margin: 0 !important;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-dark);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  width: 100%;
  box-sizing: border-box;
}

/* ----- Footer ----- */
.footer {
  background-color: var(--dark-bg);
  color: #cbd5e1;
  padding: 2rem 0 1.5rem;
  margin-top: 3rem;
  width: 100%;
}

.footer .container {
  text-align: center;
  padding: 0 1rem;
}

.footer p {
  margin-bottom: 0.25rem;
  color: #cbd5e1;
  word-wrap: break-word;
}

.footer a {
  color: #f1f5f9;
  text-decoration: underline;
}

/* ----- Sign In/Up Forms ----- */
form[action="/user/signin"],
form[action="/user/signup"] {
  max-width: 500px;
  margin: 1.5rem auto;
  padding: 1.5rem;
  background: var(--card-bg);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-lg);
  width: 90%;
}

form[action="/user/signin"] h2,
form[action="/user/signup"] h2 {
  color: var(--text-dark);
  margin-bottom: 1.5rem;
}

/* ----- Blog Add Form ----- */
form[action="/blog/"] {
  max-width: 800px;
  margin: 1rem auto;
  padding: 1.5rem;
  background: var(--card-bg);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-md);
  width: 90%;
}

/* ----- General Container Responsiveness ----- */
.container {
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
  box-sizing: border-box;
}

/* ----- Responsive Typography ----- */
@media (max-width: 576px) {
  h1 { font-size: 2rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.5rem; }
  .card-img-top { height: 160px; }
  .comment-header { flex-direction: column; align-items: flex-start; }
  .comment-author { margin-right: 0; }
  .comment-date { white-space: normal; }
  form[action^="/blog/comment/"] { flex-direction: column; }
  form[action^="/blog/comment/"] button { width: 100%; }
  .blog-post { padding: 1.5rem; }
  body > .container.mt-3:has(h1):has(img):has(pre) {
    padding: 1.5rem !important;
  }
}

/* ----- Utility / Animations ----- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.container, .card, form {
  animation: fadeIn 0.4s ease-out;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--light-bg); }
::-webkit-scrollbar-thumb { background: var(--secondary-color); border-radius: 4px; }