/* ========================================
   JefBot Connect — Styles
   ======================================== */

:root {
  --primary: #25D366;
  --primary-dark: #1da851;
  --primary-light: #dcfce7;
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --bg-input: #252525;
  --border: #2a2a2a;
  --border-focus: #25D366;
  --text: #f5f5f5;
  --text-secondary: #888;
  --text-muted: #555;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  padding: 20px 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-icon {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--danger);
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: var(--primary);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.logo-icon svg {
  width: 26px;
  height: 26px;
}

.logo h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

/* Steps */
.step { display: none; }
.step.active { display: block; animation: fadeUp 0.4s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Step Header */
.step-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.step-number {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.step-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.step-header p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 3px;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: all 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

/* Select */
.select-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: all 0.2s;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.select-input option {
  background: var(--bg-card);
  color: var(--text);
}

.hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 12px;
  margin-top: 12px;
}

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

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  width: auto;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* QR Container */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 24px;
}

.qr-loading, .qr-expired {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px;
  color: var(--text-secondary);
}

.qr-expired svg {
  color: var(--warning);
}

.qr-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#qrImage {
  width: 280px;
  height: 280px;
  border-radius: 16px;
  background: #fff;
  padding: 12px;
}

.qr-timer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

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

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

/* Instructions */
.instructions {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-top: 4px;
}

.instructions h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.instructions ol {
  padding-left: 20px;
}

.instructions li {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 4px 0;
  line-height: 1.5;
}

.instructions li strong {
  color: var(--text);
}

/* Success */
.success-container {
  text-align: center;
  padding: 20px 0;
}

.success-icon {
  width: 100px;
  height: 100px;
  background: rgba(37, 211, 102, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  color: var(--primary);
  animation: scaleIn 0.5s ease;
}

@keyframes scaleIn {
  from { transform: scale(0); }
  60% { transform: scale(1.1); }
  to { transform: scale(1); }
}

.success-container h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.success-container > p {
  color: var(--text-secondary);
  font-size: 15px;
}

.connection-info {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 24px 0;
  text-align: left;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.info-row + .info-row {
  border-top: 1px solid var(--border);
}

.info-label {
  font-size: 13px;
  color: var(--text-muted);
}

.info-value {
  font-size: 14px;
  font-weight: 600;
}

.status-online {
  color: var(--primary);
}

.action-buttons {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* Existing Instances */
.existing-instances {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.existing-instances h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.instance-item {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  transition: background 0.2s;
  overflow: hidden;
}

.instance-item:hover {
  background: var(--bg-card-hover);
}

.instance-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  cursor: pointer;
}

.instance-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.instance-chevron.open {
  transform: rotate(180deg);
}

/* Instance details panel */
.instance-details {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-section {
  padding-top: 16px;
}

.detail-section h4 {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

.detail-field {
  margin-bottom: 12px;
}

.detail-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.detail-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-value {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  color: var(--text);
  word-break: break-all;
  line-height: 1.4;
}

.detail-token {
  font-size: 11px;
  color: var(--warning);
}

.btn-copy {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-copy:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Token toggle eye button */
.btn-toggle-token {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-toggle-token:hover {
  background: var(--bg-card-hover);
  color: var(--warning);
  border-color: var(--warning);
}

.token-mask {
  color: var(--text-muted);
  letter-spacing: 2px;
  user-select: none;
}

.instance-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.instance-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.instance-status.open { background: var(--primary); }
.instance-status.close { background: var(--danger); }
.instance-status.connecting { background: var(--warning); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.instance-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.instance-state {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.instance-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Action button styles */
.btn-connect {
  background: rgba(37, 211, 102, 0.12);
  color: var(--primary);
  border: 1px solid rgba(37, 211, 102, 0.25);
}

.btn-connect:hover {
  background: rgba(37, 211, 102, 0.22);
}

.btn-disconnect {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-disconnect:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-restart {
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.btn-restart:hover {
  background: rgba(251, 191, 36, 0.2);
}

.btn-delete {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-delete:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-restart:disabled,
.btn-connect:disabled,
.btn-disconnect:disabled,
.btn-delete:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transition: transform 0.3s ease;
  z-index: 1000;
  max-width: 90vw;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.toast.success {
  border-color: rgba(37, 211, 102, 0.4);
  color: #86efac;
}

/* Auto-Restart Panel */
.auto-restart-panel {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 8px 0;
  user-select: none;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-arrow {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.panel-arrow.open {
  transform: rotate(180deg);
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-on {
  background: rgba(37, 211, 102, 0.15);
  color: var(--primary);
}

.badge-off {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.panel-body {
  padding: 16px 0 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 26px;
  transition: 0.3s;
}

.slider:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* Time config */
.time-config {
  padding: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.time-config label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.time-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.time-slot {
  display: flex;
  align-items: center;
  gap: 4px;
}

.time-slot input[type="time"] {
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.time-slot input[type="time"]:focus {
  border-color: var(--primary);
}

.time-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  font-size: 18px;
  line-height: 1;
  opacity: 0.6;
}

.time-remove:hover { opacity: 1; }

/* Restart logs */
.restart-logs {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.restart-logs h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.log-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.log-entry:last-child { border: none; }

.log-status-ok { color: var(--primary); }
.log-status-error { color: var(--danger); }

/* Filter bar */
.filter-bar {
  margin-bottom: 16px;
}

.select-filter {
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
}

/* Instances header */
.instances-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.instances-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Create form */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.company-select-row {
  display: flex;
  gap: 8px;
}

.inline-new-company {
  background: var(--bg-input);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.inline-row {
  display: flex;
  gap: 10px;
}

/* Collapsible cards */
.collapsible-card {
  margin-top: 16px;
}

/* Companies Panel */
.company-form {
  padding: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.company-form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.company-input {
  flex: 1;
  min-width: 100px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.company-input:focus {
  border-color: var(--primary);
}

.company-input::placeholder {
  color: var(--text-muted);
}

.company-input-sm {
  max-width: 120px;
}

.companies-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.company-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  gap: 12px;
}

.company-item-info {
  flex: 1;
  min-width: 0;
}

.company-item-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  margin-top: 2px;
}

.company-item-meta code {
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.company-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-copy {
  background: rgba(99, 102, 241, 0.1);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.btn-copy:hover {
  background: rgba(99, 102, 241, 0.2);
}

/* Responsive */
@media (max-width: 540px) {
  .app { padding: 12px; }
  .card { padding: 20px; }
  #qrImage { width: 240px; height: 240px; }
  .instance-actions { flex-wrap: wrap; }
}
