/* ==========================================
   INTEGRATIONS PAGE
   frontend/admin/integrations.html
   ========================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #181818;
  --card-bg:      #1e1e1e;
  --border:       rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.10);
  --text-primary: #e5e7eb;
  --text-secondary:#9ca3af;
  --text-muted:   #6b7280;
  --radius:       14px;
  --sidebar-w:    210px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* === TOP BAR === */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: #202020;
  border-bottom: 1px solid rgba(59,130,246,0.15);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

.topbar-left  { flex: 1; }
.topbar-center{ flex: 1; }
.topbar-right { flex: 1; display: flex; justify-content: flex-end; }

.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-title .ui-icon { width: 17px; height: 17px; stroke: #9ca3af; flex-shrink: 0; }
.topbar-text { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }

.topbar-action {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  font-size: 0.85rem; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; border: 1px solid transparent; text-decoration: none;
  transition: color 150ms, border-color 150ms, background 150ms;
}
.topbar-action:hover { color: var(--text-primary); border-color: var(--border-hover); background: rgba(255,255,255,0.04); }
.topbar-icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.ui-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* === PAGE LAYOUT === */
.int-layout {
  display: flex;
  height: 100vh;
  padding-top: 56px;
}

/* === SIDEBAR === */
.int-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.int-sidebar::-webkit-scrollbar { width: 4px; }
.int-sidebar::-webkit-scrollbar-track { background: transparent; }
.int-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
.int-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

.int-sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 8px;
}

.int-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 150ms, color 150ms;
  user-select: none;
  position: relative;
}

.int-nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }

.int-nav-item.active {
  background: rgba(59,130,246,0.1);
  color: #60a5fa;
}

.int-nav-icon {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.int-nav-icon--allegro { background: rgba(255,103,0,0.12); color: #fb923c; }
.int-nav-icon--erli    { background: rgba(59,130,246,0.12); color: #60a5fa; }
.int-nav-icon--ai      { background: rgba(139,92,246,0.12); color: #a78bfa; }

.int-nav-item .ui-icon { width: 15px; height: 15px; }

.int-nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.int-nav-badge--soon {
  background: rgba(139,92,246,0.15);
  color: #a78bfa;
}

/* === CONTENT === */
.int-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 48px;
}

/* === PANEL === */
.int-panel { }

.int-panel-header { margin-bottom: 24px; }
.int-panel-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; }
.int-panel-sub { margin-top: 3px; font-size: 0.875rem; color: var(--text-muted); }

/* === CARDS GRID === */
.int-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: stretch;
}

/* === CARD === */
.int-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 180ms, box-shadow 180ms;
}

.int-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.int-card--wide {
  grid-column: 1 / -1;
}

.int-card--empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  text-align: center;
  gap: 12px;
}

.empty-icon {
  width: 48px; height: 48px;
  stroke: var(--text-muted);
  opacity: 0.4;
}
.empty-title { font-size: 1rem; font-weight: 600; color: var(--text-secondary); }
.empty-sub { font-size: 0.875rem; color: var(--text-muted); max-width: 380px; line-height: 1.6; }

/* === CARD HEADER === */
.int-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.int-card-header .ui-icon { color: var(--text-muted); }

