/* =============================
   RESET & BASE
   ============================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  direction: rtl;
  min-height: 100vh;
}

/* =============================
   VIEWS
   ============================= */
.view {
  display: none;
  max-width: 100%;
  margin: 0 auto;
  padding: 20px;
}
.view.active {
  display: block;
}

/* =============================
   HEADER
   ============================= */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid #3759d7;
}
.app-header h1 {
  font-size: 1.6rem;
  color: #3759d7;
}
.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.year-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}
.year-filter label {
  color: #333;
}
.year-filter select {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
  background: #fff;
  font-family: inherit;
}

/* Flagged rows and icons */
.flag-icon {
  cursor: pointer;
  font-size: 1.1rem;
  color: #bbb;
}
.flag-icon.flagged {
  color: #d32f2f;
}
.flag-filter-header-btn.filter-flagged {
  color: #d32f2f;
}
.flag-filter-header-btn.filter-unflagged {
  color: #666;
}
.tabulator-row.flagged-row {
  background-color: rgba(211, 47, 47, 0.08);
}

/* =============================
   BUTTONS
   ============================= */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-blue {
  background: #3759d7;
  color: #fff;
}
.btn-blue:hover:not(:disabled) {
  background: #2a47b0;
}
.btn-green {
  background: #27ae60;
  color: #fff;
}
.btn-green:hover:not(:disabled) {
  background: #1e8c4c;
}
.btn-danger {
  background: #ffffff;
  border: 1px solid #e53935;
  color: #e53935;
}
.btn-danger:hover:not(:disabled) {
  background: #fdecea;
}
.btn-outline {
  background: transparent;
  border: 1px solid #3759d7;
  color: #3759d7;
}
.btn-outline:hover {
  background: #eef1fb;
}
.btn-sm {
  padding: 6px 14px;
  font-size: 0.9rem;
}
.btn-icon {
  display: inline-block;
  margin-left: 4px;
  width: 1.1em;
  text-align: center;
}
[dir="rtl"] .btn-icon {
  margin-left: 0;
  margin-right: 4px;
}
/* Stacked: icon on top, text on next line */
.btn-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.btn-stack .btn-icon {
  margin: 0;
  font-size: 1.1em;
}
.btn-stack .btn-text {
  display: block;
  line-height: 1.2;
  font-size: 0.75em;
  white-space: nowrap;
}
.btn-icon-only {
  padding: 6px 10px;
  min-width: 2.25em;
}
.btn-icon-only .btn-icon {
  margin: 0;
  width: 1em;
}
.btn-full {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  font-size: 1.1rem;
}
.btn-full.btn-stack .btn-text {
  font-size: 0.95em;
}
.btn-link {
  background: none;
  border: none;
  color: #3759d7;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover {
  color: #2a47b0;
}

/* =============================
   FORM LAYOUT
   ============================= */
.form-container {
  display: flex;
  gap: 40px;
  align-items: flex-start;
}
.camera-section {
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.form-section {
  flex: 1;
  max-width: 420px;
}

/* Camera */
.camera-wrapper {
  width: 320px;
  height: 240px;
  background: #1a1a2e;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}
.camera-wrapper video,
.camera-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-controls {
  display: flex;
  gap: 10px;
}
.camera-status {
  font-size: 0.85rem;
  color: #888;
  text-align: center;
}

/* Form fields */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.95rem;
  color: #333;
}
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  direction: rtl;
  transition: border-color 0.2s;
}
.form-group input:focus {
  outline: none;
  border-color: #3759d7;
  box-shadow: 0 0 0 2px rgba(55, 89, 215, 0.15);
}

/* =============================
   MODALS
   ============================= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.visible {
  display: flex;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  min-width: 320px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}
.modal-box h2 {
  margin-bottom: 8px;
  color: #3759d7;
}
.modal-box p {
  margin-bottom: 16px;
  color: #555;
}
.modal-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  margin-bottom: 16px;
}
.modal-box input:focus {
  outline: none;
  border-color: #3759d7;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.error-text {
  color: #e74c3c;
  font-size: 0.9rem;
  margin-top: 10px;
}

/* Image modal */
.modal-image-box {
  max-width: 600px;
}
.modal-image-box img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* Print records column picker */
.print-records-column-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 24px;
  max-height: 280px;
  overflow-y: auto;
  padding: 12px 0;
  text-align: right;
  direction: rtl;
}
.print-records-column-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: #333;
}
.print-records-column-list input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* =============================
   TOAST
   ============================= */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #27ae60;
  color: #fff;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 2000;
}
.toast.visible {
  opacity: 1;
  pointer-events: auto;
}
.toast.error {
  background: #e74c3c;
}

