:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #4f46e5;
    --primary-hover: #6366f1;
    --secondary-color: #334155;
    --secondary-hover: #475569;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at top right, rgba(79, 70, 229, 0.15), transparent 40%),
        radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.1), transparent 40%);
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    min-height: 100vh;
}

body:not(.admin-active) {
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

.container {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    padding: 2.5rem;
    border-radius: 1.5rem;
    box-shadow: var(--glass-shadow);
    width: 100%;
    max-width: 420px;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1,
h2,
h3 {
    font-weight: 600;
    margin-top: 0;
    color: white;
}

h1 {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.8rem;
    letter-spacing: -0.5px;
}

.tabs {
    display: flex;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    flex: 1;
    padding: 0.75rem;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.3s ease;
    font-weight: 500;
}

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

.tab.active {
    color: var(--primary-hover);
    border-bottom: 2px solid var(--primary-hover);
    margin-bottom: -1px;
}

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

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

input,
.modern-select {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: rgba(15, 23, 42, 0.6);
    color: white;
    box-sizing: border-box;
    transition: all 0.3s ease;
    font-family: inherit;
}

input:focus,
.modern-select:focus {
    outline: none;
    border-color: var(--primary-hover);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

button {
    width: 100%;
    padding: 0.85rem;
    border-radius: 0.75rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.39);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.23);
}

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

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

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

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

.btn-danger-outline {
    background: transparent;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
}

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

.session-box {
    background: rgba(15, 23, 42, 0.8);
    padding: 1rem;
    border-radius: 0.75rem;
    word-break: break-all;
    margin: 1.5rem 0;
    text-align: center;
    border: 1px solid var(--border-color);
}

#user-session-id {
    color: var(--primary-hover);
    font-size: 0.9rem;
}

.message {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    text-align: center;
    display: none;
    border: 1px solid transparent;
    animation: fadeIn 0.3s ease-out;
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.2);
    display: block;
}

.message.success {
    background: rgba(16, 185, 129, 0.1);
    color: #86efac;
    border-color: rgba(16, 185, 129, 0.2);
    display: block;
}

/* Admin Dashboard Layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 260px;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 2.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-links {
    list-style: none;
    padding: 1.5rem 0;
    margin: 0;
    flex: 1;
}

.nav-links li a {
    display: flex;
    align-items: center;
    padding: 1rem 2rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 1.05rem;
}

.nav-links li a:hover,
.nav-links li.active a {
    color: white;
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--primary-color);
}

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

.main-content {
    flex: 1;
    padding: 3rem 4rem;
    overflow-y: auto;
}

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

/* Modern Table */
.table-container {
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(12px);
}

.modern-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.modern-table th,
.modern-table td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modern-table th {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modern-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.modern-table tr:last-child td {
    border-bottom: none;
}

.badge {
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
    text-transform: capitalize;
}

.badge.admin {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge.user {
    background: rgba(79, 70, 229, 0.2);
    color: #818cf8;
    border: 1px solid rgba(79, 70, 229, 0.3);
}

.action-btn {
    width: auto;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    margin: 0 0.25rem;
    border-radius: 0.5rem;
}

/* AI / Cluster Button */
.btn-ai {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: #fff;
    border: none;
    padding: 0.65rem 1.25rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
}

.btn-ai:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px rgba(124, 58, 237, 0.5);
}

.btn-ai:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Cluster banner */
.cluster-banner-running {
    background: rgba(79, 70, 229, 0.12);
    border: 1px solid rgba(79, 70, 229, 0.35);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #a5b4fc;
    font-size: 0.92rem;
    margin-bottom: 1.25rem;
    animation: pulse-glow 1.8s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(79, 70, 229, 0.2);
    }

    50% {
        box-shadow: 0 0 20px rgba(79, 70, 229, 0.45);
    }
}

.cluster-banner-done {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    color: #6ee7b7;
    font-size: 0.92rem;
    margin-bottom: 1.25rem;
}

.cluster-banner-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    color: #fca5a5;
    font-size: 0.92rem;
    margin-bottom: 1.25rem;
}

/* Cluster cards grid */
.cluster-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.cluster-card {
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    border: 1px solid transparent;
    position: relative;
    transition: box-shadow 0.2s;
}

