/* ===== CSS Variables ===== */
:root {
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --border: #d1d5db;
  --bg: #f9fafb;
  --bg-hover: #f3f4f6;
  --ink: #111827;
  --muted: #6b7280;
  --error: #e11d48;
  --success: #065f46;
  --warning: #92400e;
}

/* ===== Base ===== */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell,
    "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji",
    sans-serif;
  color: var(--ink);
  margin: 0;
  padding: 20px;
}

h1 {
  margin-bottom: 20px;
}

h2 {
  font-size: 1.2em;
  margin-top: 0;
}

ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

li {
  margin-bottom: 8px;
}

li a {
  text-decoration: none;
  color: #007bff;
}

li a:hover {
  text-decoration: underline;
}

/* ===== Layout ===== */
.container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.form-container {
  width: 50%;
}

.files-container {
  width: 40%;
  margin-left: 20px;
  padding: 10px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  border-radius: 8px;
}

/* ===== Form Elements ===== */
.hint {
  display: block;
  margin-bottom: 12px;
  color: #374151;
}

.checkbox-label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.submit-row {
  margin-top: 12px;
}

input[type="submit"] {
  padding: 10px 20px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

input[type="submit"]:hover {
  background: var(--brand-hover);
}

/* ===== Messages ===== */
#error-message {
  color: var(--error);
  font-size: 0.9em;
  margin-top: 10px;
}

#status-message {
  color: #007bff;
  font-size: 1.1em;
  margin-top: 10px;
}

.loading {
  display: none;
}

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone strong {
  color: var(--brand);
}

.dropzone.dragover {
  border-color: var(--brand);
  background: #eff6ff;
}

.dz-filename {
  margin-top: 8px;
  color: #374151;
  font-size: 0.9em;
}

/* Hidden file input */
.file-input-hidden {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* ===== Results Table ===== */
#results-section {
  margin-top: 24px;
}

.results-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 8px;
}

#doc-table-wrap {
  width: 100%;
  max-height: 420px;
  overflow: auto;
  border: 1px solid #333;
  border-radius: 6px;
}

#doc-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

#doc-table thead th {
  position: sticky;
  top: 0;
  background: #1f2937;
  color: #fff;
  padding: 6px 8px;
  border-bottom: 1px solid #444;
  white-space: nowrap;
}

#doc-table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #333;
  white-space: nowrap;
}

/* ===== Badges ===== */
#detected-types {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  font-size: 12px;
}

.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #6366f1;
}

.badge .count {
  opacity: 0.8;
}

/* ===== Buttons ===== */
.btn {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.history-btn {
  margin-top: 16px;
}

.refresh-btn {
  padding: 6px 12px;
  font-size: 12px;
}

#btn-excel {
  display: none;
}

#download-button {
  display: none;
  margin-top: 10px;
  padding: 10px 15px;
  background: #007bff;
  color: #fff;
  border: none;
  cursor: pointer;
}

#download-button:hover {
  background: #0056b3;
}

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

.modal-overlay.active {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 900px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25em;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--ink);
}

.modal-body {
  padding: 20px;
  overflow: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* ===== History Table ===== */
#history-table-wrap {
  width: 100%;
  max-height: 400px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

#history-table {
  border-collapse: collapse;
  width: 100%;
}

#history-table thead th {
  position: sticky;
  top: 0;
  background: #1f2937;
  color: #fff;
  padding: 10px 12px;
  border-bottom: 1px solid #444;
  text-align: left;
  font-weight: 500;
}

#history-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
}

#history-table tbody tr:hover {
  background: var(--bg);
}

/* ===== Status Badges ===== */
.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.status-success {
  background: #d1fae5;
  color: var(--success);
}

.status-pending,
.status-in_progress {
  background: #fef3c7;
  color: var(--warning);
}

.status-failed {
  background: #fee2e2;
  color: #991b1b;
}

/* ===== Links ===== */
.download-link {
  color: var(--brand);
  text-decoration: none;
  cursor: pointer;
}

.download-link:hover {
  text-decoration: underline;
}

/* ===== Misc ===== */
.file-name {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-history {
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.cell-muted {
  color: #9ca3af;
}

/* ===== Toast Notifications ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  z-index: 2000;
  animation: slideIn 0.3s ease;
}

.toast.error {
  background: #dc2626;
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }

  .form-container,
  .files-container {
    width: 100%;
    margin-left: 0;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
  }
}