/* === STATUS INDICATOR === */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.status-connected    { background: #10b981; box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.status-dot.status-disconnected { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,0.5); animation: none; }
.status-dot.status-unknown      { background: #6b7280; animation: none; }

.status-text { font-size: 0.875rem; color: var(--text-secondary); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* === META ROWS === */
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.meta-row:last-child { border-bottom: none; }
.meta-label { color: var(--text-muted); }
.meta-value { color: var(--text-primary); font-weight: 600; font-size: 0.8rem; }

/* === NOTICES === */
.int-notice {
  font-size: 0.875rem;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid;
  margin-bottom: 4px;
}
.int-notice--ok   { background: rgba(16,185,129,0.08); color: #34d399; border-color: rgba(16,185,129,0.2); }
.int-notice--warn { background: rgba(245,158,11,0.08); color: #fbbf24; border-color: rgba(245,158,11,0.2); }
.int-notice--info { background: rgba(59,130,246,0.08); color: #60a5fa; border-color: rgba(59,130,246,0.2); }

.int-hint { font-size: 0.8rem; color: var(--text-muted); margin: 8px 0 4px; }

/* === AUTH CODE BOX === */
.auth-code-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 12px;
}
.auth-code-label { font-size: 0.75rem; color: var(--text-muted); }
.auth-code { font-size: 1.2rem; letter-spacing: 3px; font-weight: 700; color: var(--text-primary); }
.auth-link { font-size: 0.8rem; color: #60a5fa; text-decoration: none; }
.auth-link:hover { text-decoration: underline; }

/* === SUCCESS BADGE === */
.success-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(16,185,129,0.1);
  color: #34d399;
  border: 1px solid rgba(16,185,129,0.2);
}
.success-badge::before { content: '✓'; }

/* === FORMS === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group small {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-group small code {
  background: rgba(255,255,255,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.form-group .form-control,
.form-group input:not([type="checkbox"]),
.form-group select {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 150ms, background 150ms;
  width: 100%;
}

.form-group .form-control:focus,
.form-group input:focus {
  border-color: rgba(59,130,246,0.5);
  background: rgba(59,130,246,0.04);
}

.form-group--inline { flex-direction: row; align-items: center; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--text-secondary); cursor: pointer; }
.toggle-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: #3b82f6; }

.req { color: #f87171; }

.allegro-scope-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px 22px;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
}

.allegro-scope-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.allegro-scope-group__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.allegro-scope-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.allegro-scope-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #f97316;
}

.allegro-scope-item__content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.allegro-scope-item__code {
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-word;
}

.allegro-scope-item__description {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.allegro-scope-preview {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.allegro-scope-preview__label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.allegro-scope-preview__value {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  color: var(--text-primary);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* === BUTTONS === */
.btn-action {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px;
  border-radius: 10px; border: 1.5px solid;
  font-family: inherit; font-weight: 600; font-size: 0.875rem;
  cursor: pointer;
  transition: background 180ms, box-shadow 180ms, transform 120ms;
}
.btn-action:active { transform: translateY(1px); }
.btn-action .ui-icon { width: 15px; height: 15px; }

.btn-save {
  background: rgba(59,130,246,0.1); color: #60a5fa; border-color: rgba(59,130,246,0.35);
}
.btn-save:hover { background: rgba(59,130,246,0.18); box-shadow: 0 2px 10px rgba(59,130,246,0.2); }

.btn-secondary {
  background: rgba(255,255,255,0.04); color: var(--text-secondary); border-color: var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.08); border-color: var(--border-hover); }

.btn-danger {
  background: rgba(239,68,68,0.1); color: #f87171; border-color: rgba(239,68,68,0.35);
}
.btn-danger:hover { background: rgba(239,68,68,0.18); box-shadow: 0 2px 10px rgba(239,68,68,0.2); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* === HISTORY TABLE === */
.history-table {
  width: 100%;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.history-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255,255,255,0.02);
}

.history-table td { color: var(--text-secondary); }

.history-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.history-table tbody tr:last-child td { border-bottom: none; }

/* === MISC === */
.text-muted { font-size: 0.875rem; color: var(--text-muted); }

/* === RESPONSIVE === */
@media (max-width: 1100px) {
  .int-cards-grid { grid-template-columns: repeat(2, 1fr); }
  .allegro-scope-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .int-sidebar { width: 60px; padding: 16px 8px; }
  .int-sidebar-label,
  .int-nav-item span:not(.int-nav-badge) { display: none; }
  .int-nav-item { justify-content: center; padding: 9px; }
  .int-content { padding: 20px 16px 32px; }
  .int-cards-grid { grid-template-columns: 1fr; }
  .allegro-scope-groups { grid-template-columns: 1fr; padding: 14px; }
}
