:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --panel-3: #1e293b;
  --border: #334155;
  --border-light: #475569;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --purple: #a855f7;
  --sidebar-w: 340px;
  --header-h: 64px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.15s ease;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --panel-3: #e2e8f0;
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --text: #1e293b;
  --text-dim: #64748b;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ───── TOPBAR ───── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-left h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.version {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--amber);
}
.badge-ok {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--green);
}
.badge-err {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--red);
}

/* ───── MAIN LAYOUT ───── */
.main-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

@media (max-width: 1100px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-h);
    bottom: 0;
    width: 320px;
    z-index: 50;
    overflow-y: auto;
    transition: left var(--transition);
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--border);
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
  }
  .sidebar-overlay.visible {
    display: block;
  }
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}

/* ───── DROPZONE ───── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 28px 16px;
  cursor: pointer;
  transition:
    border-color var(--transition),
    background var(--transition);
  position: relative;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}
.dropzone.dragover {
  transform: scale(1.01);
}
.dz-icon {
  font-size: 36px;
  margin: 0 0 8px;
}
.dz-text {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
}
.dz-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* ───── KTP PREVIEW ───── */
.ktp-preview {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-2);
  aspect-ratio: 1.586 / 1;
}
.ktp-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ktp-preview #btnClearPreview {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

/* ───── OCR PROGRESS ───── */
.ocr-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.progress-bar {
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 3px;
  transition: width 0.3s ease;
}
.progress-text {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

/* ───── STATUS LINE ───── */
.statusline {
  min-height: 20px;
  font-size: 12px;
  color: var(--text-dim);
}
.statusline.ok {
  color: var(--green);
}
.statusline.err {
  color: var(--red);
}

/* ───── OCR QUALITY BANNER ───── */
.ocr-quality {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.ocr-quality.q-excellent {
  color: var(--green);
  border-color: var(--green);
}
.ocr-quality.q-good {
  color: var(--green);
  border-color: var(--green);
  opacity: 0.9;
}
.ocr-quality.q-mid {
  color: var(--amber);
  border-color: var(--amber);
}
.ocr-quality.q-bad {
  color: var(--red);
  border-color: var(--red);
}

/* ───── FILTER GROUP ───── */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus {
  border-color: var(--accent);
}
.search-input::placeholder {
  color: var(--text-dim);
}

.filter-select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* ───── BULK ACTIONS ───── */
.bulk-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ───── CONTENT AREA ───── */
.content-area {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ───── PANEL ───── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.panel-actions {
  display: flex;
  gap: 8px;
}

.accounts-panel .panel-header {
  padding: 14px 20px;
}
.account-count {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.selected-badge {
  font-size: 12px;
  padding: 3px 10px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 999px;
  color: var(--accent);
}

/* ───── FORM ───── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  padding: 20px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group.full-width {
  grid-column: 1 / -1;
}
.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.required {
  color: var(--red);
  margin-left: 2px;
}

.input-row {
  display: flex;
  gap: 8px;
}
.input-row input {
  flex: 1;
}

input,
select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}
input::placeholder {
  color: var(--text-dim);
}
input[type="password"] {
  font-family: monospace;
}

.btn-gen {
  flex-shrink: 0;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ───── BUTTONS ───── */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover {
  border-color: var(--accent);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  padding: 8px 10px;
}
.btn-ghost:hover {
  background: var(--panel-3);
}

.btn-outline {
  background: transparent;
}
.btn-outline:hover {
  background: var(--panel-3);
  border-color: var(--accent);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
  color: var(--red);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
}
.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
}

.btn-sm {
  padding: 7px 10px;
  font-size: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding: 0 20px 20px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
.form-actions .btn-primary {
  margin-left: auto;
}

/* ───── ACCOUNT LIST ───── */
.account-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
  padding: 0 4px 4px;
}
.account-list::-webkit-scrollbar {
  width: 6px;
}
.account-list::-webkit-scrollbar-track {
  background: transparent;
}
.account-list::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}

.acc {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}
.acc:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow);
}
.acc.selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px var(--accent),
    var(--shadow);
}

