:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --glass-grad: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* Animated Background */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.3) 0%, rgba(99, 102, 241, 0) 70%);
    filter: blur(80px);
    border-radius: 50%;
    animation: move 20s infinite alternate;
}

.blob-1 { top: -100px; left: -100px; background: rgba(99, 102, 241, 0.2); }
.blob-2 { bottom: -100px; right: -100px; background: rgba(139, 92, 246, 0.2); }

@keyframes move {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(100px, 100px) scale(1.2); }
}

.app-container {
    display: flex;
    height: 100vh;
    backdrop-filter: blur(10px);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: rgba(15, 23, 42, 0.8);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.5px;
}

.nav-menu {
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s;
    margin-bottom: 0.5rem;
}

.nav-item:hover, .nav-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-item i {
    font-size: 1.1rem;
}

.nav-item.active i {
    color: var(--primary);
}

.sidebar-footer {
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.user-info .user-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-info .user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
}

.search-bar {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 400px;
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-main);
    outline: none;
    width: 100%;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

/* Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.2rem;
}

.stat-info h3 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.stat-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Instances Grid */
.instances-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.instance-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 20px;
    position: relative;
    transition: all 0.3s;
}

.instance-card:hover {
    border-color: var(--primary);
}

.instance-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-online { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.status-offline { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.instance-name {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 4px;
    text-transform: capitalize;
}

.instance-id-row {
    display: flex;
    gap: 14px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.instance-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    width: 76px;
    height: 76px;
}

.instance-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    display: block;
}

.instance-card-clickable { cursor: pointer; }

.instance-dept-en {
    font-size: 0.9rem;
    color: #fff;
    font-weight: 500;
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

/* ---- Instance Detail page ---- */
.detail-hero {
    display: flex;
    gap: 28px;
    align-items: center;
    padding: 32px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    margin-bottom: 24px;
    position: relative;
}

.detail-actions-admin {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
}
.detail-actions-admin .action-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}
.detail-actions-admin .action-icon:hover {
    background: rgba(99, 102, 241, 0.15);
    color: #fff;
    border-color: rgba(99, 102, 241, 0.4);
}
.detail-actions-admin .action-icon.action-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

.connection-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}
.connection-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.18s;
    white-space: nowrap;
}
.connection-btn:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.35);
}
.connection-btn .conn-sub {
    opacity: 0.55;
    font-size: 0.78rem;
    font-weight: 400;
}
.connection-btn .connected-tag {
    margin-left: 4px;
    padding: 1px 7px;
    background: rgba(34, 197, 94, 0.18);
    color: #4ade80;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.connection-btn.is-primary {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.35);
    color: #c7d2fe;
}
.btn.is-connected {
    position: relative;
}
.btn.is-connected::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid rgb(30, 41, 59);
    box-sizing: content-box;
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.4);
}
.connection-btn.is-primary:hover {
    background: rgba(99, 102, 241, 0.28);
    color: #fff;
}

/* Avatar lightbox */
.avatar-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.18s ease;
}
.avatar-lightbox.active { opacity: 1; }
.avatar-lightbox img {
    max-width: 88vw;
    max-height: 88vh;
    border-radius: 50%;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
    transform: scale(0.92);
    transition: transform 0.2s ease;
    object-fit: cover;
}
.avatar-lightbox.active img { transform: scale(1); }
.avatar-lightbox-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.avatar-lightbox-close:hover { background: rgba(255, 255, 255, 0.18); }

.detail-avatar-wrap {
    position: relative;
    width: 180px;
    height: 180px;
    flex-shrink: 0;
}
.detail-avatar { cursor: zoom-in; }
.detail-avatar:hover { filter: brightness(1.05); }
.detail-avatar {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    display: block;
}
.detail-avatar-wrap .status-dot {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 4px solid rgb(30, 41, 59);
    box-sizing: border-box;
}
.detail-info { flex: 1; min-width: 0; }
.detail-name {
    font-family: Outfit, sans-serif;
    font-size: 2.4rem;
    font-weight: 700;
    margin: 0 0 4px;
    text-transform: capitalize;
    color: #fff;
}
.detail-position {
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.detail-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.detail-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 24px 28px;
    margin-bottom: 18px;
}
.detail-section h3 {
    font-family: Outfit, sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 12px;
    color: #fff;
}
.detail-section p {
    color: var(--text-muted);
    line-height: 1.7;
    margin: 0;
}
.topic-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.topic-chip {
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #c7d2fe;
    font-size: 0.85rem;
    font-weight: 500;
}
.detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.detail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 18px;
    cursor: pointer;
}
.detail-back:hover { color: var(--primary); }

.instance-avatar-wrap .status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgb(30, 41, 59);
    box-sizing: border-box;
}

.status-dot-online {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.status-dot-offline {
    background: #6b7280;
}

.instance-url {
    font-size: 0.85rem;
    color: var(--primary);
    text-decoration: none;
}

.instance-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
}

.instance-actions {
    display: flex;
    gap: 10px;
}

.action-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    transition: 0.2s;
}

.action-icon i {
    color: #fff;
}

.action-delete i {
    color: #fff;
}

.action-delete:hover i {
    color: var(--danger);
}

.action-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.instance-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.78rem;
}

.meta-chip i {
    color: var(--text-muted);
    font-size: 0.75rem;
}

a.meta-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.model-chip {
    cursor: pointer;
    padding: 3px 6px 3px 10px;
    transition: background 0.2s;
}
.model-chip:hover {
    background: rgba(99, 102, 241, 0.14);
    border-color: rgba(99, 102, 241, 0.3);
}
.model-select {
    background: transparent;
    color: var(--text-main);
    border: none;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    padding: 1px 18px 1px 0;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 2px center;
}
.model-select:disabled {
    opacity: 0.5;
    cursor: wait;
}
.model-select option {
    background: rgb(30, 41, 59);
    color: var(--text-main);
}

.action-delete:hover { color: var(--danger); }

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 5rem 2rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.3;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.active { display: flex; }

.modal-content {
    background: #1e293b;
    width: 500px;
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.domain-suffix {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

input, select {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: white;
    outline: none;
}

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

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 2rem;
}
