:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.25rem;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin: 1.5rem auto;
  max-width: 600px;
}

@media (max-width: 480px) {
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
    max-width: 100%;
    padding: 0 0.5rem;
  }
}

@media (min-width: 850px) {
  .features-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 850px;
  }
}

.feature-card {
  background: white;
  border: 1px solid hsl(var(--border));
  padding: 1rem 0.75rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

@media (max-width: 480px) {
  .feature-card {
    padding: 0.85rem 0.5rem;
    gap: 10px;
    border-radius: 10px;
  }
}

.feature-card:hover {
  border-color: #10b981;
  box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.1), 0 4px 6px -2px rgba(16, 185, 129, 0.05);
  transform: translateY(-2px);
}

.feature-card i {
  color: #10b981;
  background: hsla(162, 71%, 45%, 0.1);
  padding: 10px;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .feature-card i {
    width: 34px;
    height: 34px;
    padding: 8px;
  }
}

.feature-card span {
  font-size: 0.775rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  line-height: 1.3;
  word-break: break-word; /* Prevent clipping */
}

p.subtitle {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.search-container {
  position: relative;
  margin-bottom: 1.5rem;
}

.search-input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.8rem;
  font-size: 0.95rem;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  transition: all 0.2s ease;
  outline: none;
}

.search-input:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsla(var(--ring), 0.1);
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  width: 1.15rem;
  height: 1.15rem;
}

.stats {
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.25rem;
}

.results-grid.results-single {
  grid-template-columns: 1fr;
}

.card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card:hover {
  box-shadow: 0 8px 12px -3px rgba(0, 0, 0, 0.08);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 8px;
}

.student-info h2 {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.1;
  color: hsl(var(--foreground));
  margin-bottom: 2px;
}

