/* ===== Page Specific Logic ===== */

/* Admin Page Styles */
.bg-admin {
  background: #f44336 !important;
}
.bg-load {
  background: #2196f3 !important;
}
.bg-dou {
  background: #4caf50 !important;
}
.bg-list {
  background: #ff9800 !important;
}
.bg-rasp {
  background: #9c27b0 !important;
}

.perm-item {
  transition: all 0.3s ease;
  padding: 12px !important;
  border-radius: 12px !important;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.perm-item:has(input:checked).admin-item {
  background: rgba(244, 67, 54, 0.2) !important;
  border-color: rgba(244, 67, 54, 0.5) !important;
}
.perm-item:has(input:checked).load-item {
  background: rgba(33, 150, 243, 0.2) !important;
  border-color: rgba(33, 150, 243, 0.5) !important;
}
.perm-item:has(input:checked).dou-item {
  background: rgba(76, 175, 80, 0.2) !important;
  border-color: rgba(76, 175, 80, 0.5) !important;
}
.perm-item:has(input:checked).list-item {
  background: rgba(255, 152, 0, 0.2) !important;
  border-color: rgba(255, 152, 0, 0.5) !important;
}
.perm-item:has(input:checked).rasp-item {
  background: rgba(156, 39, 176, 0.2) !important;
  border-color: rgba(156, 39, 176, 0.5) !important;
}

.perm-item input[type='checkbox'] {
  display: none !important;
}

.perm-info {
  display: flex;
  flex-direction: column;
}
.perm-title {
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
}
.perm-desc {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
}

.collapsible-header {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.collapsible-header::after {
  content: '▼';
  font-size: 10px;
  transition: transform 0.3s;
  opacity: 0.5;
  margin-left: auto;
}
.collapsible-section.active .collapsible-header::after {
  transform: rotate(180deg);
}
.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s ease-out;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
.collapsible-section.active .collapsible-content {
  max-height: 500px;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}

.user-info-mini {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.user-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.user-info-label {
  color: rgba(255, 255, 255, 0.6);
}
.user-info-value {
  color: #fff;
  font-weight: 500;
}
.user-id-value {
  font-family: monospace;
  color: #ffeb3b;
}

.summary-table-container {
  margin-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 15px;
  color: #fff;
}

#accessSummaryTable {
  width: 100%;
  border-collapse: collapse;
  color: #fff;
}
#accessSummaryTable th {
  text-align: left;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
#accessSummaryTable td {
  padding: 10px 8px;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #fff;
}

.admin-table-cell {
  padding: 12px !important;
}
.admin-table-id {
  font-family: monospace !important;
}

/* Admin Edit Button */
.btn-edit {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-edit:hover {
  background: #fff;
  color: #000;
}

/* Auth Logic Utility */
.admin-password-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-export-block {
  margin-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 15px;
}
.admin-user-details {
  margin-top: 15px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.admin-permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

/* ===== Spreadsheet & Excel Preview (Complex) ===== */
.spreadsheet-wrapper {
  position: fixed;
  top: 80px;
  left: 20px;
  right: 20px;
  bottom: 70px;
  background: rgba(20, 20, 30, 0.4) !important;
  backdrop-filter: blur(40px) !important;
  -webkit-backdrop-filter: blur(40px) !important;
  border-radius: 24px !important;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.spreadsheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.1) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.spreadsheet-header h2 {
  margin: 0;
  font-size: 20px;
  color: #fff !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
  font-weight: 700;
}

.spreadsheet-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.spreadsheet-header-actions button {
  width: auto !important;
  margin: 0 !important;
}

#spreadsheet-container .jss_content {
  padding: 0 !important;
  margin: 0 !important;
}

.download-preview-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
  height: 44px !important;
}
.download-preview-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.spreadsheet-header-actions .close-btn {
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
}

.close-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 24px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-btn:hover {
  background: rgba(255, 60, 60, 0.25);
  border-color: rgba(255, 60, 60, 0.4);
}

#spreadsheet-container {
  flex: 1;
  overflow: auto;
  padding: 0 !important;
  background: #e8e8e8;
}

