/* --- 1. VARIABLES & THEMES --- */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --accent-border: #e2e8f0;
  --success: #059669;
  --danger: #dc2626;
  --stats-bg: #f8fafc;
}

/* --- 2. DARK MODE OVERRIDES --- */
body.dark-mode {
  --bg: #0f172a;
  --card: #1e293b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-border: #334155;
  --stats-bg: #1e293b;
  --stats-border: #334155;
}

/* Adjustments for dark mode elements */
body.dark-mode #qr-input,
body.dark-mode #search-input,
body.dark-mode #filter-spec,
body.dark-mode #filter-date,
body.dark-mode .modal-content,
body.dark-mode .container {
  background: var(--card);
  color: var(--text-main);
  border-color: var(--accent-border);
}

body.dark-mode th {
  background: #334155;
  color: #cbd5e1;
}

body.dark-mode tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

body.dark-mode input::placeholder {
  color: var(--text-muted);
}

/* --- 3. GLOBAL STYLES --- */
body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text-main);
  margin: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 1000px;
  background: var(--card);
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  border: 1px solid var(--accent-border);
}

/* --- 4. LOGIN & AUTH UTILITIES --- */
.hidden {
  display: none !important;
}

.auth-container {
  max-width: 400px;
  margin-top: 100px;
}

.header-centered {
  justify-content: center;
}

.btn-full {
  width: 100%;
  margin-top: 10px;
}

#login-screen input {
  margin-bottom: 15px;
}

/* --- 5. BRANDING, STATS & HEADER --- */
.branding-header {
  text-align: center;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--accent-border);
}

.branding-header h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 2px;
  color: var(--primary);
  text-transform: uppercase;
}

.branding-sub {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-top: 8px;
}

#user-greeting {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}

.stat-card {
  background: var(--stats-bg);
  border: 1px solid var(--accent-border);
  padding: 15px;
  border-radius: 6px;
  text-align: center;
}

.total-card {
  grid-column: 1 / -1;
  border: 1px solid #bfdbfe;
}

.stat-card .label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

header {
  text-align: left;
  margin-bottom: 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Old header H1 is no longer used, branding-header H1 replaced it */

.header-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.status-badge {
  color: var(--success);
  font-size: 0.75rem;
  background: var(--card);
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--accent-border); /* Added subtle border to match branding bar */
}

/* --- 6. INPUTS & BUTTONS --- */
#qr-input,
#search-input {
  width: 100%;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
  border-radius: 6px;
  outline: none;
  font-size: 0.95rem;
  margin-bottom: 10px;
  box-sizing: border-box;
}

.filter-group {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  width: 100%;
}

#filter-spec,
#filter-date {
  flex: 1; /* Forces 50% width each */
  min-width: 0; /* Prevents flex items from overflowing */
  padding: 10px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
  border-radius: 6px;
  height: 42px; /* Fixed height for perfect alignment */
  box-sizing: border-box;
  font-family: inherit;
}

#qr-input:focus,
#search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

button {
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  border: none;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-theme {
  background: transparent;
  border: 1px solid var(--accent-border);
  color: var(--text-main);
  padding: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-theme:hover {
  background: var(--bg);
  border-color: var(--primary);
}

.btn-logout {
  padding: 5px 10px;
  font-size: 0.7rem;
}

.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.btn-manual {
  background: var(--card);
  color: var(--text-main);
  border: 1px solid #cbd5e1;
  flex: 1;
}
.btn-clear {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  flex: 1;
}
.btn-print {
  background: #475569;
  color: white;
  flex: 1;
}
.btn-download {
  background: var(--success);
  color: white;
  flex: 1;
}

/* Ensure header actions stay aligned */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* --- ADMIN RECYCLE BIN BUTTON --- */
.btn-deleted-toggle {
  background-color: transparent;
  color: #ef4444; /* Red color to indicate danger/deleted items */
  border: 1px solid #fca5a5;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-deleted-toggle:hover {
  background-color: #fef2f2;
  border-color: #ef4444;
}

/* Dark mode adjustment for the deleted button */
body.dark-mode .btn-deleted-toggle {
  color: #f87171;
  border-color: #991b1b;
}

body.dark-mode .btn-deleted-toggle:hover {
  background-color: #450a0a;
}

/* The "Late" or "Present" text - Now perfectly centered */
.status-text {
  font-weight: 600;
  /* Removed flex-grow to prevent it from pushing against the absolute icon */
}

/* Base style for both action buttons */
.btn-restore, .btn-delete {
  background: transparent !important;
  border: none !important;
  cursor: pointer;
  font-size: 1.1rem;
  box-shadow: none !important;
  padding: 5px !important;
  margin: 0 !important;
  transition: transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-restore:hover, .btn-delete:hover {
  transform: scale(1.2);
  background: transparent !important;
}

/* Specific font size tweak for restore icon if needed */
.btn-restore {
  font-size: 1.2rem;
}

/* --- 7. TABLE & MODAL --- */
.table-container {
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: center; /* CENTER all headers */
  padding: 14px;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  border-bottom: 2px solid var(--accent-border);
}

td {
  padding: 14px;
  border-bottom: 1px solid var(--accent-border);
  font-size: 0.9rem;
  text-align: center; /* CENTER all cell content */
  vertical-align: middle; /* Vertically center content */
}

/* Special handling for the Status column to allow icon positioning */
td:last-child {
  position: relative; /* Make this the positioning context for absolute children */
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  z-index: 100;
}

/* Styling for Input Labels and Groups */
.input-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* Aligns title to the left */
  margin-bottom: 15px;
  width: 100%;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text-main);
  box-sizing: border-box;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-content {
  background: white;
  padding: 25px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.actions-cell {
  width: 50px;
  text-align: center;
}

/* Modal button styles */
.modal-btns {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.btn-save {
  background: var(--success);
  color: white;
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-save:hover {
  background: #047857;
}

.btn-cancel {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  flex: 1;
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-cancel:hover {
  background: #fef2f2;
}



/* --- 9. STUDENT PROFILE MODAL SPECIFICS --- */
#profileModal .modal-content {
  padding: 40px;
  max-width: 420px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--accent-border);
  text-align: center;
}

#p-img {
  width: 140px;
  height: 140px;
  border: 4px solid var(--primary);
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 20px;
  display: block;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  text-indent: -9999px; /* Hides "Student Photo" text if image is missing */
}

#p-name {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 25px;
  color: var(--primary);
  letter-spacing: 1px;
}

#profileModal p {
  width: 100%;
  display: flex;
  justify-content: space-between; /* This pushes label to left and data to right */
  align-items: center;
  border-bottom: 1px solid var(--accent-border);
  padding: 10px 0;
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-main);
}

