/* =========================================================================
   CSS variables and Base Styles
   ========================================================================= */
:root {
  /* Colors */
  --bg-app: #0f1115;
  --bg-sidebar: #15181e;
  --bg-panel: #1a1d24;
  --bg-panel-hover: #21252d;
  --bg-card: #222630;

  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --text-accent: #38bdf8;

  --border-light: #2c323f;

  /* Status Colors */
  --status-solved: #10b981;
  --status-solved-bg: rgba(16, 185, 129, 0.1);
  --status-revision: #f59e0b;
  --status-revision-bg: rgba(245, 158, 11, 0.1);
  --status-unsolved: #475569;

  /* Scrollbar */
  --scrollbar-bg: transparent;
  --scrollbar-thumb: #334155;
  --scrollbar-thumb-hover: #475569;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  /* App container handles scrolling */
}

ul {
  list-style: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
  outline: none;
}

.hidden {
  display: none !important;
}

/* =========================================================================
   Layout
   ========================================================================= */
.app-container {
  display: grid;
  grid-template-columns: var(--sidebar-width, 20%) 1fr;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

.scroll-area {
  overflow-y: auto;
  height: calc(100vh - 80px);
  /* Account for header heights */
  padding: 24px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* =========================================================================
   Sidebar
   ========================================================================= */
.sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
}

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

.progress-text {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.progress-bar-container {
  height: 4px;
  background-color: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--status-solved);
  width: 0%;
  transition: width 0.3s ease;
}

.pattern-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  min-height: 0;
  /* critical: allows flex child to shrink and scroll */
}

.pattern-item {
  padding: 10px 14px;
  margin-bottom: 4px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.15s ease;
}

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

.pattern-item.active {
  background-color: rgba(56, 189, 248, 0.1);
  color: var(--text-accent);
}

.pattern-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}

.pattern-item-progress {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 12px;
  flex-shrink: 0;
}

/* =========================================================================
   Main Panel
   ========================================================================= */
.main-panel {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-app);
  border-right: 1px solid var(--border-light);
}

.main-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-light);
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

#problemFilter {
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.pattern-description {
  margin-bottom: 40px;
}

/* Problem List */
.problem-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.problem-card {
  background-color: var(--bg-card);
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.problem-card:hover {
  background-color: var(--bg-panel-hover);
  border-color: var(--border-light);
}

.problem-card.active {
  border-color: var(--text-accent);
}

/* Status variants */
.problem-card.status-solved {
  border-left: 3px solid var(--status-solved);
}

.problem-card.status-revision {
  border-left: 3px solid var(--status-revision);
}

.problem-card.status-unsolved {
  border-left: 3px solid var(--status-unsolved);
}

.problem-checkbox {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  margin-right: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.problem-checkbox:checked {
  background-color: var(--status-solved);
  border-color: var(--status-solved);
}

.problem-checkbox:checked::after {
  content: "✓";
  color: #fff;
  font-size: 14px;
  font-weight: bold;
}

.problem-title {
  flex: 1;
  font-weight: 500;
  font-size: 1rem;
}

.problem-card.status-solved .problem-title {
  color: var(--text-muted);
  text-decoration: line-through;
}

.meta-badges {
  display: flex;
  gap: 8px;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-revision {
  background-color: var(--status-revision-bg);
  color: var(--status-revision);
}

/* =========================================================================
   Details Panel (Right) - Slide Over
   ========================================================================= */
.details-panel {
  position: fixed;
  top: 0;
  right: 0;
  transform: translateX(100%);
  /* Hidden by default via transform */
  width: 50vw;
  /* Default width */
  min-width: 50vw;
  max-width: calc(100vw - var(--sidebar-width, 20%));
  height: 100vh;
  background-color: var(--bg-panel);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
  border-left: 1px solid var(--border-light);
}

.details-panel.open {
  transform: translateX(0);
}

/* Disable transition during resize */
.details-panel.resizing {
  transition: none;
}

.resizer {
  position: absolute;
  left: -3px;
  /* Hang slightly off the edge */
  top: 0;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  background-color: transparent;
  z-index: 101;
}

.resizer:hover,
.details-panel.resizing .resizer {
  background-color: var(--text-accent);
}

.left-resizer {
  left: auto;
  right: -3px;
}

body.resizing-left .left-resizer {
  background-color: var(--text-accent);
}

.details-placeholder {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}

.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.details-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  /* Ensures proper child scrolling */
}

.details-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-light);
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  margin-left: auto;
}

.close-btn:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.1);
}

.details-actions {
  display: flex;
  gap: 12px;
}

.status-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  transition: all 0.2s;
}

.status-toggle input {
  display: none;
}

.status-toggle.revision:has(input:checked) {
  background-color: var(--status-revision-bg);
  border-color: var(--status-revision);
  color: var(--status-revision);
}

.status-toggle.solved:has(input:checked) {
  background-color: var(--status-solved-bg);
  border-color: var(--status-solved);
  color: var(--status-solved);
}


.details-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  min-height: 0;
  /* Ensures proper scrolling inside flex containers */
}

.problem-body {
  margin-bottom: 30px;
}

.notes-section {
  border-top: 1px solid var(--border-light);
  padding-top: 24px;
  display: flex;
  flex-direction: column;
}

.notes-section h3 {
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: var(--text-main);
}

.notes-section textarea {
  width: 100%;
  height: 100px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  color: var(--text-main);
  resize: vertical;
  transition: border-color 0.2s;
}

.notes-section textarea:focus {
  border-color: var(--text-accent);
}

/* =========================================================================
   Markdown Typography (GitHub Dark inspired but simplified)
   ========================================================================= */
.markdown-body {
  color: var(--text-main);
  line-height: 1.6;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 5px;
  margin-bottom: 10px;
  font-weight: 600;
  line-height: 1.25;
}


.markdown-body h1 {
  font-size: 1.75em;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.3em;
}

.markdown-body h2 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.3em;
  /* margin-top: 32px; */
}

.markdown-body h3 {
  font-size: 1.25em;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre {
  margin-top: 0;
  margin-bottom: 16px;
}

.markdown-body a {
  color: var(--text-accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body pre {
  background-color: #161b22;
  border-radius: 6px;
  padding: 16px;
  overflow: auto;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
  background-color: rgba(240, 246, 252, 0.15);
  padding: 0.2em 0.4em;
  border-radius: 6px;
}

.markdown-body pre code {
  background-color: transparent;
  padding: 0;
}

.markdown-body blockquote {
  padding: 0 1em;
  color: var(--text-muted);
  border-left: 0.25em solid var(--border-light);
}

.markdown-body ul {
  padding-left: 2em;
  list-style-type: disc;
}

/* Fade in animation */
.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 250px 1fr;
  }

  .details-panel {
    width: 100% !important;
    min-width: 100%;
  }

  .resizer {
    display: none;
  }
}