/* ============================================================
   ViViDly Admin Dashboard — Complete Dark Theme
   ============================================================ */

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #161618;
    --bg-card: #1a1a1e;
    --bg-card-hover: #212126;
    --bg-input: #111113;
    --bg-sidebar: #111113;
    --bg-badge: rgba(124, 58, 237, 0.12);
    --primary: #7C3AED;
    --primary-glow: rgba(124, 58, 237, 0.35);
    --primary-light: #a78bfa;
    --primary-dark: #5b21b6;
    --secondary: #3b82f6;
    --accent: #f59e0b;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);
    --text-primary: #f0f0f5;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   LOGIN GATE
   ============================================================ */
.gate-overlay {
    position: fixed;
    inset: 0;
    background: #0a0a0f;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-card {
    background: #1a1a2e;
    padding: 48px;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid rgba(124, 58, 237, 0.3);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
}

.login-card img.login-logo {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    margin-bottom: 24px;
    object-fit: cover;
}

.login-title {
    color: white;
    font-weight: 700;
    font-size: 2.2rem;
    margin-bottom: 2px;
    letter-spacing: -1px;
}

.login-h2 {
    color: #7C3AED;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.login-card .login-subtitle {
    color: #9ca3af;
    margin-bottom: 32px;
    font-size: 0.9rem;
    font-weight: 400;
}

.login-btn-google {
    background: linear-gradient(135deg, #7C3AED, #4F46E5);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-btn-google:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(124, 58, 237, 0.4);
    filter: brightness(1.1);
}

.access-denied-card {
    max-width: 480px;
}

.access-denied-card .denied-icon {
    font-size: 56px;
    color: var(--danger);
    margin-bottom: 16px;
}

.access-denied-card p.denied-msg {
    color: var(--text-secondary);
    margin: 12px 0 28px 0;
    line-height: 1.6;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.admin-shell {
    display: flex;
    height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    gap: 8px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
    margin-bottom: 32px;
}

.brand-logo {
    width: 36px;
    height: 36px;
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 4px;
}

.brand h2 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

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

.nav-group-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 16px 12px 6px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 16px var(--primary-glow);
}

.nav-item .material-icons-outlined {
    font-size: 20px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.02);
}

.admin-info img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.admin-info .admin-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.admin-info .admin-email {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* --- Main Content --- */
.main-view {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background: var(--bg-primary);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.page-header .header-meta {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color var(--transition);
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* --- Stat Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-card .stat-icon.purple {
    background: var(--bg-badge);
    color: var(--primary);
}

.stat-card .stat-icon.green {
    background: var(--success-bg);
    color: var(--success);
}

.stat-card .stat-icon.blue {
    background: var(--info-bg);
    color: var(--info);
}

.stat-card .stat-icon.amber {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-card .stat-change.up {
    color: var(--success);
}

.stat-card .stat-change.down {
    color: var(--danger);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    box-sizing: border-box;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hover);
}

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

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

.btn-success {
    background: var(--success-bg);
    color: var(--success);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
select,
textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    width: 100%;
    transition: all var(--transition);
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    display: inline-block;
}

.toggle input {
    display: none;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    cursor: pointer;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    top: 3px;
    left: 3px;
    transition: all var(--transition);
}

.toggle input:checked+.toggle-slider {
    background: var(--primary);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(18px);
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

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

/* User cell */
.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-badge);
}

.user-avatar-placeholder {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-badge);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
}

.user-cell .user-name {
    font-weight: 600;
    font-size: 0.88rem;
}

.user-cell .user-email {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.badge-purple {
    background: var(--bg-badge);
    color: var(--primary-light);
}

.badge-neutral {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

/* ============================================================
   GRID LAYOUTS
   ============================================================ */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.grid-1-1-1 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

/* ============================================================
   TAB CONTENT
   ============================================================ */
.tab-content {
    display: none;
    animation: fadeSlideIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar .search-input {
    flex: 1;
    min-width: 200px;
    max-width: 320px;
    position: relative;
}

.toolbar .search-input input {
    padding-left: 38px;
}

.toolbar .search-input .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
    pointer-events: none;
}

.toolbar select.filter-select,
select.filter-select {
    min-width: 140px;
    width: auto !important;
    flex-shrink: 0;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

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

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

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

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

/* ============================================================
   USER DETAIL PANEL
   ============================================================ */
.detail-panel {
    position: fixed;
    top: 0;
    right: -500px;
    width: 480px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 500;
    overflow-y: auto;
    transition: right 0.3s ease;
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.3);
    padding: 32px;
}

.detail-panel.open {
    right: 0;
}

.detail-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.detail-profile {
    text-align: center;
    padding: 20px 0 28px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.detail-profile img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 12px;
    border: 3px solid var(--primary);
}

.detail-profile h3 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

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

.detail-rows {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.detail-row .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.detail-row .value {
    font-size: 0.88rem;
    font-weight: 500;
    text-align: right;
}

.detail-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 28px;
}

/* ============================================================
   INFRA MODULE
   ============================================================ */
.key-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.key-card .key-info .key-name {
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 4px;
}

.key-card .key-info .key-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.info-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
}

.info-item .info-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.info-item .info-value {
    font-weight: 600;
    font-size: 0.95rem;
}

/* ============================================================
   TOAST
   ============================================================ */
#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 14px 22px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 10000;
    font-size: 0.88rem;
    font-weight: 500;
    animation: toastIn 0.3s ease;
    max-width: 400px;
}

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

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

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

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

/* ============================================================
   PERMISSIONS TABLE
   ============================================================ */
.perm-grid {
    display: flex;
    align-items: center;
    gap: 16px;
}

.perm-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.perm-save-btn {
    opacity: 0;
    transition: opacity var(--transition);
}

tr:hover .perm-save-btn {
    opacity: 1;
}

/* ============================================================
   CHARTS
   ============================================================ */
.chart-container {
    position: relative;
    height: 280px;
    margin-top: 12px;
}

/* ============================================================
   RECENT LIST
   ============================================================ */
.recent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.recent-item:last-child {
    border-bottom: none;
}

.recent-item .recent-info {
    flex: 1;
}

.recent-item .recent-name {
    font-weight: 600;
    font-size: 0.88rem;
}

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

.recent-item .recent-badge {
    margin-left: auto;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state .material-icons-outlined {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ============================================================
   LOADING
   ============================================================ */
.loading-row td {
    text-align: center;
    padding: 32px !important;
    color: var(--text-muted);
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2-1 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-view {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}