:root {
  --primary: #1e3a8a;
  --primary-light: #2563eb;
  --gold: #d97706;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

.hidden {
  display: none !important;
}

/* Login Overlay Styles */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: #ffffff;
  border-radius: 16px;
  padding: 2.25rem 2rem;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
  border-top: 5px solid #f59e0b;
}

.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.6rem;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.3);
}

.login-card h2 {
  text-align: center;
  font-size: 1.35rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.login-card p.sub {
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.login-field {
  margin-bottom: 1.1rem;
}

.login-field label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 0.35rem;
}

.login-field input {
  width: 100%;
  padding: 0.68rem 0.85rem;
  font-size: 0.98rem;
}

.btn-login-submit {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.75rem;
}

header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff;
  padding: 1.25rem 2rem;
  border-bottom: 4px solid #f59e0b;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
  color: #0f172a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand p {
  font-size: 0.88rem;
  color: #cbd5e1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-logout {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(239, 68, 68, 0.2);
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.dot-offline {
  background: #ef4444;
}

main {
  max-width: 1280px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 3rem;
}

.config-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 190px;
}

.field-group-wide {
  flex: 1.4;
}

.field-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

select,
input[type="text"],
input[type="password"],
textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab-btn {
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

.tab-btn:hover:not(.active) {
  background: #e2e8f0;
  color: var(--text);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 1.25rem;
}

@media (max-width: 960px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.35rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--primary);
}

.dropzone {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 2rem 1.25rem;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary-light);
  background: #eff6ff;
}

.dropzone h3 {
  font-size: 1.08rem;
  margin-bottom: 0.35rem;
  color: var(--primary);
}

.dropzone p {
  font-size: 0.88rem;
  color: var(--muted);
}

.file-preview {
  margin-top: 1rem;
  padding: 0.85rem;
  background: #f1f5f9;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.file-meta-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.img-preview-box {
  margin-top: 0.75rem;
  text-align: center;
}

.img-preview-box img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.img-preview-box img:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.img-preview-hint {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Document Preview Modal */
.doc-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.doc-modal.hidden {
  display: none;
}

.doc-modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: min(96vw, 1080px);
  height: min(92vh, 860px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.doc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.doc-modal-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-modal-body {
  flex: 1;
  overflow: auto;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.doc-modal-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  background: #ffffff;
}

.doc-modal-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 6px;
  background: #ffffff;
}

.doc-modal-body pre {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  background: #ffffff;
  color: #0f172a;
  border-radius: 6px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
}

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-flex-1 {
  flex: 1;
}

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

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

.btn-secondary {
  background: #e2e8f0;
  color: #1e293b;
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-outline {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.86rem;
  padding: 0.45rem 0.85rem;
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.divider {
  margin: 1.25rem 0;
  border: none;
  border-top: 1px solid var(--border);
}

.sample-hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.full-textarea {
  width: 100%;
}

.job-status-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-box {
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  text-align: center;
}

.stat-box .num {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.num-primary { color: var(--primary); }
.num-danger { color: var(--danger); }
.num-th { color: #1e40af; }
.num-en { color: #86198f; }

.stat-box .lbl {
  font-size: 0.78rem;
  color: var(--muted);
}

.summary-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: #eff6ff;
  border-left: 4px solid var(--primary-light);
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

.warning-banner {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--warning-bg);
  border-left: 4px solid var(--warning);
  color: #92400e;
  font-size: 0.88rem;
  margin-bottom: 0.85rem;
}

.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.section-label {
  font-size: 0.92rem;
  font-weight: 700;
}

.btn-group-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.highlight-section {
  margin-bottom: 1rem;
}

.highlight-box {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fcfcfd;
  white-space: pre-wrap;
  font-size: 0.95rem;
  max-height: 250px;
  overflow-y: auto;
  line-height: 1.8;
}

mark.err-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.08rem 0.3rem;
  border-radius: 4px;
  border-bottom: 2px solid #dc2626;
  font-weight: 600;
  cursor: pointer;
}

mark.err-warning {
  background: #fef3c7;
  color: #92400e;
  padding: 0.08rem 0.3rem;
  border-radius: 4px;
  border-bottom: 2px solid #d97706;
  font-weight: 600;
  cursor: pointer;
}

mark.err-suggestion {
  background: #e0f2fe;
  color: #075985;
  padding: 0.08rem 0.3rem;
  border-radius: 4px;
  border-bottom: 2px dashed #0284c7;
  cursor: pointer;
}

.issue-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 460px;
  overflow-y: auto;
  margin-top: 0.75rem;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.empty-state-success {
  text-align: center;
  padding: 2rem;
  color: var(--success);
  font-weight: 600;
}

.issue-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  background: #fff;
  border-left: 4px solid var(--danger);
}

.issue-card.sev-warning {
  border-left-color: var(--warning);
}

.issue-card.sev-suggestion {
  border-left-color: var(--info);
}

.issue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.word-diff {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 1.02rem;
  font-weight: 700;
}

.word-wrong {
  color: var(--danger);
  text-decoration: line-through;
  background: var(--danger-bg);
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
}

.word-correct {
  color: var(--success);
  background: var(--success-bg);
  padding: 0.1rem 0.5rem;
  border-radius: 5px;
}

.word-alts {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 400;
}

.badge-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
}

.badge-th {
  background: #dbeafe;
  color: #1e40af;
}

.badge-en {
  background: #fae8ff;
  color: #86198f;
}

.issue-exp {
  font-size: 0.88rem;
  color: #334155;
  margin-top: 0.25rem;
}

.issue-ctx {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
  font-family: monospace;
  background: #f8fafc;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.dict-filter-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.dict-lang-select {
  width: 140px;
}

.dict-scroll {
  max-height: 430px;
  overflow-y: auto;
}

table.dict-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

table.dict-table th,
table.dict-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  text-align: left;
}

table.dict-table th {
  background: #f1f5f9;
  font-weight: 700;
}

.dict-form-box {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.dict-form-title {
  display: block;
  margin-bottom: 0.6rem;
}

.dict-form-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.dict-form-row12 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

pre.code-block {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}
