:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252836;
  --bg-hover: #2a2d3a;
  --border: #2e3140;
  --text: #e4e6ef;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-h: #818cf8;
  --primary-bg: rgba(99, 102, 241, 0.1);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #0f1117;
  color: #e4e6ef;
  line-height: 1.6;
  min-height: 100vh;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-wrapper .login-box {
  background: #1a1d27;
  border: 1px solid #2e3140;
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  text-align: center;
}
.login-wrapper .login-box .logo-big {
  display: block;
  width: 200px;
  height: auto;
  margin: 0 auto 24px;
}
.login-wrapper .login-box h2 {
  font-size: 20px;
  margin-bottom: 8px;
}
.login-wrapper .login-box p {
  font-size: 13px;
  color: #8b8fa3;
  margin-bottom: 24px;
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.app {
  display: none;
  flex-direction: column;
  height: 100vh;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  min-width: 220px;
  background: #1a1d27;
  border-right: 1px solid #2e3140;
  display: flex;
  flex-direction: column;
  padding: 8px 0 12px;
  overflow-y: auto;
}

.sidebar .tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  color: #8b8fa3;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 8px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.sidebar .tab:hover {
  color: #e4e6ef;
  background: #252836;
}
.sidebar .tab.active {
  color: #818cf8;
  background: rgba(99, 102, 241, 0.12);
}
.sidebar .tab.admin-only {
  display: none;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.nav-sep {
  height: 1px;
  background: #2e3140;
  margin: 8px 16px;
}
.nav-grow {
  flex: 1;
  min-height: 12px;
}

.header {
  background: #1a1d27;
  border-bottom: 1px solid #2e3140;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header h1 {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.header h1 .logo {
  height: 28px;
  width: auto;
  display: block;
}
.header .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  font-size: 13px;
  color: #8b8fa3;
}
.user-info strong {
  color: #e4e6ef;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #8b8fa3;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b8fa3;
}
.status-dot.ok {
  background: #22c55e;
}
.status-dot.error {
  background: #ef4444;
}
.status-dot.loading {
  background: #f59e0b;
  animation: pulse 1s infinite;
}

.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.monitor-block {
  margin: 8px;
  border: 1px solid #2e3140;
  border-radius: 6px;
  background: #0f1117;
  overflow: hidden;
  flex-shrink: 0;
}
.monitor-header {
  padding: 13px 14px 11px;
  font-size: 10px;
  font-weight: 600;
  color: #8b8fa3;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid #2e3140;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.monitor-empty {
  padding: 24px 14px;
  font-size: 12px;
  color: #8b8fa3;
  text-align: center;
}
.monitor-item {
  padding: 10px 14px;
  border-bottom: 1px solid #2e3140;
}
.monitor-item:last-child {
  border-bottom: none;
}
.monitor-name {
  font-size: 12px;
  font-weight: 500;
  color: #e4e6ef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.monitor-elapsed {
  font-size: 10px;
  color: #8b8fa3;
}
.monitor-bar {
  margin-top: 5px;
  height: 3px;
  background: #252836;
  border-radius: 2px;
  overflow: hidden;
}
.monitor-bar-fill {
  height: 100%;
  background: #6366f1;
  border-radius: 2px;
  transition: width 0.3s;
}
.monitor-progress-label {
  font-size: 10px;
  color: #818cf8;
  margin-top: 2px;
}

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

.card {
  background: #1a1d27;
  border: 1px solid #2e3140;
  border-radius: 8px;
  margin-bottom: 16px;
}
.card .card-header {
  padding: 12px 20px;
  border-bottom: 1px solid #2e3140;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.card .card-header h2 {
  font-size: 14px;
  font-weight: 600;
}
.card .card-body {
  padding: 16px 20px;
}

.form-group {
  margin-bottom: 14px;
}
.form-group:last-child {
  margin-bottom: 0;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #8b8fa3;
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  background: #252836;
  border: 1px solid #2e3140;
  border-radius: 8px;
  color: #e4e6ef;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #6366f1;
}
.form-group textarea {
  min-height: 60px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

.form-row-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 14px;
}

.form-help {
  font-size: 10px;
  color: #8b8fa3;
  margin-top: 3px;
}

.alert-info {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: #8b8fa3;
  margin: 12px 20px 0;
  line-height: 1.5;
}

.sub-section {
  font-size: 13px;
  font-weight: 600;
  color: #8b8fa3;
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #2e3140;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: #6366f1;
  color: #fff;
}
.btn-primary:hover {
  background: #818cf8;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-success {
  background: #22c55e;
  color: #fff;
}
.btn-success:hover {
  filter: brightness(1.1);
}
.btn-danger {
  background: #ef4444;
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(1.1);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
}
.btn-outline {
  background: transparent;
  border: 1px solid #2e3140;
  color: #8b8fa3;
}
.btn-outline:hover {
  border-color: #6366f1;
  color: #818cf8;
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  text-align: left;
  padding: 8px 14px;
  color: #8b8fa3;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #2e3140;
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #2e3140;
  vertical-align: middle;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table tr:hover td {
  background: #2a2d3a;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
}
.badge-admin {
  background: rgba(99, 102, 241, 0.1);
  color: #818cf8;
}
.badge-viewer {
  background: #252836;
  color: #8b8fa3;
}
.badge-active {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}
.badge-inactive {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}
.badge-api {
  background: #6366f1;
  color: #fff;
}
.badge-csv {
  background: #f59e0b;
  color: #fff;
}
.badge-script {
  background: #22c55e;
  color: #fff;
}

.api-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid #2e3140;
  cursor: pointer;
  transition: background 0.15s;
}
.api-card:last-child {
  border-bottom: none;
}
.api-card:hover {
  background: #2a2d3a;
}
.api-card .api-card-info h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 1px;
}
.api-card .api-card-info p {
  font-size: 11px;
  color: #8b8fa3;
}
.api-card .api-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mapping-header,
.mapping-row {
  display: grid;
  grid-template-columns: 1fr 28px 1fr 90px 70px 90px 36px 32px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #2e3140;
}
.mapping-header:last-child,
.mapping-row:last-child {
  border-bottom: none;
}