.cluster-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cluster-card-title {
    font-weight: 700;
    font-size: 1rem;
}

.cluster-card-count {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.25);
    color: rgba(255, 255, 255, 0.7);
}

.cluster-expand-btn {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.78rem;
    padding: 0.3rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.18s;
    font-weight: 500;
}

.cluster-expand-btn:hover {
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
}

/* Product thumbnail grid inside each cluster */
.product-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.product-thumb {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 0.65rem;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s;
    border: 1px solid rgba(255, 255, 255, 0.07);
    position: relative;
}

.product-thumb:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.product-thumb img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
}

.product-thumb-placeholder {
    width: 100%;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    background: rgba(255, 255, 255, 0.04);
}

.product-thumb-name {
    padding: 0.4rem 0.45rem 0.5rem;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.3;
    word-break: break-word;
}

/* 12 distinct cluster colour themes */
.cc-0 {
    background: rgba(79, 70, 229, 0.15);
    border-color: rgba(79, 70, 229, 0.35);
}

.cc-0 .cluster-card-title {
    color: #a5b4fc;
}

.cc-1 {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
}

.cc-1 .cluster-card-title {
    color: #6ee7b7;
}

.cc-2 {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
}

.cc-2 .cluster-card-title {
    color: #fcd34d;
}

.cc-3 {
    background: rgba(236, 72, 153, 0.12);
    border-color: rgba(236, 72, 153, 0.35);
}

.cc-3 .cluster-card-title {
    color: #f9a8d4;
}

.cc-4 {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.35);
}

.cc-4 .cluster-card-title {
    color: #93c5fd;
}

.cc-5 {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
}

.cc-5 .cluster-card-title {
    color: #fca5a5;
}

.cc-6 {
    background: rgba(20, 184, 166, 0.12);
    border-color: rgba(20, 184, 166, 0.35);
}

.cc-6 .cluster-card-title {
    color: #5eead4;
}

.cc-7 {
    background: rgba(168, 85, 247, 0.12);
    border-color: rgba(168, 85, 247, 0.35);
}

.cc-7 .cluster-card-title {
    color: #d8b4fe;
}

.cc-8 {
    background: rgba(251, 146, 60, 0.12);
    border-color: rgba(251, 146, 60, 0.35);
}

.cc-8 .cluster-card-title {
    color: #fed7aa;
}

.cc-9 {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.35);
}

.cc-9 .cluster-card-title {
    color: #86efac;
}

.cc-10 {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.35);
}

.cc-10 .cluster-card-title {
    color: #c7d2fe;
}

.cc-11 {
    background: rgba(244, 63, 94, 0.12);
    border-color: rgba(244, 63, 94, 0.35);
}

.cc-11 .cluster-card-title {
    color: #fda4af;
}

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

.modal-content {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 2.5rem;
    border-radius: 1.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    margin-top: 0;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-actions button {
    margin: 0;
}

/* ── Product Description Drawer ───────────────────────────────────────── */
.product-drawer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    justify-content: flex-end;
    animation: fadeIn 0.2s ease;
}

.product-drawer-content {
    background: #0f172a;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 520px;
    height: 100%;
    overflow-y: auto;
    padding: 2rem 2rem 3rem;
    position: relative;
    animation: slideInRight 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.drawer-close {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.drawer-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

.drawer-product-header {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    margin-bottom: 1.75rem;
    padding-right: 2.5rem;
}

.drawer-img {
    width: 90px;
    height: 90px;
    border-radius: 0.75rem;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.drawer-name {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.4;
    margin: 0;
    color: var(--text-color);
}

.drawer-meta {
    font-size: 0.78rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.07);
    color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.drawer-section {
    margin-bottom: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    padding-top: 1.25rem;
}

.drawer-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}

.drawer-desc {
    font-size: 0.9rem;
    line-height: 1.75;
    color: rgba(255, 255, 255, 0.82);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Clickable product row */
.product-row-clickable {
    cursor: pointer;
    transition: background 0.15s;
}

.product-row-clickable:hover td {
    background: rgba(79, 70, 229, 0.08) !important;
}