/* Global Box Sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  padding: 2rem;
  text-align: center;
  margin: 0;
  line-height: 1.6;
  background-color: #fdfdfd;
  color: #333;
}

/* Responsive Table Wrapper */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border-radius: 8px;
}

table {
  margin: 0 auto;
  border-collapse: collapse;
  width: 100%;
  max-width: 800px;
  /* Prevent tables from getting too wide on large screens */
  background-color: white;
}

th,
td {
  border: 1px solid #ddd;
  padding: 12px 15px;
  text-align: left;
}

th {
  background-color: #f8f9fa;
  font-weight: 600;
}

tfoot tr:first-child td {
  border-top: 3px solid #666;
}

/* Button Styling */
button,
.button,
.class-button {
  display: inline-block;
  padding: 10px 20px;
  margin: 5px;
  border: 1px solid #ccc;
  background-color: #f8f9fa;
  color: #333;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
  /* Ensure sufficient touch target */
  min-height: 44px;
  line-height: normal;
}

button:hover,
.button:hover,
.class-button:hover,
.classList a:hover {
  background-color: #007bff;
  color: white;
  border-color: #0056b3;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:active,
.button:active,
.class-button:active {
  transform: translateY(0);
}

/* Class List Links (from menu.html context) */
.classList a:hover {
  background-color: #007bff;
  color: white;
  border-color: #0056b3;
}

/* === Login Page Styles === */

/* === Login Page Styles === */

#login-sections-container {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 2rem;
  margin-bottom: 3rem;
  /* More bottom space */
  flex-wrap: wrap;
}

#login-sections-container section {
  background-color: white;
  padding: 30px;
  border: 1px solid #e1e4e8;
  border-radius: 12px;
  width: 350px;
  text-align: left;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  /* Deeper shadow */
  transition: transform 0.2s, box-shadow 0.2s;
}

#login-sections-container section:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
  /* Lift effect */
}

#login-sections-container h2 {
  text-align: center;
  margin-top: 0;
  margin-bottom: 1.5rem;
  font-size: 1.5em;
  color: #2c3e50;
  font-weight: 700;
}

#login-sections-container form div {
  margin-bottom: 1.25rem;
}

#login-sections-container label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #495057;
  font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 12px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 16px;
  /* Prevents zoom on iOS */
  transition: border-color 0.2s, box-shadow 0.2s;
  background-color: white;
  /* Ensure background is white for selects */
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: #007bff;
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  cursor: pointer;
  margin: 5px;
}

#login-sections-container section button {
  width: 100%;
  margin-top: 15px;
  margin-left: 0;
  margin-right: 0;
  /* Ensure styles override generic button defaults */
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  padding: 12px;
}

.btn-primary {
  background-color: #007bff;
  color: white;
  transition: background-color 0.2s;
}

.btn-primary:hover {
  background-color: #0056b3;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-primary:active {
  background-color: #004494;
  transform: translateY(0);
}

.btn-google {
  background-color: white;
  color: #333;
  border: 1px solid #ddd !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Roboto, sans-serif;
}

.btn-google::before {
  content: "";
  /* A simplistic Google 'G' icon placeholder or we can use an SVG if available. 
     For now, just a colored G using text or background would be complex. 
     Let's stick to text or SVG if provided. 
     Alternatively, use a multicolored border left? No, keep it simple. */
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 10px;
  background: url('https://upload.wikimedia.org/wikipedia/commons/5/53/Google_%22G%22_Logo.svg') no-repeat center center;
  background-size: contain;
}

.btn-google:hover {
  background-color: #f8f9fa;
  border-color: #ccc !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.text-separator {
  display: flex;
  align-items: center;
  text-align: center;
  color: #6c757d;
  margin: 1rem 0;
  font-size: 0.9em;
}

.text-separator::before,
.text-separator::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #dee2e6;
}

.text-separator::before {
  margin-right: .5em;
}

.text-separator::after {
  margin-left: .5em;
}

