:root {
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 222.2 84% 4.9%;
  --radius: 0.375rem;
}

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

ul, ol {
  list-style: none !important;
  margin: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-size: 0.9rem;
}

.content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
}

/* Typography Compact */
h1 { font-size: 1.5rem; letter-spacing: -0.01em; margin-bottom: 0.5rem; }
h3 { font-size: 1rem; font-weight: 600; }
h4 { font-size: 0.9rem; font-weight: 600; }

/* Compact Header */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: hsla(var(--background), 0.95);
  backdrop-filter: blur(4px);
  border-bottom: 1px solid hsl(var(--border));
  padding: 0.4rem 0;
}

header .content {
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* Compact Inputs & Buttons */
.input-group {
  position: relative;
  width: 100%;
  max-width: 300px;
}

input {
  width: 100%;
  height: 2rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  padding: 0 0.5rem;
  font-size: 0.8rem;
  transition: all 0.2s;
}

input:focus {
  outline: none;
  border-color: hsl(var(--ring));
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  padding: 0 0.75rem;
  font-weight: 500;
  font-size: 0.8rem;
  border-radius: var(--radius);
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border: none;
  cursor: pointer;
}

button#clear {
  position: absolute;
  right: 0.2rem;
  top: 50%;
  transform: translateY(-50%);
  height: 1.6rem;
  padding: 0 0.4rem;
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

/* Compact Grid & Cards */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.subject-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  transition: all 0.2s;
}

.subject-card a {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.subject-card:hover {
  border-color: hsl(var(--primary));
  background-color: hsl(var(--accent));
}

.subject-card-icon {
  width: 1.5rem;
  height: 1.5rem;
  background-color: hsl(var(--secondary));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
  color: hsl(var(--primary));
}

.subject-card-icon svg { width: 0.8rem; height: 0.8rem; }

.subject-name {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
  line-height: 1.2;
}

.subject-meta {
  margin-bottom: 0.5rem;
}

.badge {
  padding: 0.05rem 0.4rem;
  background-color: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 500;
}

.subject-card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
  margin-top: auto;
}

/* Ultra-Compact Question Styles (da.php) */
.qa {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ques-compact {
  padding: 0.5rem 0.75rem;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  transition: background-color 0.2s;
}

.ques-compact:hover {
  background-color: hsl(var(--accent));
}

.q-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.q-num {
  font-weight: 700;
  color: hsl(var(--primary));
  font-size: 0.8rem;
  min-width: 1.5rem;
}

.q-text {
  font-weight: 600;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
}

.a-row {
  display: flex;
  gap: 0.5rem;
  padding-left: 2rem;
  font-size: 0.85rem;
  color: #059669; /* Emeral 600 */
}

.a-indicator {
  font-weight: 700;
  color: #10b981;
}

.a-text {
  font-weight: 500;
}

/* Utils & Navigation */
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.d-none { display: none !important; }

#search-controls {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: 100;
}

#search-controls button {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

#search-controls img { width: 1.25rem; filter: invert(1); }

.highlight-clip-text { background-color: #fbbf24; color: #000; border-radius: 2px; }

/* Print & Wrapper */
.print-wrapper {
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.print {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  background-color: hsl(var(--secondary));
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
}

.print svg { width: 1rem; height: 1rem; }

@media print {
  @page {
    margin: 1.5cm;
  }
  
  body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
    padding: 1rem !important;
  }

  /* Force all borders and text to black for BW printing */
  * {
    color: black !important;
    border-color: black !important;
    border-radius: 0 !important;
  }

  .no-print, header, footer, #search-controls, .badge { 
    display: none !important; 
  }

  .content { 
    max-width: 100%; 
    padding: 0;
    margin: 0;
  }

  /* Question Print Style */
  .ques-compact { 
    border: none !important; 
    border-bottom: 1px solid black !important; 
    padding: 12px 0 !important;
    margin: 0 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    background: transparent !important;
  }

  .q-text { font-size: 11pt !important; font-weight: 500; }
  .a-row { 
    padding-left: 1.5rem; 
    font-weight: bold;
    margin-top: 6px;
  }
  .a-indicator { font-size: 12pt; }

  #study-hub > div { 
    background: white !important; 
    border: 2px solid black !important; 
    padding: 1.5rem !important;
  }
  
  .print-hub-content { display: block !important; }
  
  .subject-grid { 
    display: block !important;
  }
  .subject-grid > div {
    margin-bottom: 1.5rem !important;
    background: white !important;
    border: 1px solid black !important;
    padding: 1rem !important;
    break-inside: avoid;
  }

  .mermaid { 
    border: none !important; 
    padding: 0 !important; 
    margin: 1cm auto !important;
    display: flex !important;
    justify-content: center;
    max-width: 100%;
  }
  .mermaid svg {
    max-width: 18cm !important;
    height: auto !important;
    filter: grayscale(1); /* Ensure mermaid is black & white */
  }

  h1 { font-size: 18pt !important; margin-bottom: 0.5cm !important; border-bottom: 3px solid black; padding-bottom: 5px; }
  h4 { font-size: 12pt !important; margin: 0.5cm 0 0.2cm 0 !important; border-bottom: 1px solid black; }
  
  #print-header { display: block !important; text-align: right; font-size: 9pt; color: black; margin-bottom: 1rem; border: none !important; }
}

@media (max-width: 640px) {
  header .content {
    flex-direction: row; /* Gọn trên mobile vẫn nằm ngang */
    gap: 0.5rem;
  }
  .input-group { max-width: 160px; }
  h1 { font-size: 1.25rem; }
  .subject-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}