/* Excel Preview Formatting */
.sheet-section {
  margin-bottom: 40px;
  padding: 20px;
  background: #f0f0f0;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.sheet-title {
  margin: 0 0 20px 0;
  padding: 12px 20px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  border-radius: 8px;
}
.table-section-title {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 10px 20px;
  margin: 0 0 2px 0;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px 8px 0 0;
}
.excel-preview {
  background: #fff;
  padding: 40px 50px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
  border-radius: 0 0 8px 8px;
  overflow-x: auto;
  color: #000;
}
.excel-header {
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.excel-org {
  font-weight: bold;
  font-size: 11px;
}
.excel-service-code {
  border: 2px solid #000;
  width: 120px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}
.excel-title {
  grid-column: 1 / span 2;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  margin: 15px 0;
}
.excel-teacher {
  text-align: center;
  border-bottom: 1px solid #000;
  font-size: 16px;
  color: #000 !important;
}
.excel-teacher-hint {
  text-align: center;
  font-size: 8px;
  margin-bottom: 15px;
}
.excel-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 100%;
  border: 2px solid #000;
}
.excel-table th,
.excel-table td {
  border: 1px solid #666;
  padding: 4px 2px;
  text-align: center;
  vertical-align: middle;
}
.excel-table thead th {
  background: #ececec;
  font-weight: 600;
}
.excel-table .cell-group,
.excel-table .cell-subject {
  text-align: left;
  background: #ecf1e0 !important;
  padding-left: 5px;
}
.excel-table .cell-total {
  font-weight: bold;
  background: #f0f0f0 !important;
}
.excel-table .totals-row td {
  border-top: 2px solid #000;
  color: #ff0000;
  font-weight: bold;
}
.excel-table .totals-label {
  text-align: left;
  padding-left: 5px;
  background: #fff !important;
}
.excel-table .totals-value {
  color: #ff0000;
  background: #fff !important;
}
.excel-table .totals-value.over-limit {
  background: #ffff00 !important;
}
.excel-signatures {
  margin-top: 30px;
  font-size: 12px;
  text-align: left;
}
.excel-signatures div {
  margin-bottom: 15px;
}

/* Spreadsheet Editable Cells */
[contenteditable='true'] {
  cursor: text;
}
[contenteditable='true']:hover {
  background: #f5f5dc !important;
}
[contenteditable='true']:focus {
  outline: 2px solid #667eea;
  background: #fff9c4 !important;
}

/* Tabs for Preview */
.preview-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.05);
  overflow-x: auto;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}
.preview-tab {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.preview-tab.active {
  background: #667eea;
  color: #fff;
  border-color: #667eea;
  box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

/* JSpreadsheet Enhancements */
#status {
  color: #fff !important;
  text-align: center !important;
  margin-bottom: 20px !important;
}
#status.loading {
  font-style: italic;
  animation: blink 1.5s infinite;
}
.spreadsheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

/* Reconciliation Section */
.reconciliation-section {
  margin-top: 40px;
  width: 100%;
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  padding-top: 20px;
}
.reconciliation-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
  align-items: center;
}

/* Auth Overlay Restoration */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.12) !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  border-radius: 18px !important;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35) !important;
  padding: 22px !important;
  color: #fff !important;
}
.auth-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
  color: #fff !important;
}
.auth-subtitle {
  font-size: 14px;
  opacity: 0.9;
  text-align: center;
  margin-bottom: 16px;
  color: rgba(255, 255, 255, 0.8) !important;
}
.auth-label {
  display: block;
  margin-bottom: 10px;
  font-weight: 600;
  color: #fff;
}
.auth-input {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  font-size: 16px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.auth-input:first-of-type {
  margin-bottom: 16px;
}
.auth-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 60, 60, 0.18);
  border: 1px solid rgba(255, 60, 60, 0.35);
  font-size: 14px;
}
.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  width: 100%;
}
.auth-actions button {
  width: 100% !important;
  margin: 0 !important;
  height: 44px !important;
}
.auth-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.2) !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  padding: 12px 14px !important;
  border-radius: 10px !important;
  cursor: pointer !important;
}
