:root {
    --sidebar-width: 250px;
    --sidebar-bg: #000;
    --sidebar-active: #1A1A1A;
    --sidebar-hover: #1A1A1A;
    --sidebar-text: #999;
    --sidebar-text-active: #F2F2F2;
    --content-bg: #F2F2F2;
    --primary: #1A1A1A;
    --primary-hover: #333333;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--content-bg);
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #1A1A1A;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.sidebar-brand h5 {
    color: #FFF;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}

.sidebar-brand .brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.875rem;
}

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

.sidebar-nav .nav-item {
    margin: 2px 0.75rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.sidebar-nav .nav-link:hover {
    color: var(--sidebar-text-active);
    background: var(--sidebar-hover);
}

.sidebar-nav .nav-link.active {
    color: var(--sidebar-text-active);
    background: var(--sidebar-active);
}

.sidebar-nav .nav-link i {
    font-size: 1.125rem;
    width: 1.25rem;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #1A1A1A;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--sidebar-text);
    font-size: 0.8125rem;
}

.sidebar-user .user-avatar {
    width: 32px;
    height: 32px;
    background: #333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    overflow: hidden;
    flex: 1;
}

.sidebar-user .user-name {
    color: #E6E6E6;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    font-size: 0.6875rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #E6E6E6;
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar h1 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #000;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.content-area {
    padding: 1.5rem;
}

.card {
    border: 1px solid #E6E6E6;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #E6E6E6;
    padding: 1rem 1.25rem;
}

.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    border-bottom-width: 1px;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    font-size: 0.875rem;
    color: #333;
    border-bottom: 1px solid #F2F2F2;
}

.table tbody tr:hover {
    background: #F2F2F2;
}

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

.search-box {
    position: relative;
    max-width: 320px;
}

.search-box .form-control {
    padding-left: 2.5rem;
    border-color: #E6E6E6;
    border-radius: 6px;
    font-size: 0.875rem;
    height: 38px;
}

.search-box .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.search-box .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 0.875rem;
    pointer-events: none;
}

.users-search {
    max-width: 400px;
}

.users-search .input-group-text {
    background: #fff;
    border-color: #E6E6E6;
    color: #999;
    font-size: 0.875rem;
}

.users-search .form-control {
    border-color: #E6E6E6;
    font-size: 0.875rem;
    height: 38px;
}

.users-search .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.users-search .btn {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0 1rem;
}

.users-filters {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
}

.users-filters .form-select {
    width: auto;
    min-width: 140px;
    font-size: 0.8125rem;
    border-color: #E6E6E6;
    color: #333;
    height: 34px;
    padding-top: 0;
    padding-bottom: 0;
}

.users-filters .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.badge-role {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-superadmin {
    background: #fef3c7;
    color: #92400e;
}

.badge-admin {
    background: #dbeafe;
    color: #1e40af;
}

.badge-editor {
    background: #d1fae5;
    color: #065f46;
}

.badge-status {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-trialing { background: #dbeafe; color: #1e40af; }
.badge-canceled { background: #fee2e2; color: #991b1b; }
.badge-pastdue { background: #fef3c7; color: #92400e; }
.badge-none { background: #F2F2F2; color: #666; }

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

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

.pagination .page-link {
    color: var(--primary);
    font-size: 0.875rem;
    border-color: #E6E6E6;
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--content-bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid #E6E6E6;
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-brand .brand-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

.login-brand h4 {
    font-weight: 600;
    color: #000;
    margin-bottom: 0.25rem;
}

.login-brand p {
    color: #666;
    font-size: 0.875rem;
    margin: 0;
}

.login-card .form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: #333;
}

.login-card .form-control {
    border-color: #E6E6E6;
    border-radius: 6px;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
}

.login-card .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.625rem;
    font-weight: 500;
}

.stat-card {
    background: #fff;
    border: 1px solid #E6E6E6;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: #666;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #000;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.empty-state i {
    font-size: 2.5rem;
    color: #CCC;
    margin-bottom: 0.75rem;
}

.empty-state p {
    font-size: 0.9375rem;
    margin: 0;
}

.alert {
    border-radius: 6px;
    font-size: 0.875rem;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #333;
    padding: 0.25rem;
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1035;
    }

    .sidebar-overlay.open {
        display: block;
    }
}

/* ── Library ─────────────────────────────────────────── */

.library-header {
    margin-bottom: 1rem;
}

.library-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
}

.library-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.library-email-search {
    max-width: 440px;
}

.library-email-search .input-group-text {
    background: #fff;
    border-color: #E6E6E6;
    color: #999;
    font-size: 0.875rem;
}

.library-email-search .form-control {
    border-color: #E6E6E6;
    font-size: 0.875rem;
    height: 38px;
}

.library-email-search .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.library-email-search .btn {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0 1rem;
}

.library-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.library-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid #E6E6E6;
    border-radius: 9999px;
    background: #fff;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.library-pill:hover {
    border-color: #CCC;
    color: #333;
}

.library-pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.library-pill--dropdown i {
    font-size: 0.625rem;
    transition: transform 0.15s ease;
}

.library-pill-dropdown {
    position: relative;
}

.library-pill-popover {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 100;
    min-width: 180px;
    max-height: 280px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #E6E6E6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 0.25rem 0;
}

.library-pill-popover.show {
    display: block;
}

.library-pill-popover__title {
    padding: 0.5rem 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #999;
}

.library-pill-popover__item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    text-align: left;
    border: none;
    background: none;
    color: #333;
    cursor: pointer;
}

.library-pill-popover__item:hover {
    background: #F2F2F2;
}

.library-pill-popover__item:last-child:hover {
    border-radius: 0 0 8px 8px;
}

.library-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.library-toolbar .form-select {
    width: auto;
    min-width: 140px;
    font-size: 0.8125rem;
    border-color: #E6E6E6;
    height: 34px;
    padding-top: 0;
    padding-bottom: 0;
}

.library-toolbar .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.library-size-slider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #999;
    font-size: 0.875rem;
}

