:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --accent: #0d9488;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Noto Sans Thai", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.bg-glow {
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  top: -180px;
  left: -120px;
  background: #3b82f6;
}

.bg-glow-2 {
  bottom: -180px;
  right: -120px;
  background: #14b8a6;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

/* Header */
.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 12px;
  padding-bottom: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-weight: 500;
  color: var(--primary);
}

.brand-tagline {
  font-size: 0.8rem;
  color: var(--text-light);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warning);
}

.status-dot.loading {
  animation: pulse 1.3s infinite ease-in-out;
}

.status-dot.ready {
  background: var(--success);
}

.status-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* Main */
.main-content {
  flex: 1;
  padding-top: 24px;
  padding-bottom: 40px;
}

/* Loader Card */
.loader-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.loader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.loader-detail {
  color: var(--text-light);
  margin-left: 8px;
  font-size: 0.84rem;
}

.loader-pct {
  font-weight: 700;
  color: var(--primary);
}

.progress-track {
  height: 8px;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #0d9488);
  transition: width 0.25s ease;
}

/* Dropzone */
.dropzone {
  background: var(--surface);
  border: 2px dashed #cbd5e1;
  border-radius: 20px;
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, transform 0.15s;
  box-shadow: var(--shadow);
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--primary);
  background: #f8fbff;
}

.dropzone-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
}

.dropzone h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
  font-weight: 700;
}

.dropzone-sub {
  margin: 0 auto 22px;
  max-width: 540px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

kbd {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.8em;
  font-family: monospace;
}

.dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.url-import {
  max-width: 560px;
  margin: 0 auto 22px;
  cursor: default;
}

.url-input-group {
  display: flex;
  gap: 8px;
  background: var(--surface-muted);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.url-input-group input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
}

.url-error {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 0.83rem;
  text-align: left;
}

.privacy-badges {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.82rem;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.83rem;
  border-radius: 8px;
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Workspace */
.workspace-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.meta-chip {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text-light);
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* PDF Bar */
.pdf-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
}

.pdf-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pdf-page-info {
  font-size: 0.88rem;
  font-weight: 600;
  color: #1e40af;
}

/* Split Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 520px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fcfcfd;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-hint {
  font-size: 0.78rem;
  color: var(--text-light);
}

.canvas-stage {
  position: relative;
  flex: 1;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
  max-height: 680px;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  background: #fff;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  height: auto;
}

#overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-weight: 600;
  color: var(--primary);
  z-index: 5;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Tabs & Result */
.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
}

.tab.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.export-actions {
  display: flex;
  gap: 6px;
}

.stats-bar {
  display: flex;
  gap: 18px;
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--text-light);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
}

.tab-content.active {
  display: flex;
}

#resultTextarea {
  flex: 1;
  width: 100%;
  min-height: 420px;
  border: none;
  resize: none;
  padding: 16px;
  font-family: "Noto Sans Thai", "Inter", monospace;
  font-size: 0.96rem;
  line-height: 1.7;
  color: var(--text);
  outline: none;
}

.lines-list {
  flex: 1;
  overflow-y: auto;
  max-height: 580px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.line-item:hover,
.line-item.active {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.line-item-text {
  font-size: 0.92rem;
  word-break: break-word;
}

.conf-badge {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.conf-high {
  background: #dcfce7;
  color: #166534;
}

.conf-mid {
  background: #fef3c7;
  color: #92400e;
}

/* Footer */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: auto;
  position: relative;
  z-index: 1;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
}

.footer-title {
  font-size: 1rem;
  margin-bottom: 4px;
}

.footer-desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 480px;
}

.footer-links-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.footer-links ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer-links a {
  font-size: 0.84rem;
  color: var(--primary);
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 50;
}

.hidden {
  display: none !important;
}