#error-message {
  color: #dc3545;
  margin-top: 1rem;
  min-height: 1.5em;
  font-weight: 500;
}

/* === Mobile Optimizations === */
/* Trigger mobile layout sooner (e.g. for tablets in portrait) */
@media (max-width: 900px) {
  body {
    padding: 1rem 0.5rem;
  }

  /* Login Page Mobile */
  #login-sections-container {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1rem;
  }

  #login-sections-container section {
    width: 100%;
    max-width: 100%;
    padding: 20px;
  }

  /* Compact Table Styles */
  .table-wrapper {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    width: calc(100% + 1rem);
    /* Full width bleed to maximize space */
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    overflow-x: auto;
    /* Ensure scrolling is enabled */
  }

  table {
    font-size: 13px;
    /* Smaller font for dense data */
    width: 100%;
    /* Ensure table uses full width */
    table-layout: auto;
    /* Let columns adjust naturally, or use fixed if strictly needed */
    /* table-layout: fixed; Only use if we want to FORCE column widths */
  }

  th,
  td {
    padding: 8px 3px;
    /* Even tighter padding */
    white-space: normal;
    /* Allow text wrapping */
    word-break: break-word;
    /* Break long words */
    max-width: 150px;
    /* Prevent any single cell from getting too wide by default */
  }

  /* Specific override for very long content like codes */
  td:first-child,
  /* Assuming code is often first */
  td.long-text {
    word-break: break-all;
  }

  /* specific adjustments for form elements inside tables */
  td input[type="text"],
  td select {
    padding: 4px;
    font-size: 13px;
    min-height: 30px;
    max-width: 100%;
    /* Ensure inputs don't overflow cells */
    box-sizing: border-box;
  }

  td button {
    padding: 6px 8px;
    font-size: 12px;
    margin: 2px 0;
    width: 100%;
    /* Stack buttons fully */
    display: block;
    /* Force block to stack vertically */
  }


  /* Scale class buttons on mobile properly */
  #dynamicClassList {
    padding: 0 10px;
  }

  #dynamicClassList .day-section>div {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px !important;
  }

  #dynamicClassList .day-section>ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 0;
  }

  #dynamicClassList .day-section>ul li {
    margin: 0;
  }

  #dynamicClassList .class-button,
  #dynamicClassList .classList a {
    flex: 0 1 calc(25% - 8px);
    /* up to 4 per row, scaled down */
    max-width: 90px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
  }

  h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
  }

  h2 {
    font-size: 1.25rem;
    color: #34495e;
  }

  /* Table Actions Column: distinct styling for the last column (Actions) to allow button stacking */
  td:last-child {
    text-align: center;
    width: 1%;
    /* Shrink to fit content */
    white-space: nowrap;
    /* Keep actions somewhat together if possible, or allow wrap if constrained */
    min-width: 70px;
    /* Ensure enough touch width */
  }

  /* Allow actions column to wrap elements if needed */
  td:last-child {
    white-space: normal;
  }
}

/* === Point Control Buttons (Index Page) === */

#studentButtons,
#teacherButtons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  justify-content: center;
  gap: 12px;
  margin-top: 1rem;
  margin-bottom: 2rem;
  padding: 0 5px;
}

.point-control-group {
  display: flex;
  background-color: #f1f3f5;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid #e9ecef;
}

.btn-count {
  flex: 1;
  border: none;
  font-weight: 700;
  font-size: 1rem;
  /* Slightly smaller for mobile */
  padding: 12px 0;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0 !important;
  border-radius: 0 !important;
  min-height: 48px;
}

.btn-add {
  background-color: #e6fcf5;
  color: #0ca678;
  border-right: 1px solid #dee2e6;
}

.btn-add:hover {
  background-color: #20c997;
  color: white;
}

.btn-add:active {
  background-color: #0ca678;
  color: white;
}

.btn-remove {
  background-color: #fff5f5;
  color: #fa5252;
}