.mapping-header {
  font-size: 10px;
  color: #8b8fa3;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  border-bottom: 2px solid #2e3140;
}

.mapping-row .arrow {
  text-align: center;
  color: #6366f1;
  font-size: 14px;
}
.mapping-row input,
.mapping-row select {
  padding: 7px 8px;
  background: #252836;
  border: 1px solid #2e3140;
  border-radius: 8px;
  color: #e4e6ef;
  font-size: 12px;
  font-family: inherit;
}
.mapping-row input:focus,
.mapping-row select:focus {
  outline: none;
  border-color: #6366f1;
}

.remove-field-btn {
  background: none;
  border: none;
  color: #8b8fa3;
  cursor: pointer;
  font-size: 14px;
  padding: 3px;
  border-radius: 4px;
}
.remove-field-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.remarks-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  cursor: default;
}
.remarks-tooltip .remarks-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.5);
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}
.remarks-tooltip .remarks-tip {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1d27;
  border: 1px solid rgba(245, 158, 11, 0.6);
  color: #e4e6ef;
  font-size: 11px;
  font-style: normal;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: normal;
  word-break: break-word;
  max-width: 760px;
  min-width: 400px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.remarks-tooltip .remarks-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(245, 158, 11, 0.6);
}
.remarks-tooltip:hover .remarks-tip {
  opacity: 1;
}

.pipeline-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid #2e3140;
}
.pipeline-card:last-child {
  border-bottom: none;
}
.pipeline-card:hover {
  background: #2a2d3a;
}
.pipeline-card[onclick] {
  cursor: pointer;
}
.pipeline-card .pipeline-info h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 1px;
}
.pipeline-card .pipeline-info p {
  font-size: 11px;
  color: #8b8fa3;
}
.pipeline-card .pipeline-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pipeline-card .pipeline-last-run {
  font-size: 10px;
  color: #8b8fa3;
}

.log-viewer {
  background: #0d0f14;
  border-radius: 8px;
  padding: 14px;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1.7;
  max-height: 500px;
  overflow-y: auto;
}
.log-viewer .log-entry {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}
.log-viewer .log-time {
  color: #8b8fa3;
  white-space: nowrap;
  flex-shrink: 0;
}
.log-viewer .log-level {
  font-weight: 600;
  width: 52px;
  flex-shrink: 0;
}
.log-viewer .log-level.DEBUG {
  color: #8b8fa3;
}
.log-viewer .log-level.INFO {
  color: #818cf8;
}
.log-viewer .log-level.WARNING {
  color: #f59e0b;
}
.log-viewer .log-level.ERROR {
  color: #ef4444;
}
.log-viewer .log-message {
  word-break: break-word;
}
.log-viewer .log-context {
  color: #8b8fa3;
  font-size: 10px;
}

.log-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.log-toolbar select {
  background: #252836;
  border: 1px solid #2e3140;
  border-radius: 8px;
  color: #e4e6ef;
  padding: 4px 8px;
  font-size: 11px;
  font-family: inherit;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.status-grid .status-item {
  background: #252836;
  border-radius: 8px;
  padding: 12px;
}
.status-grid .status-item .label {
  font-size: 10px;
  color: #8b8fa3;
  margin-bottom: 3px;
}
.status-grid .status-item .value {
  font-size: 14px;
  font-weight: 600;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.open {
  display: flex;
}
.modal-overlay .modal {
  background: #1a1d27;
  border: 1px solid #2e3140;
  border-radius: 12px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-overlay .modal .modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid #2e3140;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-overlay .modal .modal-header h3 {
  font-size: 15px;
}
.modal-overlay .modal .modal-close {
  background: none;
  border: none;
  color: #8b8fa3;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}
.modal-overlay .modal .modal-close:hover {
  color: #e4e6ef;
}
.modal-overlay .modal .modal-body {
  padding: 16px 20px;
}
.modal-overlay .modal .modal-footer {
  padding: 14px 20px;
  border-top: 1px solid #2e3140;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.json-preview {
  background: #0d0f14;
  border-radius: 8px;
  padding: 12px;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 11px;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  color: #8b8fa3;
}

.quality-bar {
  height: 6px;
  border-radius: 3px;
  background: #252836;
  overflow: hidden;
  margin-top: 4px;
}
.quality-bar .quality-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  background: #22c55e;
}
.toast.error {
  background: #ef4444;
}

.empty {
  text-align: center;
  padding: 32px;
  color: #8b8fa3;
  font-size: 13px;
}

.file-drop {
  border: 2px dashed #2e3140;
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  color: #8b8fa3;
  transition: all 0.2s;
  cursor: pointer;
}
.file-drop:hover, .file-drop.drag-over {
  border-color: #6366f1;
  color: #818cf8;
  background: rgba(99, 102, 241, 0.1);
}

@media (max-width: 768px) {
  .header {
    padding: 12px 16px;
  }
  .sidebar {
    width: 180px;
    min-width: 180px;
  }
  .main {
    padding: 16px;
  }
  .monitor-block {
    display: none;
  }
  .form-row,
  .form-row-3,
  .form-row-4 {
    grid-template-columns: 1fr;
  }
  .mapping-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .mapping-row .arrow {
    display: none;
  }
  .mapping-header {
    display: none;
  }
  .pipeline-card,
  .api-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
