/* ==========================================================
   Audit Tool — v2 Styling (with upload + claim system)
   ========================================================== */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Sarabun", "Noto Sans Thai", sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  line-height: 1.5;
}

.screen { display: none; }
.screen.active { display: block; }

.hidden { display: none !important; }

/* ========== Login Screen ========== */
#login-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: white;
  padding: 48px;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  text-align: center;
  min-width: 400px;
}

.login-box h1 { margin: 0 0 8px; font-size: 28px; color: #112240; }
.login-box .subtitle { color: #666; margin: 0 0 32px; }

.staff-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.staff-btn {
  padding: 16px;
  background: #f5f5f7;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.staff-btn:hover {
  background: #112240;
  color: white;
  border-color: #112240;
}

/* ========== Loading Screen ========== */
#loading-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.loading-box { text-align: center; }

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e0e0e0;
  border-top-color: #112240;
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Top Bar ========== */
#audit-screen.active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #112240;
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; }
.topbar-center { flex: 1; }
.topbar-right { flex: 0 0 auto; display: flex; gap: 8px; }

.staff-badge {
  background: #D4A943;
  color: #112240;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

.progress-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  margin-bottom: 4px;
}

.progress-pct {
  background: rgba(212, 169, 67, 0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
  margin-left: auto;
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: #D4A943;
  width: 0%;
  transition: width 0.3s;
}

/* ========== Buttons ========== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn:hover:not(:disabled) { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: #D4A943; color: #112240; }
.btn-ghost { background: rgba(255,255,255,0.1); color: white; }
.btn-warning { background: #f0ad4e; color: white; }
.btn-flag { background: #dc3545; color: white; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

.btn-primary:hover:not(:disabled) { background: #c4992f; }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.2); }

.btn-upload {
  background: #28a745;
  color: white;
  width: 100%;
  padding: 12px;
  font-size: 14px;
}
.btn-upload:hover:not(:disabled) { background: #218838; }

/* ========== Filter Bar ========== */
.filterbar {
  background: white;
  padding: 12px 20px;
  display: flex;
  gap: 20px;
  border-bottom: 1px solid #e0e0e0;
  flex-wrap: wrap;
}

.filterbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.filterbar label input { cursor: pointer; }

/* ========== Claim Banner ========== */
.claim-banner {
  background: #fff3cd;
  border-bottom: 1px solid #ffc107;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.claim-banner span {
  color: #856404;
  font-size: 14px;
}

.claim-banner .btn-ghost {
  background: #ffc107;
  color: #856404;
}

.claim-banner .btn-ghost:hover {
  background: #e0a800;
}

/* ========== Audit Main ========== */
.audit-main {
  flex: 1;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.audit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* ========== Left Panel ========== */
.audit-left {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.audit-left h3 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.5px;
}

.image-container {
  width: 100%;
  aspect-ratio: 1;
  background: #f5f5f7;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-fallback { color: #999; font-size: 14px; }

.image-thumbs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.image-thumbs img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  background: #f5f5f7;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
}

.image-thumbs img.active { border-color: #D4A943; }

/* ========== Uploaded Images Section ========== */
.uploaded-section {
  margin: 24px 0;
  padding: 16px;
  background: #f9f9fb;
  border-radius: 8px;
  border: 2px dashed #d0d0d8;
}

.uploaded-section h3 {
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.upload-count {
  font-size: 13px;
  color: #28a745;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.uploaded-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.uploaded-item {
  aspect-ratio: 1;
  background: white;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.uploaded-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.15s;
}

.uploaded-thumb:hover { transform: scale(1.05); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: #999;
  font-size: 13px;
  margin: 16px 0;
}

.upload-zone {
  text-align: center;
}

.upload-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: #666;
}

.upload-status {
  margin-top: 8px;
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

.upload-status.success { color: #28a745; }
.upload-status.error { color: #dc3545; }

/* ========== Reference Data ========== */
.reference-data h4 {
  margin: 12px 0 4px;
  font-size: 13px;
  color: #666;
  font-weight: 500;
}

.ref-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}

.ref-table td {
  padding: 4px 0;
  vertical-align: top;
}

.ref-table td:first-child {
  color: #666;
  width: 100px;
  font-weight: 500;
}

.ref-name {
  margin: 0 0 8px;
  padding: 8px 12px;
  background: #f9f9fb;
  border-radius: 6px;
  font-size: 14px;
  word-break: break-word;
}

.ref-urls {
  margin: 4px 0;
  padding-left: 18px;
  font-size: 12px;
}

.ref-urls a {
  color: #0066cc;
  word-break: break-all;
}

/* ========== Right Panel - Form ========== */
.audit-right {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.audit-right h3 {
  margin: 0 0 20px;
  font-size: 18px;
  color: #112240;
}

.form-row { margin-bottom: 16px; }

.form-row label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.form-row .req { color: #dc3545; }

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d0d0d8;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  transition: border-color 0.15s;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: #112240;
  box-shadow: 0 0 0 3px rgba(17, 34, 64, 0.1);
}

.form-row input:disabled,
.form-row select:disabled,
.form-row textarea:disabled {
  background: #f5f5f7;
  color: #999;
  cursor: not-allowed;
}

.form-row textarea {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.form-actions .btn {
  flex: 1;
  min-width: 100px;
  padding: 12px;
  font-size: 14px;
}

.form-actions .btn-ghost {
  background: #e8e8ed;
  color: #333;
}

.form-actions .btn-ghost:hover:not(:disabled) { background: #d0d0d8; }

.form-status {
  margin-top: 12px;
  font-size: 13px;
  color: #666;
  text-align: center;
  min-height: 18px;
}

.form-status.success { color: #28a745; }
.form-status.error { color: #dc3545; }

/* ========== Modal ========== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-box h2 { margin: 0; }

.modal-box input {
  padding: 10px 12px;
  border: 1px solid #d0d0d8;
  border-radius: 6px;
  font-size: 14px;
}

.jump-results {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
}

.jump-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  font-size: 13px;
}

.jump-item:hover { background: #f5f5f7; }
.jump-item:last-child { border-bottom: none; }

.jump-item .status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.status.pending { background: #ccc; }
.status.completed { background: #28a745; }
.status.flagged { background: #dc3545; }
.status.skipped { background: #f0ad4e; }

.status-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-left: 6px;
}

.status-badge.claim {
  background: #fff3cd;
  color: #856404;
}

/* ========== Lightbox ========== */
.lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: transparent;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
  width: 40px;
  height: 40px;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .audit-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar-center { order: 3; flex-basis: 100%; }
}
