:root {
    --bg-main: #0b141a;
    --bg-card: #111b21;
    --bg-card-hover: #182229;
    --bg-input: #202c33;
    --primary: #00a884;
    --primary-hover: #06cf9c;
    --primary-dim: rgba(0, 168, 132, 0.15);
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --text-main: #e9edef;
    --text-muted: #8696a0;
    --border: #222e35;
    --border-light: rgba(255, 255, 255, 0.08);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    text-decoration: none;
}

.brand span {
    color: var(--primary);
}

.brand-badge {
    background: var(--primary-dim);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid rgba(0, 168, 132, 0.3);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-tag {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Main Layout */
.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
    flex: 1;
}

/* Navigation Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Card Components */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 868px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
}

.badge-ready, .badge-success {
    background: rgba(0, 168, 132, 0.15);
    color: var(--primary);
    border: 1px solid rgba(0, 168, 132, 0.3);
}

.badge-qr, .badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

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

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    animation: pulse 2s infinite;
}

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

/* QR Code Box */
.qr-container {
    text-align: center;
    padding: 1.5rem 0;
}

.qr-box {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    display: inline-block;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.qr-box svg {
    display: block;
    width: 240px;
    height: 240px;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.2rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

input, select, textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

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

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

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.token-box {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.token-box input {
    font-family: monospace;
    letter-spacing: 0.5px;
}

/* Code Blocks */
pre, code {
    font-family: 'Fira Code', Consolas, Monaco, monospace;
    font-size: 0.85rem;
}

pre {
    background: #060b0e;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    color: #34d399;
}

/* Table */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
}

/* Auth Pages */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 1.6rem;
    color: var(--text-main);
    margin-bottom: 0.4rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Animaciones y Efectos de Conexión */
.device-card {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.device-card.card-connected-highlight {
    border-color: var(--primary) !important;
    box-shadow: 0 0 25px rgba(0, 168, 132, 0.45) !important;
    animation: pulseBorder 2s infinite alternate;
}

@keyframes pulseBorder {
    0% {
        box-shadow: 0 0 10px rgba(0, 168, 132, 0.3);
    }
    100% {
        box-shadow: 0 0 30px rgba(0, 168, 132, 0.7);
    }
}

/* Botón Comprobar Conexión */
.btn-check-conn {
    background: linear-gradient(135deg, #00a884 0%, #059669 100%) !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(0, 168, 132, 0.35);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-check-conn:hover {
    background: linear-gradient(135deg, #06cf9c 0%, #10b981 100%) !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 168, 132, 0.5);
}

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

/* Celebratory Overlay */
.connection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(11, 20, 26, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    animation: fadeInOverlay 0.35s ease forwards;
}

@keyframes fadeInOverlay {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.success-icon-wrap {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: rgba(0, 168, 132, 0.18);
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    position: relative;
    animation: bounceSuccess 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceSuccess {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); }
}

.success-icon-wrap::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--primary);
    animation: ripple 1.5s infinite ease-out;
}

@keyframes ripple {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.6); opacity: 0; }
}

.success-check-svg {
    width: 40px;
    height: 40px;
    color: var(--primary);
    stroke-width: 3;
}

/* Toast flotante */
.app-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
}

.app-toast {
    pointer-events: auto;
    background: #182229;
    color: #e9edef;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 0.9rem 1.2rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 280px;
    max-width: 420px;
    animation: slideInRight 0.3s ease;
    transition: all 0.3s ease;
}

.app-toast.toast-warning {
    border-left-color: var(--warning);
}

.app-toast.toast-danger {
    border-left-color: var(--danger);
}

.app-toast.toast-success {
    border-left-color: var(--primary);
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Metric Cards & Admin Storage */
.metric-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background: var(--bg-card);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.modal-overlay {
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

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

/* ============================================================
   API PLAYGROUND MODERN STYLES
   ============================================================ */
.playground-topbar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.playground-device-picker {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.playground-device-picker select {
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    outline: none;
    min-width: 260px;
    transition: border-color 0.2s;
}

.playground-device-picker select:focus {
    border-color: var(--primary);
}

.playground-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    overflow-x: auto;
    padding-bottom: 4px;
}

.pg-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.55rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.pg-nav-btn:hover {
    color: var(--text-main);
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.pg-nav-btn.active {
    background: rgba(0, 168, 132, 0.12);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 12px rgba(0, 168, 132, 0.15);
}

.method-tag {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.method-tag.post {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.method-tag.get {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.4);
}

.playground-grid {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 992px) {
    .playground-grid {
        grid-template-columns: 1fr;
    }
}

.endpoint-banner {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.2rem;
    font-family: monospace;
    font-size: 0.88rem;
    color: #cbd5e1;
    overflow-x: auto;
}

.endpoint-banner code {
    color: #38bdf8;
    background: transparent;
    font-weight: 600;
}

.playground-console-card {
    position: sticky;
    top: 75px;
    background: #080d11;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.console-header {
    background: #10171d;
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.console-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.console-badges {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-pill {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.status-pill.ready { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.status-pill.error { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.status-pill.idle { background: rgba(255, 255, 255, 0.05); color: var(--text-muted); border: 1px solid var(--border); }

.console-body pre {
    background: #060a0d;
    color: #e2e8f0;
    padding: 1rem;
    margin: 0;
    font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    max-height: 380px;
    min-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.console-footer {
    background: #0d1419;
    border-top: 1px solid var(--border);
    padding: 0.6rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.curl-box-preview {
    margin-top: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}

.curl-box-preview summary {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.curl-box-preview pre {
    margin-top: 0.6rem;
    margin-bottom: 0;
    padding: 0.75rem;
    background: #060a0d;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.78rem;
    color: #94a3b8;
    overflow-x: auto;
}

/* ========================================================
   WEBHOOK LOGS - DESGLOSAR / ACURRUCAR (EXPANDABLE ROWS)
   ======================================================== */
.webhooks-log-table tr.webhook-main-row {
    cursor: pointer;
    transition: background 0.15s ease;
}

.webhooks-log-table tr.webhook-main-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.webhooks-log-table tr.webhook-main-row.is-expanded {
    background: rgba(0, 168, 132, 0.08);
    border-bottom: none;
}

.webhook-toggle-icon {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.is-expanded .webhook-toggle-icon {
    transform: rotate(90deg);
    color: var(--primary);
}

.webhook-detail-row {
    transition: all 0.2s ease;
}

.webhook-detail-row td {
    padding: 0 !important;
    background: #090e12;
    border-bottom: 1px solid var(--border);
}

.webhook-detail-box {
    background: #060a0d;
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    margin: 0.4rem 0.6rem 0.8rem 0.6rem;
    padding: 0.85rem 1rem;
    position: relative;
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
}

.webhook-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.webhook-json-content {
    background: #0a0f14;
    border: 1px solid #1a242d;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-family: 'Consolas', 'Menlo', 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #38bdf8;
    max-height: 320px;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.btn-copy-json {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    background: #182229;
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

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


