/* API Management Drawer Styles */

/* Hide burger menu when drawer is open */
body.api-drawer-open > .mobile-menu-toggle {
  display: none !important;
}

/* Overlay */
.api-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: flex;
  justify-content: flex-end;
  animation: apiDrawerFadeIn 0.2s ease;
}

.api-drawer-overlay.hidden {
  display: none !important;
}

@keyframes apiDrawerFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes apiDrawerSlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* Drawer panel */
.api-drawer {
  width: 380px;
  max-width: 95vw;
  height: 100%;
  background: var(--bg-surface, #1a1a1a);
  border-left: 1px solid var(--border, #333);
  display: flex;
  flex-direction: column;
  animation: apiDrawerSlideIn 0.25s ease;
}

/* Drawer header */
.api-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, #333);
  background: var(--bg-card, #1e293b);
}

.api-drawer-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-drawer-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  margin: 0;
}

.api-drawer-subtitle {
  font-size: 13px;
  color: var(--text-secondary, #94a3b8);
}

.api-drawer-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-secondary, #94a3b8);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}

.api-drawer-close:hover {
  color: var(--text-primary, #f1f5f9);
  background: var(--bg-hover, rgba(255, 255, 255, 0.1));
}

/* Drawer body */
.api-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Drawer footer */
.api-drawer-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border, #333);
  background: var(--bg-card, #1e293b);
}

.api-drawer-footer .btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Section titles */
.api-section {
  margin-bottom: 20px;
}

.api-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px 0;
}

/* Exchange cards */
.api-exchange-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg, #0f172a);
  border: 1px solid var(--border, #333);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}

.api-exchange-card.connected {
  border-color: rgba(34, 197, 94, 0.3);
}

.api-exchange-card:hover {
  border-color: var(--brand, #6366f1);
}

.api-exchange-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

.api-exchange-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.api-exchange-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-exchange-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
}

.api-exchange-status {
  font-size: 12px;
  color: var(--text-secondary, #94a3b8);
}

.api-exchange-status.connected {
  color: var(--success, #22c55e);
}

.api-exchange-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.api-exchange-actions .btn {
  padding: 6px 12px;
  font-size: 12px;
}

/* Empty hint */
.api-empty-hint {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary, #94a3b8);
  font-size: 14px;
}

/* Loading spinner inline */
.loading-spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border, #333);
  border-top-color: var(--brand, #6366f1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Loading state */
.api-drawer-body .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  color: var(--text-secondary, #94a3b8);
}

.api-drawer-body .loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border, #333);
  border-top-color: var(--brand, #6366f1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

/* Error state */
.api-drawer-body .error-state {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary, #94a3b8);
}

/* ========== Connection Modal ========== */
.api-connection-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10001;
}

.api-connection-modal.hidden {
  display: none !important;
}

.api-connection-modal-content {
  background: var(--bg-surface, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.api-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border, #333);
}

.api-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
}

.api-modal-header p {
  margin: 2px 0 0 0;
  font-size: 13px;
  color: var(--text-secondary, #94a3b8);
}

.api-modal-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary, #94a3b8);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.api-modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover, rgba(255, 255, 255, 0.1));
}

#apiConnectionForm {
  padding: 16px;
}

.api-form-group {
  margin-bottom: 16px;
}

.api-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #f1f5f9);
  margin-bottom: 6px;
}

.api-form-group .required {
  color: var(--error, #ef4444);
}

.api-form-group .input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  background: var(--bg, #0f172a);
  color: var(--text-primary, #f1f5f9);
  font-size: 14px;
}

.api-form-group .input:focus {
  outline: none;
  border-color: var(--brand, #6366f1);
}

/* Permissions info */
.api-permissions-info {
  padding: 12px;
  background: var(--bg, #0f172a);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.api-permissions-label {
  margin: 0 0 8px 0;
  font-weight: 500;
  color: var(--text-secondary, #94a3b8);
}

.api-permissions-info ul {
  margin: 0 0 12px 0;
  padding-left: 20px;
  color: var(--text-secondary, #94a3b8);
}

.api-permissions-info li {
  margin-bottom: 4px;
}

.api-setup-steps {
  margin: 0 0 12px 0;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-primary, #e2e8f0);
}

.api-setup-steps li {
  margin-bottom: 6px;
  line-height: 1.4;
}

.api-setup-steps li b {
  color: var(--text-white, #fff);
}

.api-guide-link {
  color: var(--brand, #6366f1);
  text-decoration: none;
  font-size: 12px;
}

.api-guide-link:hover {
  text-decoration: underline;
}

/* Test result */
#apiTestResult {
  margin-bottom: 16px;
}

.api-test-success {
  padding: 12px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 8px;
  color: var(--success, #22c55e);
  font-size: 14px;
}

.api-test-success small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.8;
}

.api-test-error {
  padding: 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  color: var(--error, #ef4444);
  font-size: 14px;
}

.api-test-error strong {
  display: block;
  margin-bottom: 4px;
}

.api-test-error p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary, #94a3b8);
}

/* Modal actions */
.api-modal-actions {
  display: flex;
  gap: 10px;
}

.api-modal-actions .btn {
  flex: 1;
  padding: 10px 16px;
}

/* ========== Multi-Account UI ========== */

/* Exchange group container */
.api-exchange-group {
  background: var(--bg, #0f172a);
  border: 1px solid var(--border, #333);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.api-exchange-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card, #1e293b);
  border-bottom: 1px solid var(--border, #333);
}

.api-exchange-group-header .api-exchange-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.api-exchange-group-header .api-exchange-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  flex: 1;
}

.api-account-count {
  font-size: 11px;
  color: var(--text-secondary, #94a3b8);
  background: var(--bg, #0f172a);
  padding: 3px 8px;
  border-radius: 12px;
}

/* Accounts list */
.api-accounts-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Individual account row */
.api-account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-surface, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  transition: all 0.15s;
}

.api-account-row:hover {
  border-color: var(--brand, #6366f1);
}

.api-account-row.paused {
  opacity: 0.6;
}

.api-account-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-account-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-account-status {
  font-size: 11px;
  color: var(--text-secondary, #94a3b8);
}

.api-account-status.active {
  color: var(--success, #22c55e);
}

.api-account-status.paused {
  color: var(--warning, #f59e0b);
}

.api-account-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.api-account-actions .btn {
  padding: 5px 10px;
  font-size: 11px;
}

/* Add another account button */
.api-add-account-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px 12px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary, #94a3b8);
  background: transparent;
  border: 1px dashed var(--border, #333);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.api-add-account-btn:hover {
  color: var(--brand, #6366f1);
  border-color: var(--brand, #6366f1);
  background: rgba(99, 102, 241, 0.05);
}

.api-add-account-btn svg {
  flex-shrink: 0;
}

/* Form field hints */
.api-field-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-tertiary, #64748b);
}

/* Optional label styling */
.api-form-group .optional {
  font-weight: normal;
  font-size: 11px;
  color: var(--text-tertiary, #64748b);
}

/* Mobile responsive */
@media (max-width: 480px) {
  .api-drawer {
    width: 100%;
    max-width: 100%;
  }

  .api-drawer-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
  }

  .api-exchange-card {
    flex-wrap: wrap;
  }

  .api-exchange-actions {
    width: 100%;
    margin-top: 8px;
  }

  .api-exchange-actions .btn {
    flex: 1;
  }

  /* Multi-account mobile adjustments */
  .api-account-row {
    flex-wrap: wrap;
  }

  .api-account-actions {
    width: 100%;
    margin-top: 6px;
  }

  .api-account-actions .btn {
    flex: 1;
  }
}

/* ========== Sync Status Panel ========== */

.api-sync-status-panel {
  padding: 12px 16px;
  background: var(--bg-card, #1e293b);
  border-bottom: 1px solid var(--border, #333);
}

.sync-status-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg, #0f172a);
  border-radius: 8px;
}

.sync-status-row.running {
  border-left: 3px solid var(--brand, #6366f1);
}

.sync-status-row.error {
  border-left: 3px solid var(--error, #ef4444);
  background: rgba(239, 68, 68, 0.05);
}

.sync-status-row.idle {
  border-left: 3px solid var(--success, #22c55e);
}

.sync-status-indicator {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sync-status-icon {
  font-size: 16px;
}

.sync-status-info {
  flex: 1;
  min-width: 0;
}

.sync-status-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  margin-bottom: 2px;
}

.sync-status-message {
  font-size: 12px;
  color: var(--text-secondary, #94a3b8);
}

.sync-status-detail {
  font-size: 11px;
  color: var(--text-secondary, #94a3b8);
  margin-top: 4px;
}

.sync-status-detail.zero-fills {
  color: var(--warning, #f59e0b);
}

.sync-status-exchange {
  font-size: 11px;
  color: var(--text-tertiary, #64748b);
  margin-top: 4px;
}

.sync-status-recovery {
  font-size: 11px;
  color: var(--text-secondary, #94a3b8);
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 4px;
}

.sync-retry-btn {
  flex-shrink: 0;
  align-self: center;
}

/* Sync Logs */
.sync-logs-panel {
  margin-top: 12px;
  padding: 10px;
  background: var(--bg, #0f172a);
  border-radius: 8px;
  border: 1px solid var(--border, #333);
}

.sync-logs-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.sync-logs-empty {
  font-size: 12px;
  color: var(--text-tertiary, #64748b);
  padding: 8px 0;
}

.sync-logs-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.sync-log-entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  background: var(--bg-surface, #1a1a1a);
  border-radius: 4px;
}

.sync-log-entry.error {
  background: rgba(239, 68, 68, 0.1);
}

.sync-log-entry.warn {
  background: rgba(234, 179, 8, 0.1);
}

.sync-log-time {
  color: var(--text-tertiary, #64748b);
  flex-shrink: 0;
}

.sync-log-code {
  color: var(--brand, #6366f1);
  flex-shrink: 0;
  font-weight: 500;
}

.sync-log-message {
  color: var(--text-secondary, #94a3b8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-log-entry.error .sync-log-message {
  color: var(--error, #ef4444);
}

.sync-log-entry.warn .sync-log-message {
  color: var(--warning, #eab308);
}

/* Loading spinner inline */
.loading-spinner-inline {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border, #333);
  border-top-color: var(--brand, #6366f1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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