.student-id {
  font-size: 0.85rem;
  color: hsl(var(--muted-foreground));
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.675rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success {
  background-color: hsla(var(--success), 0.1);
  color: hsl(var(--success));
  border: 1px solid hsla(var(--success), 0.2);
}

.badge-destructive {
  background-color: hsla(var(--destructive), 0.1);
  color: hsl(var(--destructive));
  border: 1px solid hsla(var(--destructive), 0.2);
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

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

.subject-badge {
  margin: 0.75rem 0;
  padding: 0.6rem 0.75rem;
  background-color: hsl(var(--muted));
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 700;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
}

.footer-info {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid hsl(var(--border));
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1.5rem;
  color: hsl(var(--muted-foreground));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

@media (max-width: 640px) {
  .empty-state {
    padding: 2.5rem 1rem;
  }
}

.empty-state i {
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
}

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid hsl(var(--muted));
  border-top-color: hsl(var(--ring));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .details-grid {
    grid-template-columns: 1fr 1fr; /* Force 2 columns as requested */
    gap: 0.5rem;
  }
}

/* --- NEW COMPONENT STYLES --- */

/* Countdown Timer */
.exam-countdown {
  margin-bottom: 1rem;
  background: #fff1f2;
  color: #e11d48;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: clamp(0.7rem, 2.5vw, 0.75rem);
  font-weight: 700;
  border: 1px solid #fecdd3;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
  transition: all 0.3s ease;
}

/* Subject Header Area */
.subject-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.75rem;
  background-color: hsla(var(--primary), 0.05);
  border-radius: 8px;
}

.subject-name-v2 {
  flex: 1;
  font-weight: 800;
  color: hsl(var(--primary));
  font-size: 1.05rem;
}

.roommate-btn {
  background: hsla(var(--primary), 0.1);
  border: 1px solid hsla(var(--primary), 0.2);
  color: hsl(var(--primary));
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.2s;
}

.roommate-btn:hover {
  background: hsla(var(--primary), 0.2);
}

/* Chart Section */
.roommate-chart-card {}

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

.chart-icon-box {
  background: #dbeafe;
  color: #2563eb;
  padding: 8px;
  border-radius: 8px;
  display: flex;
}

.chart-title-box h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.chart-title-box p {
  margin: 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.chart-body {
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.chart-canvas-area {
  height: 180px;
  flex: 1;
  min-width: 200px;
  position: relative;
}

.chart-legend-area {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-width: 200px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
}

.legend-label-box {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-count {
  color: #6b7280;
  font-weight: 600;
}

/* Roommate List Styling */
.roommate-header-v2 {
  background: hsl(var(--primary));
  color: #fff;
}

.roommate-header-v2 h2 {
  color: #fff;
  font-size: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.roommate-header-v2 .detail-label {
  color: rgba(255, 255, 255, 0.6);
}

.roommate-header-v2 .detail-value {
  color: #fff;
}

.roommate-table .badge-text {
  margin-left: .5rem;
}

.roommate-top-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

@media (max-width: 850px) {
  .roommate-top-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {

  .roommate-table th:first-child,
  .roommate-table td:first-child {
    width: 30px;
    padding: 0.75rem 0.5rem;
    font-size: 0.7rem;
    text-align: center;
  }

  .roommate-table th:nth-child(3),
  .roommate-table td:nth-child(3) {
    display: none;
    /* Hide ID on mobile */
  }

  .roommate-table .badge-text {
    display: none;
    /* Hide text, only icon */
  }

  .roommate-table .badge {
    padding: 4px;
    border-radius: 50%;
  }

  .roommate-table .badge i {
    margin: 0 !important;
  }

  .roommate-table td {
    padding: 0.75rem 0.5rem;
  }
  .you-badge {
    display: none;
  }
}

.roommate-table-container {
  overflow-x: auto;
}

.roommate-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.roommate-table th {
  text-align: left;
  background: hsl(var(--muted));
  padding: 0.75rem 1.5rem;
}

.roommate-table td {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

/* Zalo Section */
.zalo-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.zalo-input-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.zalo-input {
  padding: 0.4rem;
  font-size: 0.75rem;
  border: 1px solid hsl(var(--input));
  border-radius: 4px;
  width: 140px;
}

.zalo-link-btn {
  background-color: #0068ff;
  color: white;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  font-size: 0.75rem;
}

.roommate-zalo-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.legend-label-text {
  font-weight: 500;
  color: #4b5563;
}

.roommate-list-card {
  padding: 0 !important;
}

.list-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
  font-weight: 600;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.row-ineligible {
  background: hsla(var(--destructive), 0.05);
}

.roommate-table td.student-name {
  font-weight: 500;
}

.roommate-table td.student-id {
  font-family: monospace;
}

.roommate-table td.student-class {
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
}

.zalo-submit-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  background: hsl(var(--primary));
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* --- CARD HEADER REDESIGN --- */
.student-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed hsl(var(--border));
  margin-bottom: 1rem;
}

.student-id-pill {
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.student-name-main {
  flex: 1;
  font-size: 1rem !important;
  font-weight: 700;
  color: hsl(var(--foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.course-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.85rem;
  background: hsla(var(--primary), 0.03);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid hsla(var(--primary), 0.05);
}

.course-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 6px;
  color: hsl(var(--primary));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.course-info-main {
  flex: 1;
  min-width: 0;
}

.course-name-text {
  display: block;
  font-weight: 800;
  font-size: 0.95rem;
  color: hsl(var(--primary));
  line-height: 1.2;
}

.roommate-btn-v3 {
  background: white;
  border: 1px solid hsla(var(--primary), 0.15);
  color: hsl(var(--primary));
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.roommate-btn-v3:hover {
  background: hsl(var(--primary));
  color: white;
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  .roommate-btn-v3 span {
    display: none;
    /* Icon only on very small screens */
  }
}

/* Row Highlighting */
.row-current-student {
  background-color: hsla(0, 0%, 0%, 0.05) !important; /* Xám mờ */
}

.row-current-student .student-name {
  font-weight: 800;
  color: #000;
}

.you-badge {
  background: #0068ff; /* Màu xanh Zalo */
  color: white;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  font-weight: 800;
  vertical-align: middle;
}