.btn-remove:hover {
  background-color: #ff8787;
  color: white;
}

.btn-remove:active {
  background-color: #fa5252;
  color: white;
}

/* Mobile adjustments */
@media (max-width: 400px) {

  #studentButtons,
  #teacherButtons {
    grid-template-columns: repeat(2, 1fr);
    /* Force 2 columns */
    gap: 8px;
  }

  .btn-count {
    padding: 10px 0;
    font-size: 0.95rem;
    min-height: 44px;
  }
}

/* === State Buttons (Mark as Done / Lock) === */
.state-buttons-container {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.btn-state {
  padding: 12px 24px;
  font-weight: 600;
  border-radius: 8px;
  font-size: 1rem;
  min-width: 160px;
  transition: all 0.2s ease;
}

.btn-done {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.btn-done:hover:not(.disabled) {
  background-color: #c3e6cb;
  border-color: #71dd8a;
  color: #155724;
}

.btn-lock {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.btn-lock:hover:not(.disabled) {
  background-color: #f5c6cb;
  border-color: #f1b0b7;
  color: #721c24;
}

/* State Styling for Menu buttons */
.class-button-done {
  background-color: #d4edda !important;
  border-color: #c3e6cb !important;
  color: #155724 !important;
}

.class-button-done:hover {
  background-color: #c3e6cb !important;
}

.class-button-locked {
  background-color: #f8d7da !important;
  border-color: #f5c6cb !important;
  color: #721c24 !important;
}

.class-button-locked:hover {
  background-color: #f5c6cb !important;
}

/* Styling for disabled buttons when done/locked */
.btn-count.disabled,
.btn-state.disabled {
  background-color: #e9ecef;
  color: #adb5bd;
  border-color: #dee2e6;
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

.classList {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
}

.classList li {
  margin-bottom: 10px;
}

.classList a {
  display: inline-block;
  padding: 12px 20px;
  background-color: #f8f9fa;
  border: 1px solid #ccc;
  text-decoration: none;
  color: #333;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  box-sizing: border-box;
  max-width: 300px;
  text-align: center;
  /* Prevent them from being too wide on desktop */
}

.classList a:hover {
  background-color: #007bff;
  color: white;
  border-color: #0056b3;
  transform: translateY(-1px);
}

.classList a:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* --- Style for the Left-Side Container (for User and Language) --- */
#leftSideContainer {
  position: fixed;
  top: 15px;
  left: 15px;
  padding: 15px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  /* Slightly stronger shadow */
  border-radius: 8px;
  background-color: white;
  z-index: 1000;
}

/* --- Style for the Language Toggle --- */
#languageToggle {
  display: flex;
  border: 1px solid #ced4da;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 10px;
  background-color: #fff;
}

#languageToggle span {
  flex-grow: 1;
  text-align: center;
  padding: 8px 12px;
  cursor: pointer;
  background-color: #f8f9fa;
  color: #495057;
  transition: all 0.2s ease;
  user-select: none;
  font-size: 0.9rem;
}

#languageToggle span.active {
  background-color: #007bff;
  color: white;
  font-weight: 600;
}

/* Style for the main content container */
#mainContent {
  max-width: 800px;
  padding: 20px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  box-sizing: border-box;
  width: 100%;
}

/* --- Style for the Header Buttons Container --- */
#headerButtons {
  position: fixed;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 10px;
  z-index: 1000;
  flex-wrap: wrap;
  /* Allow wrapping if needed on medium screens */
  justify-content: flex-end;
}

.header-button {
  padding: 10px 15px;
  cursor: pointer;
  background-color: #f8f9fa;
  border: 1px solid #ccc;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  min-height: 40px;
}

.header-button:hover {
  background-color: #007bff;
}

body {
  padding-top: 100px;
  /* Ensure content is visible below fixed headers */
  padding-left: 0;
  background-color: #fdfdfd;
}

#loggedInUser {
  display: flex;
  align-items: center;
  font-weight: 600;
  color: #333;
  font-size: 0.95rem;
}