#profileModal strong {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#profileModal span {
  font-weight: 600;
}

/* Row Hover Effect for Clickable Students */
#table-body tr {
  transition: background 0.2s ease;
  cursor: pointer;
}

#table-body tr:hover {
  background: rgba(37, 99, 235, 0.08) !important;
}

body.dark-mode #table-body tr:hover {
  background: rgba(255, 255, 255, 0.05) !important;
}

/* Loading state for profile image */
#p-img[src=""] {
  visibility: hidden;
}


/* --- 8. RESPONSIVE & PRINT --- */
#cam-btn,
.btn-cam,
#reader {
  display: none !important;
}

@media (max-width: 1024px) {
  #cam-btn,
  .btn-cam {
    display: block !important;
    background: var(--primary);
    color: white;
    width: 100%;
    margin-bottom: 10px;
  }
  #reader {
    width: 100%;
    border-radius: 8px;
    border: 2px solid var(--accent-border);
    background: #000;
    margin-bottom: 15px;
  }
}

/* --- PRINT MODE --- */
@media print {
  /* Hide everything except the table */
  .branding-header,
  header,
  .stats,
  .actions,
  #reader,
  #cam-btn,
  .btn-cam,
  .input-section,
  .search-section,
  .modal,
  .btn-clear,
  .btn-delete,
  .btn-restore,
  .actions-cell {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    padding: 0;
  }

  .container {
    box-shadow: none;
    width: 100%;
    max-width: 100%;
    padding: 20px;
    border: none;
  }

  table {
    width: 100%;
    border: 1px solid #000;
  }

  th,
  td {
    border: 1px solid #ddd;
    color: black !important;
    text-align: left;
    padding: 10px;
  }

  /* Hide the empty actions column header */
  th:last-child,
  td:last-child {
    display: none !important;
  }
}

/* --- MOBILE OPTIMIZATION (Original Logic Restored) --- */
@media (max-width: 600px) {
  * {
    box-sizing: border-box !important;
  }

  body {
    padding: 5px;
    overflow-x: hidden;
  }

  .container {
    padding: 10px;
    border-radius: 10px;
    width: 100%;
    max-width: 100%;
  }

  .filter-group {
    flex-direction: row !important;
  }

  thead {
    display: none;
  }

  .table-container {
    overflow-x: hidden;
    border: none;
  }

  table {
    display: block;
    width: 100% !important;
    min-width: 100% !important;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    background: rgba(0, 0, 0, 0.02);
    margin-bottom: 12px;
    border-radius: 12px;
    border: 1px solid var(--accent-border);
    padding: 8px;
  }

  td {
    border: none;
    padding: 8px 5px;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
  }

  td::before {
    content: attr(data-label);
    font-weight: bold;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    flex-shrink: 0;
  }

  /* Student Row Highlight */
  td:nth-child(2) {
    background: rgba(37, 100, 235, 0.1);
    border-radius: 8px;
    margin: 5px 0;
    padding: 10px;
  }

  td:nth-child(2)::before {
    content: "STUDENT";
  }

  .mobile-align-right {
    text-align: right;
    flex-grow: 1;
    word-break: break-all;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .btn-cam {
    grid-column: span 2;
  }

  .status-wrapper {
    width: auto;
    justify-content: flex-end;
  }
}
