    :root {
      --primary: #4f46e5;
      --primary-dark: #4338ca;
      --success: #10b981;
      --bg: #f8fafc;
      --card-bg: #ffffff;
      --text: #111827;
      --muted: #6b7280;
      --radius: .5rem;
      --spacing: 1rem;
      --transition: .3s ease;
    }
    *, *::before, *::after { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: 'Segoe UI', sans-serif;
      background: var(--bg);
      color: var(--text);
      display: flex;
      flex-direction: column;      /* stack header + card vertically */
      align-items: center;
      justify-content: flex-start; /* start at top */
      padding: var(--spacing);
    }

    .card {
      width: 100%;
      max-width: 600px;
      background: var(--card-bg);
      border-radius: var(--radius);
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
      padding: calc(var(--spacing) * 1.5);
      transition: transform var(--transition);
    }
    .card:hover { transform: translateY(-4px); }

    h1 {
      text-align: center;
      margin-bottom: var(--spacing);
      color: var(--primary-dark);
    }

    form {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: var(--spacing);
    }
    .half { grid-column: span 1; }
    .full { grid-column: 1 / -1; }

    label {
      display: flex;
      flex-direction: column;
      font-weight: 600;
      color: var(--muted);
    }
    input, select, textarea, button {
      width: 100%;
      margin-top: .25rem;
      padding: .75rem;
      border: 1px solid #d1d5db;
      border-radius: var(--radius);
      font-size: 1rem;
      transition: border-color var(--transition);
    }
    textarea { height: 4rem; }
    button { height: 2.5rem; }

    input:focus, select:focus, textarea:focus {
      outline: none;
      border-color: var(--primary);
    }

    @media (max-width: 480px) {
      form { grid-template-columns: 1fr; }
      .half, .full { grid-column: 1 / -1; }
    }

    .checkbox-group {
      display: flex;
      gap: 1rem;
      align-items: center;
      grid-column: 1 / -1;
    }
    .checkbox-group input { width: auto; margin-right: .5rem; }

    button.primary {
      background: var(--primary);
      color: #fff;
      border: none;
      cursor: pointer;
      transition: background var(--transition), transform var(--transition);
    }
    button.primary:disabled {
      opacity: .6;
      cursor: not-allowed;
    }
    button.primary:hover:not(:disabled) {
      background: var(--primary-dark);
      transform: translateY(-2px);
    }

    /* Loading spinner */
    #loading {
      display: none;
      text-align: center;
      margin-top: var(--spacing);
    }
    .spinner {
      width: 2rem;
      height: 2rem;
      border: .3rem solid #e5e7eb;
      border-top-color: var(--primary);
      border-radius: 50%;
      animation: spin .8s linear infinite;
      margin: auto;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* Toasts */
    #toast-container {
      position: fixed;
      top: 20px;
      right: 20px;
      display: flex;
      flex-direction: column;
      gap: .5rem;
      z-index: 1000;
    }
    .toast {
      background: #fff;
      border: 1px solid #d1d5db;
      padding: .75rem 1rem;
      border-radius: var(--radius);
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    /* History table */
    #test-history-table {
      width: 100%;
      border-collapse: collapse;
      margin-top: var(--spacing);
    }
    #test-history-table th,
    #test-history-table td {
      border: 1px solid #d1d5db;
      padding: .5rem;
      text-align: left;
    }
    #test-history-table th {
      background: #f8fafc;
      position: relative;
      user-select: none;
    }
    #test-history-table th[data-col]::after {
      content: "▲▼";
      font-size: .6rem;
      position: absolute;
      right: .5rem;
      opacity: .4;
    }
    #test-history-table tbody {
      transition: opacity .3s ease;
    }

    /* Pagination */
    #pagination {
      text-align: center;
      margin-top: var(--spacing);
    }
    #pagination a {
      margin: 0 .25rem;
      text-decoration: none;
      color: var(--primary-dark);
      font-weight: 600;
      cursor: pointer;
    }
    #pagination a.active {
      text-decoration: underline;
    }

    /* Output styling */
    #output {
      margin-top: 20px;
      border: 1px solid #d1d5db;
      padding: 1rem;
      border-radius: 8px;
      background-color: #f8fafc;
    }

    /* Logout & profile */
    #logout-btn {
      display: none;
      position: absolute;
      width: auto;
      top: 100px;
      right: 20px;
      padding: 8px 16px;
      background-color: var(--primary);
      color: white;
      border: none;
      border-radius: var(--radius);
      cursor: pointer;
      font-size: 1rem;
      box-shadow: 0 4px 10px rgba(0,0,0,0.1);
      transition: background-color .3s ease;
    }
    #logout-btn:hover {
      background-color: var(--primary-dark);
    }
    #profile-pic {
      display: none;
      position: absolute;
      top: 150px;
      right: 20px;
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
/* Toolbar above the card, full-width and responsive */
#header-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing);
  margin-bottom: var(--spacing);
}

@media (max-width: 480px) {
  #header-controls {
    flex-direction: column;
    text-align: center;
  }
}
@media (max-width: 600px) {
  body {
    /* Stack header-controls above the card */
    flex-direction: column !important;
    align-items: stretch  !important;
    justify-content: flex-start !important;
  }
  .card {
    /* Let the card span the full width of its container */
    max-width: none !important;
    margin: var(--spacing) 0 !important;
  }


  #profile-dropdown button:hover {
  background-color: #f0f0f0;
}
}

/* Top Navigation Bar */
#topbar {
  position: sticky;
  top: 0;
  width: 100%;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1000;
}

/* Brand/Logo styling */
.topbar-left #brand {
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--primary-dark);
}

/* Right side of navbar */
.topbar-right {
  position: relative;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.topbar-right img#profile-pic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

/* Dropdown menu */
#profile-dropdown {
  display: none;
  position: absolute;
  top: 48px;
  right: 0;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  min-width: 160px;
}

#profile-dropdown button {
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
}
.result-container {
  margin-top: 20px;
  border: 1px solid #d1d5db;
  padding: 1rem;
  border-radius: 8px;
  background-color: #f8fafc;
  position: relative;
}
.result-container .close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: background-color var(--transition);
}
.result-container .close-btn:hover {
  background: var(--primary-dark);
}


#profile-dropdown button:hover {
  background-color: #f2f2f2;
}
.result-container {
  margin-top: 20px;
  border: 1px solid #d1d5db;
  padding: 1rem;
  border-radius: 8px;
  background-color: #f8fafc;
  position: relative;
}
.result-container .close-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  color: #999;
}
.result-container .close-btn:hover {
  color: #333;
}