/* =============================
   MANAGER TABLE AREA
   ============================= */
#managerTable {
  direction: rtl;
  width: 100%;
}

/* Make Tabulator RTL-friendly tweaks */
#managerTable .tabulator {
  direction: rtl;
}

/* Remove the blue left-border bar from first column (Tabulator modern theme) */
#managerTable .tabulator-row .tabulator-cell:first-child {
  border-left: none;
}
#managerTable .tabulator-row:nth-child(2n) .tabulator-cell:first-child {
  border-left: none;
}

/* Image expand button in table */
.img-expand-btn {
  background: #3759d7;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.img-expand-btn:hover {
  background: #2a47b0;
}
.img-expand-btn.no-photo {
  background: #ccc;
  cursor: default;
  color: #888;
}

/* =============================
   PHOTO REQUIRE CHECKBOX
   ============================= */
.photo-require-group {
  margin-top: 12px;
  margin-bottom: 4px;
}
.photo-require-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  user-select: none;
}
.photo-require-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* =============================
   DELETE ROW BUTTON
   ============================= */
.btn-delete-row {
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 26px;
  height: 26px;
  font-size: 0.8rem;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.btn-delete-row:hover {
  background: #c0392b;
}

/* =============================
   MULTI-SELECT FILTER
   ============================= */
.mf-container {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
}
.mf-trigger {
  background: transparent;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 8px;
  color: #555;
  font-family: inherit;
  line-height: 1.4;
}
.mf-trigger:hover {
  background: #eef1fb;
  border-color: #3759d7;
}
.mf-active-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3759d7;
  display: inline-block;
}
.mf-dropdown {
  position: absolute;
  z-index: 9999;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 220px;
  max-width: 320px;
  direction: rtl;
  padding: 10px;
}
.mf-search {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 6px;
  direction: rtl;
}
.mf-search:focus {
  outline: none;
  border-color: #3759d7;
}
.mf-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}
.mf-actions a {
  color: #3759d7;
  text-decoration: underline;
  cursor: pointer;
}
.mf-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 4px;
  margin-bottom: 8px;
}
.mf-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 3px;
}
.mf-item:hover {
  background: #f0f2f5;
}
.mf-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.mf-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mf-buttons {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.mf-apply, .mf-cancel, .mf-reset {
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid #ccc;
  background: #fff;
}
.mf-apply {
  background: #3759d7;
  color: #fff;
  border-color: #3759d7;
}
.mf-apply:hover {
  background: #2a47b0;
}
.mf-reset {
  background: #f0f2f5;
  color: #333;
}
.mf-reset:hover {
  background: #ddd;
}
.mf-cancel:hover {
  background: #f0f2f5;
}

/* =============================
   STATUS BAR
   ============================= */
#tableStatusBar {
  display: flex;
  gap: 20px;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #333;
  background: #eef1fb;
  border-radius: 6px;
  margin-bottom: 8px;
}
#statusTotal {
  color: #3759d7;
}
#statusSelected {
  color: #27ae60;
}

/* =============================
   SELECTED ROW HIGHLIGHT
   ============================= */
#managerTable .tabulator-row.tabulator-selected {
  background-color: #d4e3ff !important;
}
#managerTable .tabulator-row.tabulator-selected:hover {
  background-color: #c0d5ff !important;
}

/* =============================
   PRINT OVERLAY
   ============================= */
.print-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #fff;
  overflow-y: auto;
  padding: 0;
}
.print-overlay-toolbar {
  position: sticky;
  top: 0;
  z-index: 3001;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px 20px;
  background: #f0f2f5;
  border-bottom: 2px solid #3759d7;
}
#printOverlayContent {
  padding: 20px;
}

/* When printing, hide everything except the print overlay content */
@media print {
  body > *:not(.print-overlay) {
    display: none !important;
  }
  .print-overlay {
    position: static;
    overflow: visible;
  }
  .print-overlay .no-print {
    display: none !important;
  }
  #printOverlayContent {
    padding: 0;
  }
}

/* =============================
   RESPONSIVE
   ============================= */
@media (max-width: 720px) {
  .form-container {
    flex-direction: column;
    align-items: center;
  }
  .camera-section {
    flex: none;
  }
  .form-section {
    max-width: 100%;
    width: 100%;
  }
}