.library-size-slider input[type="range"] {
    width: 100px;
    accent-color: var(--primary);
    cursor: pointer;
}

.library-content {
    min-height: 200px;
}

.library-grid {
    --lib-cols: 4;
}

.lib-day-group {
    margin-bottom: 1rem;
}

.lib-day-header {
    padding: 0.5rem 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #999;
}

.lib-day-grid {
    display: grid;
    grid-template-columns: repeat(var(--lib-cols, 4), 1fr);
    gap: 8px;
}

.lib-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    background: #E6E6E6;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.lib-card:hover {
    opacity: 0.85;
}

.lib-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lib-card img.loaded {
    opacity: 1;
}

.lib-card__placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #CCC;
    font-size: 1.5rem;
}

.lib-card__play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    pointer-events: none;
}

.lib-card__email {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px 6px;
    font-size: 0.625rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.lib-card:hover .lib-card__email {
    opacity: 1;
}

.lib-card__failed {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 1px 6px;
    font-size: 0.625rem;
    font-weight: 600;
    color: #fff;
    background: #ef4444;
    border-radius: 4px;
}

.library-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
}

.library-empty p {
    margin: 0.5rem 0 0;
    font-size: 0.9375rem;
}

.library-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    font-size: 0.875rem;
}

/* ── Library Popup ───────────────────────────────────── */

.library-popup {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.library-popup__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    cursor: pointer;
}

.library-popup__dialog {
    position: relative;
    display: flex;
    width: 90vw;
    max-width: 1000px;
    height: 80vh;
    max-height: 700px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.library-popup__close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.library-popup__close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.library-popup__media {
    flex: 1;
    min-width: 0;
    background: #1A1A1A;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.library-popup__sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 1.25rem;
    overflow-y: auto;
    border-left: 1px solid #E6E6E6;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.popup-type {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #999;
}

.popup-email {
    font-size: 0.8125rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.popup-email i {
    color: #999;
}

.popup-inputs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.popup-inputs img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #E6E6E6;
}

.popup-prompt {
    font-size: 0.8125rem;
    color: #4D4D4D;
    line-height: 1.5;
    word-break: break-word;
}

.popup-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.popup-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 2px 8px;
    background: #F2F2F2;
    border-radius: 4px;
    color: #666;
}

.popup-date {
    font-size: 0.75rem;
    color: #999;
}

.popup-actions {
    display: flex;
    gap: 6px;
    margin-top: auto;
    padding-top: 0.5rem;
}

.popup-action-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #E6E6E6;
    border-radius: 8px;
    background: #fff;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: none;
    transition: all 0.15s ease;
}

.popup-action-btn:hover {
    border-color: #CCC;
    color: #333;
}

.popup-video-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}

.popup-video-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.popup-video-wrap video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.popup-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.popup-media-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #fff;
}

/* ── User Detail ─────────────────────────────────────── */

.user-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.user-detail-title h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.user-detail-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
}

.user-detail-tabs {
    border-bottom-color: #E6E6E6;
}

.user-detail-tabs .nav-link {
    font-size: 0.875rem;
    font-weight: 500;
    color: #666;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.625rem 1rem;
    border-radius: 0;
}

.user-detail-tabs .nav-link:hover {
    color: #333;
    border-bottom-color: #CCC;
}

.user-detail-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: none;
}

.user-detail-content {
    background: none;
}

.detail-table {
    margin: 0;
}

.detail-table td {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid #F2F2F2;
}

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

.detail-label {
    font-weight: 500;
    color: #666;
    width: 140px;
    white-space: nowrap;
}

.stripe-link {
    color: #635bff;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
}

.stripe-link:hover {
    color: #4b44c9;
    text-decoration: underline;
}

.stat-detail {
    font-size: 0.75rem;
    color: #999;
    margin-top: 0.25rem;
}

.ledger-filters {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.ledger-filters .form-control {
    width: auto;
    min-width: 150px;
    font-size: 0.8125rem;
    border-color: #E6E6E6;
    height: 34px;
}

.ledger-filters .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

@media (max-width: 768px) {
    .user-detail-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .user-detail-meta {
        flex-wrap: wrap;
    }

    .ledger-filters {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .library-popup__dialog {
        flex-direction: column;
        width: 95vw;
        height: 90vh;
    }

    .library-popup__media {
        height: 50%;
    }

    .library-popup__sidebar {
        width: 100%;
        height: 50%;
        border-left: none;
        border-top: 1px solid #E6E6E6;
    }

    .lib-day-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .library-size-slider {
        display: none;
    }

    .library-pills {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .library-pills::-webkit-scrollbar {
        display: none;
    }
}