.acc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.acc-checkbox {
  flex-shrink: 0;
  margin-right: 8px;
}
.acc-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.acc-info {
  flex: 1;
  min-width: 0;
}
.acc-email {
  font-weight: 600;
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
}
.acc-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.acc-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 0 14px 10px;
  border-top: 1px solid var(--border);
}
.chip {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.chip.ready {
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.12);
}
.chip.incomplete {
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
}
.chip.verified {
  color: var(--purple);
  border-color: rgba(168, 85, 247, 0.4);
  background: rgba(168, 85, 247, 0.12);
}
.chip.error {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.12);
}

.acc-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* ───── TOAST ───── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition:
    transform 0.3s ease,
    opacity 0.3s ease;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.ok {
  border-color: rgba(34, 197, 94, 0.5);
}
.toast.err {
  border-color: rgba(239, 68, 68, 0.5);
}
.toast.warn {
  border-color: rgba(245, 158, 11, 0.5);
}

/* ───── RESPONSIVE ───── */
@media (max-width: 640px) {
  .topbar {
    padding: 0 16px;
  }
  .topbar-left h1 {
    font-size: 16px;
  }
  .content-area {
    padding: 16px;
  }
  .form-grid {
    padding: 16px;
    gap: 12px;
  }
  .form-actions {
    padding: 0 16px 16px;
  }
  .form-actions .btn-primary {
    margin-left: 0;
    width: 100%;
  }
  .form-actions {
    flex-direction: column;
  }
  .btn {
    width: 100%;
  }
  .bulk-actions {
    flex-direction: column;
  }
  .bulk-actions .btn {
    width: 100%;
  }
}

/* ───── ANIMATIONS ───── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.acc {
  animation: fadeIn 0.2s ease;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ───── CONFIDENCE BADGES ───── */
.conf-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 28px;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  white-space: nowrap;
  margin-left: 4px;
  flex-shrink: 0;
}
.conf-badge.conf-high {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--green);
}
.conf-badge.conf-medium {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--amber);
}
.conf-badge.conf-low {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--red);
}

/* Input confidence border states */
input.conf-high,
select.conf-high {
  border-color: var(--green) !important;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15) !important;
}
input.conf-medium,
select.conf-medium {
  border-color: var(--amber) !important;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15) !important;
}
input.conf-low,
select.conf-low {
  border-color: var(--red) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}

/* ───── FIELD VALIDATION ───── */
.field-msg {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  min-height: 14px;
}
.field-msg.error {
  color: var(--red);
}
.field-msg.warning {
  color: var(--amber);
}
.field-msg.valid {
  color: var(--green);
}

input.valid,
select.valid {
  border-color: var(--green) !important;
}
input.warning,
select.warning {
  border-color: var(--amber) !important;
}
input.error,
select.error {
  border-color: var(--red) !important;
}

/* ───── DEBUG TOGGLE ───── */
.debug-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  user-select: none;
}
.debug-toggle:hover {
  background: var(--panel-3);
}
.debug-toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ───── DEBUG PANEL ───── */
.debug-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.debug-header h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
}
.debug-content {
  max-height: 300px;
  overflow: auto;
  font-size: 10px;
  font-family: monospace;
  background: var(--bg);
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
}
.debug-content pre {
  margin: 0;
}

/* ───── INPUT ROW WITH CONFIDENCE ───── */
.input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.input-row input {
  flex: 1;
}
.input-row .conf-badge {
  margin-left: 4px;
}
.input-row .btn-gen {
  flex-shrink: 0;
  width: 36px;
}

/* Form group with messages */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group.full-width {
  grid-column: 1 / -1;
}

/* ───── RESPONSIVE CONFIDENCE ───── */
@media (max-width: 640px) {
  .input-row .conf-badge {
    display: none;
  }
}

.hidden-field {
  display: none;
}
