/* ============================================================
   CSS VARIABLES — Light & Dark themes
   ============================================================ */
:root {
  --sidebar-width: 260px;
  --topbar-height: 56px;

  /* Light theme */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-card: #ffffff;

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: #eff6ff;

  --border: #e2e8f0;
  --border-sidebar: rgba(255,255,255,0.08);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);

  --nav-active-bg: rgba(59,130,246,0.12);
  --nav-hover-bg: rgba(255,255,255,0.06);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-serif: 'DM Serif Display', Georgia, serif;
  --font-mono: 'DM Mono', monospace;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-sidebar: #020617;
  --bg-card: #1e293b;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-soft: rgba(59,130,246,0.15);
  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
  transition: background 0.3s, color 0.3s;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; display: block; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.25rem 1.5rem;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Profile block */
.sidebar-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border-sidebar);
  width: 100%;
  margin-bottom: 1.25rem;
}

.avatar-link { display: block; margin-bottom: 1rem; }

.avatar-img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(59,130,246,0.5);
  box-shadow: 0 0 0 6px rgba(59,130,246,0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.avatar-img:hover {
  transform: scale(1.04);
  box-shadow: 0 0 0 8px rgba(59,130,246,0.2);
}

.avatar-placeholder {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(59,130,246,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--accent);
  border: 3px solid rgba(59,130,246,0.3);
}

.site-name {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: #ffffff;
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-bottom: 0.4rem;
  display: block;
  transition: color 0.2s;
}

.site-name:hover { color: var(--accent); }

.site-tagline {
  font-size: 0.78rem;
  color: var(--text-sidebar);
  opacity: 0.7;
  line-height: 1.5;
  font-weight: 300;
  font-style: italic;
}

/* Nav */
.sidebar-nav { width: 100%; flex: 1; }

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-size: 0.9rem;
  font-weight: 400;
  transition: background 0.2s, color 0.2s;
  position: relative;
}

.nav-item .nav-link:hover {
  background: var(--nav-hover-bg);
  color: #fff;
}

.nav-item.active .nav-link {
  background: var(--nav-active-bg);
  color: #fff;
}

.nav-item.active .nav-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-link i {
  width: 18px;
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.8;
}

.nav-item.active .nav-link i { opacity: 1; }

/* Sidebar bottom */
.sidebar-bottom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-sidebar);
  width: 100%;
  margin-top: auto;
}

.sidebar-bottom a,
.sidebar-bottom button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-sidebar);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
  opacity: 0.7;
}

.sidebar-bottom a:hover,
.sidebar-bottom button:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
  opacity: 1;
}

.icon-border {
  width: 1px;
  height: 20px;
  background: var(--border-sidebar);
  margin: 0 0.25rem;
}

/* ============================================================
   MAIN WRAPPER
   ============================================================ */
#main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s;
}

/* ============================================================
   TOPBAR
   ============================================================ */
#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-height);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 1.25rem;
  gap: 0.75rem;
}

#topbar-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.topbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.2s, color 0.2s;
}

.topbar-btn:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

@media (min-width: 769px) {
  #sidebar-trigger { display: none; }
}

.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#main-content {
  flex: 1;
  padding: 1rem 0;
}

/* ============================================================
   POST CARDS
   ============================================================ */
#post-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 860px;
}

.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.25s, transform 0.25s, border-color 0.25s;
}

.post-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--accent);
}

.post-card-link {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  color: inherit;
  text-decoration: none;
}

.post-card-body {
  flex: 1;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.post-card-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  line-height: 1.35;
  transition: color 0.2s;
}

.post-card:hover .post-card-title { color: var(--accent); }

.post-card-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  align-items: center;
}

.post-card-meta .post-tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  margin-left: 0;
}

/* Media panel — right side, correct aspect ratio */
.post-card-media {
  width: 240px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
}

.post-card-media img {
  width: 100%;
  height: auto;
  aspect-ratio: 1280 / 827;
  object-fit: cover;
  object-position: center;
  display: block;
}

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

.empty-state i { font-size: 2.5rem; margin-bottom: 1rem; display: block; }

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
  max-width: 860px;
}

.page-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.page-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-style: italic;
}

/* ============================================================
   POST ARTICLE
   ============================================================ */
.post-article { max-width: 720px; }

.post-header { margin-bottom: 2.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }

.post-title {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  line-height: 1.2;
}

.post-desc {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-style: italic;
}

.post-meta {
  display: flex;
  gap: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  align-items: center;
}

.post-tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.76rem;
  margin-left: 4px;
}

.post-footer { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }

.btn-back {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.2s;
}
.btn-back:hover { color: var(--accent); }

/* ============================================================
   PROSE CONTENT
   ============================================================ */
.content h1, .content h2, .content h3, .content h4 {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.3;
  margin: 2rem 0 1rem;
}
.content h1 { font-size: 1.8rem; }
.content h2 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.content h3 { font-size: 1.15rem; }

.content p { margin-bottom: 1.25rem; color: var(--text-primary); }

.content ul, .content ol {
  margin: 0 0 1.25rem 1.5rem;
}

.content li { margin-bottom: 0.4rem; }

.content blockquote {
  border-left: 4px solid var(--accent);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--accent);
}

.content pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.content pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.content img { border-radius: var(--radius-sm); margin: 1.5rem auto; }

.content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.content th, .content td {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  text-align: left;
}

.content th {
  background: var(--bg-primary);
  font-weight: 600;
}

.content tr:nth-child(even) { background: var(--bg-primary); }

/* ============================================================
   PROJECTS GRID
   ============================================================ */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.25s, transform 0.25s, border-color 0.25s;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.project-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
  border-color: var(--accent);
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.project-icon {
  width: 44px;
  height: 44px;
  background: var(--accent-soft);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.2rem;
}

.project-links { display: flex; gap: 0.5rem; }

.project-links a {
  color: var(--text-muted);
  font-size: 1rem;
  transition: color 0.2s;
}
.project-links a:hover { color: var(--accent); }

.project-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--text-primary);
}

.project-desc { font-size: 0.86rem; color: var(--text-secondary); line-height: 1.6; }

.project-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.25rem; }

.project-tag {
  font-size: 0.73rem;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ============================================================
   FINANCE PAGE
   ============================================================ */
.finance-section {
  margin-bottom: 2.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--text-primary);
  margin: 0;
}

.section-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* Collapsible cards */
.collapsible-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  cursor: pointer;
  background: var(--bg-card);
  transition: background 0.2s;
  user-select: none;
}

.collapsible-header:hover { background: var(--bg-primary); }

.collapsible-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

.collapsible-arrow {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.3s ease;
}

.collapsible-card.open .collapsible-arrow {
  transform: rotate(180deg);
}

.collapsible-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 0px solid var(--border);
}

.collapsible-card.open .collapsible-body {
  max-height: 2000px;
  border-top-width: 1px;
}

.collapsible-content { padding: 1.25rem 1.5rem; }

/* ============================================================
   FOOTER
   ============================================================ */
#site-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ============================================================
   MOBILE OVERLAY
   ============================================================ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s;
}

#sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  #main-wrapper {
    margin-left: 0;
  }

  .projects-grid {
    grid-template-columns: 1fr;
  }

  .post-card-link {
    flex-direction: column;
  }

  .post-card-media {
    width: 100%;
    height: auto;
    aspect-ratio: 1280 / 827;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }

  .post-title { font-size: 1.6rem; }
}

@media (max-width: 480px) {
  #main-content .container-fluid { padding: 0.75rem 1rem; }
}