#profileCircle {
  width: 32px;
  height: 32px;
  background-color: #adb5bd;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  #leftSideContainer {
    position: static;
    margin: 0 auto 15px auto;
    width: 90%;
    /* Center with some margin */
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Center content inside */
  }

  #loggedInUser {
    margin-bottom: 10px;
    width: 100%;
    justify-content: center;
  }

  #languageToggle {
    width: 100%;
  }

  #headerButtons {
    position: static;
    flex-direction: column;
    /* Stack buttons vertically */
    width: 90%;
    margin: 0 auto 20px auto;
    max-width: 400px;
    gap: 8px;
  }

  .header-button {
    width: 100%;
    /* Full width buttons */
    text-align: center;
    padding: 12px;
  }

  #mainContent {
    position: static;
    transform: none;
    width: 100%;
    padding: 10px;
  }

  body {
    padding-top: 10px;
    padding-bottom: 30px;
  }
}

/* --- Extracted Inline Styles --- */

.mt-3rem {
  margin-top: 3rem;
}

.mt-2rem {
  margin-top: 2rem;
}

.mt-1rem {
  margin-top: 1rem;
}

.mb-1rem {
  margin-bottom: 1rem;
}

.mb-5px {
  margin-bottom: 5px;
}

.narrow-col {
  width: 1%;
  white-space: nowrap;
  text-align: center;
}

.narrow-col input[type="checkbox"] {
  margin: 0 4px;
}

#students-table td:last-child {
  white-space: nowrap;
  width: 1%;
}

#students-table td:last-child button {
  display: inline-block;
  width: auto;
  margin: 2px;
}

@media (max-width: 900px) {
  #students-table td:last-child {
    white-space: normal;
    padding: 0;
  }

  #students-table td:last-child button {
    width: 100%;
    display: block;
    margin: 0;
    box-sizing: border-box;
    border-radius: 0;
    border-left: none;
    border-right: none;
    white-space: nowrap;
  }
}


/* --- Extracted Inline Styles --- */

.mt-3rem {
  margin-top: 3rem;
}

.mt-2rem {
  margin-top: 2rem;
}

.mt-1rem {
  margin-top: 1rem;
}

.mb-1rem {
  margin-bottom: 1rem;
}

.mb-5px {
  margin-bottom: 5px;
}

.btn-danger {
  background-color: #dc3545;
  color: white;
  border-color: #bd2130;
}

.class-teacher-heading {
  margin-top: 0;
  font-weight: normal;
  color: #555;
}

.qr-modal-overlay {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
  z-index: 1000;
}

.qr-modal-content {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  position: relative;
  text-align: center;
  max-width: 100%;

  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.qr-modal-close {
  position: absolute;
  right: 0.5rem;
  top: 0.5rem;
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
  padding: 0.5rem;
}

.qr-modal-note {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  color: #333;
  word-break: break-word;
}

.flex-center {
  display: flex;
  justify-content: center;
}

/* --- User Specific Overrides --- */
#students-table-wrapper {
  overflow-x: visible !important;
}

#students-table {
  width: max-content !important;
  min-width: 100% !important;
}

@media (min-width: 901px) {
  #students-table td:last-child {
    white-space: nowrap !important;
    width: 1% !important;
    /* expands the action column to fit its exact nowrap content on desktop */
  }

  #students-table td:last-child button {
    display: inline-block !important;
    width: auto !important;
    margin: 2px 4px !important;
    padding: 8px 12px !important;
  }
}

#classTable td.narrow-col {
  white-space: nowrap !important;
  width: 1% !important;
}

#classTable div[style*="flex"] {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  justify-content: center !important;
  align-items: center !important;
  gap: 8px !important;
}

#classTable input[type="checkbox"] {
  display: inline-block !important;
  margin: 0 !important;
}

.qr-modal-url {
  margin-top: 1rem;
  font-size: 0.9rem;
  word-break: break-all;
}