:root {
  --bg-dark: #0b0f19;
  --bg-card: #151b2b;
  --bg-card-hover: #1c2438;
  --border: #232d42;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* MODAL DE LOGIN */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 13, 0.85);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; padding: 1rem;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.logo-area { text-align: center; margin-bottom: 2rem; }
.logo-icon {
  width: 54px; height: 54px;
  background: linear-gradient(135deg, #2563eb, #10b981);
  border-radius: 14px; display: inline-flex;
  align-items: center; justify-content: center;
  color: #fff; margin-bottom: 0.8rem;
  box-shadow: 0 8px 24px rgba(37,99,235,0.3);
}
.logo-area h2 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.logo-area h2 span { color: var(--primary); }
.logo-area p { font-size: 0.85rem; color: var(--text-muted); }

.quick-logins {
  margin-top: 1.5rem; padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-muted);
}
.btn-chip {
  background: #1e293b; border: 1px solid var(--border);
  color: var(--text-main); padding: 0.25rem 0.6rem;
  border-radius: 6px; font-size: 0.75rem; cursor: pointer;
  transition: all 0.2s;
}
.btn-chip:hover { background: var(--primary); border-color: var(--primary); }

/* LAYOUT PRINCIPAL */
.app-layout {
  display: flex; flex-direction: column; min-height: 100vh;
}
.top-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-logo {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #2563eb, #10b981);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.brand-title { font-size: 1.25rem; font-weight: 800; }
.brand-title span { color: var(--primary); }
.brand-sub { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.instance-status-pill {
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  padding: 0.35rem 0.85rem; border-radius: 999px;
  font-size: 0.8rem;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
}
.dot-green { background: #10b981; box-shadow: 0 0 8px #10b981; }
.dot-red { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.dot-yellow { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }
.dot-gray { background: #64748b; }

.user-profile { display: flex; align-items: center; gap: 0.75rem; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: #2563eb; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.user-info { display: flex; flex-direction: column; }
.user-info strong { font-size: 0.85rem; }
.user-info small { font-size: 0.7rem; color: var(--text-muted); }

/* TABS */
.tabs-bar {
  background: #111726;
  border-bottom: 1px solid var(--border);
  padding: 0.3rem 1.5rem 0;
  display: flex; gap: 0.5rem; overflow-x: auto;
  scrollbar-width: none;
}
.tab-btn {
  background: transparent; border: none;
  color: var(--text-muted); padding: 0.75rem 1rem;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.5rem;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: all 0.2s;
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-count {
  background: rgba(59,130,246,0.15); color: var(--primary);
  padding: 0.1rem 0.45rem; border-radius: 999px; font-size: 0.7rem;
}

/* MAIN CONTENT */
.main-content {
  flex: 1; padding: 1.5rem;
  max-width: 1400px; width: 100%; margin: 0 auto;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.45rem; font-weight: 700; }
.page-header p { font-size: 0.85rem; color: var(--text-muted); }

/* CARDS */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; font-weight: 700; }
.card-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.grid-2col {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.5rem;
}

/* QR CODE AREA */
.qr-container {
  min-height: 270px; display: flex; align-items: center; justify-content: center;
  background: #080c14; border: 1px dashed var(--border); border-radius: 12px;
  padding: 1rem; margin-bottom: 1.25rem;
}
.qr-container img {
  max-width: 250px; width: 100%; height: auto;
  border-radius: 8px; background: #fff; padding: 8px;
}
.qr-loading {
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  color: var(--text-muted); font-size: 0.85rem;
}
.spin { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.divider {
  display: flex; align-items: center; text-align: center; margin: 1.2rem 0;
  color: var(--text-muted); font-size: 0.7rem; font-weight: 600;
}
.divider::before, .divider::after {
  content: ''; flex: 1; border-bottom: 1px solid var(--border);
}
.divider span { padding: 0 0.8rem; }

.pairing-box {
  margin-top: 0.8rem; padding: 0.75rem; background: #080c14;
  border: 1px solid var(--border); border-radius: 8px; text-align: center;
}
.pairing-box strong {
  display: block; font-family: var(--font-mono);
  font-size: 1.4rem; color: #10b981; letter-spacing: 0.2em; margin-top: 0.25rem;
}

/* INFO ROWS */
.conn-info-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.65rem 0.85rem; background: #0d131f; border-radius: 8px;
  font-size: 0.85rem;
}
.info-row span { color: var(--text-muted); }

.card-callout {
  display: flex; gap: 0.85rem; padding: 1rem;
  background: rgba(59,130,246,0.06); border: 1px solid rgba(59,130,246,0.2);
  border-radius: 10px; font-size: 0.825rem; color: #bfdbfe;
}
.card-callout i { flex-shrink: 0; margin-top: 2px; }

/* FORMS & INPUTS */
.form-group { margin-bottom: 1.2rem; }
.form-group label {
  display: block; font-size: 0.825rem; font-weight: 600;
  margin-bottom: 0.4rem; color: var(--text-main);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; background: #0c121d; border: 1px solid var(--border);
  color: var(--text-main); border-radius: 8px; padding: 0.65rem 0.85rem;
  font-size: 0.875rem; font-family: inherit; transition: border 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}
.help-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; display: block; }
.input-with-icon { position: relative; }
.input-with-icon i {
  position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); width: 18px; height: 18px;
}
.input-with-icon input { padding-left: 2.5rem; }

.input-group { display: flex; gap: 0.5rem; }
.input-group input { flex: 1; }

.checkbox-group label {
  display: flex; align-items: flex-start; gap: 0.6rem;
  cursor: pointer; font-size: 0.85rem; font-weight: 500;
}
.checkbox-group input { margin-top: 3px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-size: 0.85rem; font-weight: 600; padding: 0.65rem 1.15rem;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent;
  transition: all 0.2s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #1e293b; color: var(--text-main); border-color: var(--border); }
.btn-secondary:hover { background: #283548; }
.btn-danger { background: rgba(239,68,68,0.15); color: #f87171; border-color: rgba(239,68,68,0.3); }
.btn-danger:hover { background: #ef4444; color: #fff; }
.btn-block { width: 100%; }
.btn-icon {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 6px; display: inline-flex;
}
.btn-icon:hover { color: var(--text-main); background: #1e293b; }
.btn-close {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 6px;
}
.btn-sm-text {
  background: none; border: none; color: var(--primary);
  font-size: 0.75rem; font-weight: 600; cursor: pointer; padding: 0 0.3rem;
}
.btn-sm-text:hover { text-decoration: underline; }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.725rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-success { background: rgba(16,185,129,0.15); color: #34d399; }
.badge-danger { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-warning { background: rgba(245,158,11,0.15); color: #fbbf24; }

/* TABLES */
.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; text-align: left; }
th, td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
tr:hover td { background: rgba(255,255,255,0.015); }

/* CARDS GRID FOR GATILHOS */
.cards-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1.25rem;
}
.trigger-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; display: flex;
  flex-direction: column; justify-content: space-between;
  transition: all 0.2s;
}
.trigger-card:hover { border-color: #3b82f6; transform: translateY(-2px); }
.trigger-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 0.75rem;
}
.trigger-body { font-size: 0.825rem; color: var(--text-muted); margin-bottom: 1rem; }
.trigger-keywords {
  display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem;
}
.keyword-tag {
  background: #1e293b; color: #93c5fd; padding: 0.15rem 0.5rem;
  border-radius: 4px; font-size: 0.725rem; font-family: var(--font-mono);
}
.trigger-footer {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border); padding-top: 0.75rem;
}

/* SEGMENTED CONTROL */
.segmented-control {
  display: flex; background: #0c121d; border: 1px solid var(--border);
  border-radius: 8px; padding: 3px; gap: 3px;
}
.seg-btn {
  flex: 1; background: transparent; border: none; color: var(--text-muted);
  padding: 0.55rem; font-size: 0.825rem; font-weight: 600;
  border-radius: 6px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 0.4rem; transition: all 0.2s;
}
.seg-btn.active { background: #1e293b; color: #fff; }

.group-select-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.group-checkbox-list {
  max-height: 200px; overflow-y: auto; background: #0c121d;
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.group-item-label {
  display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem;
  padding: 0.35rem 0.5rem; border-radius: 6px; cursor: pointer;
}
.group-item-label:hover { background: #1e293b; }

.delay-inputs { display: flex; align-items: center; gap: 0.5rem; }
.delay-inputs input { width: 80px; text-align: center; }

/* CONSOLE LOGS */
.console-box {
  background: #080c14; border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; height: 420px; overflow-y: auto;
  font-family: var(--font-mono); font-size: 0.775rem; color: #cbd5e1;
}
.log-line { padding: 0.25rem 0; border-bottom: 1px solid rgba(255,255,255,0.03); }
.log-time { color: var(--text-muted); margin-right: 0.5rem; }
.log-tag { font-weight: 700; margin-right: 0.5rem; }

/* MODALS */
.modal-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.75rem; width: 100%; max-width: 580px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
}
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.75rem;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.75rem;
  margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem;
}

@media (max-width: 768px) {
  .top-nav { padding: 0.75rem 1rem; }
  .main-content { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .grid-2col { grid-template-columns: 1fr; }
}
