/* ================== Discord-Style Dark Theme Admin Panel ================== */

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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-chat: #0d1117;
    --accent: #ffc107;
    --accent-hover: #ffca28;
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #6b7280;
    --border: #2d3748;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --online: #22c55e;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ================== Mobile Header ================== */
#mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    gap: 12px;
}

#mobile-header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

#mobile-header button {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

#mobile-header button:hover {
    background: var(--bg-tertiary);
}

.header-actions {
    display: flex;
    gap: 4px;
}

#notif-btn {
    position: relative;
}

#notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    background: var(--danger);
    border-radius: 8px;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
}

#notif-badge:not(:empty) {
    display: flex;
}

/* ================== App Container ================== */
#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ================== Sidebar ================== */
#sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-top {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 18px;
    font-weight: 700;
}

#logout-btn {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

#logout-btn:hover {
    background: var(--danger);
    color: white;
}

.search-box {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-primary);
    margin: 12px;
    border-radius: var(--radius-sm);
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    width: 100%;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ================== Tabs ================== */
#user-tabs {
    display: flex;
    padding: 0 12px 12px;
    gap: 6px;
}

#user-tabs .tab {
    flex: 1;
    background: var(--bg-primary);
    border: none;
    color: var(--text-secondary);
    padding: 10px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

#user-tabs .tab:hover {
    background: var(--bg-tertiary);
}

#user-tabs .tab.active {
    background: var(--accent);
    color: var(--bg-primary);
}

/* ================== User List ================== */
#user-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.user-item {
    padding: 14px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.user-item:hover {
    background: var(--bg-tertiary);
}

.user-item.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
}

.user-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.user-id {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: var(--online);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.order-badge {
    background: var(--accent);
    color: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

.user-email {
    font-size: 12px;
    color: var(--accent);
    margin-top: 2px;
}

.verify-badge {
    margin-right: 4px;
}

.verify-badge.verified {
    color: var(--success);
}

.verify-badge.pending {
    color: var(--warning);
}

.user-location {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.user-time {
    font-size: 11px;
    color: var(--text-muted);
}

.last-message {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 230px;
}

.unread-count {
    background: var(--accent);
    color: var(--bg-primary);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

/* ================== Chat Area ================== */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    overflow: hidden;
}

/* ================== Chat View Container ================== */
#chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

#chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

#chat-header.hidden {
    display: none;
}

#chat-header .back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
}

.user-info {
    flex: 1;
}

.user-info h2 {
    font-size: 16px;
    font-weight: 600;
}

.user-info span {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-actions button {
    background: var(--bg-tertiary);
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.chat-actions button:hover {
    background: var(--border);
}

/* ================== Messages ================== */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
}

.empty-state span {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.message {
    margin-bottom: 20px;
    /* Increased for better separation */
    display: flex;
    flex-direction: column;
    width: 100%;
}

.message.user {
    align-items: flex-start;
}

.message.admin {
    align-items: flex-end;
}

.message-bubble {
    padding: 10px 14px;
    /* Slightly more padding */
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    /* Better readability */
    word-wrap: break-word;
    white-space: normal;
    max-width: 75%;
    /* Reduced to prevent extreme stretching */
    min-width: 60px;
    height: auto !important;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.message-text {
    display: block;
    word-break: break-word;
    color: inherit !important;
    /* Force inherit from parent bubble */
    font-size: inherit;
    line-height: inherit;
}

.message.user .message-bubble {
    background: var(--bg-secondary);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
    /* White text on dark background */
}

.message.user .message-bubble .message-text {
    color: var(--text-primary) !important;
    /* Explicit white text */
}

.message.admin .message-bubble {
    background: var(--accent);
    color: #1a1a2e;
    /* Dark text on yellow background */
    border-bottom-right-radius: 4px;
}

.message.admin .message-bubble .message-text {
    color: #1a1a2e !important;
    /* Explicit dark text on yellow */
}

/* ✅ Message Reply Bubble in Admin Panel */
.message-reply-bubble {
    background: rgba(0, 0, 0, 0.1);
    border-left: 3px solid var(--accent);
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 12px;
    opacity: 0.9;
    color: inherit;
}

.message.user .message-reply-bubble {
    border-left-color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
    text-align: right;
    clear: both;
}

.message.admin .message-time {
    color: rgba(0, 0, 0, 0.5);
}

/* ================== Typing Indicator ================== */
#typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

#typing-indicator.hidden {
    display: none;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ================== Input Area ================== */
#input-area {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

#input-area.hidden {
    display: none;
}

#message-input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
}

#message-input:focus {
    border-color: var(--accent);
}

#send-btn {
    background: var(--accent);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

#send-btn svg {
    color: var(--bg-primary);
}

/* ================== Thread List View ================== */
#thread-list-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

#thread-list-view.hidden {
    display: none;
}

.thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.thread-header .back-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
}

.thread-header h2 {
    font-size: 16px;
}

.thread-header span {
    font-size: 12px;
    color: var(--text-muted);
}

#thread-list {
    flex: 1;
    overflow-y: auto;
}

.thread-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
}

.thread-item:hover {
    background: var(--bg-tertiary);
}

.thread-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.thread-icon.order {
    background: linear-gradient(135deg, var(--accent) 0%, #ff9800 100%);
}

.thread-details {
    flex: 1;
}

.thread-name {
    font-weight: 600;
    font-size: 15px;
    display: block;
}

.thread-preview {
    font-size: 13px;
    color: var(--text-muted);
}

.unverified-thread-badge {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 6px;
    vertical-align: middle;
}

/* ================== Notification Panel ================== */
#notification-panel {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#notification-panel header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#notification-panel header h3 {
    font-size: 15px;
}

#notification-panel header button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

#notification-panel header button:hover {
    color: var(--text-primary);
}

#notification-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.notification-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.notification-item:hover {
    background: var(--border);
}

.notification-item.success {
    border-left: 3px solid var(--success);
}

.notification-item.warning {
    border-left: 3px solid var(--warning);
}

.notification-message {
    font-size: 13px;
    line-height: 1.4;
}

.notification-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
}

.empty-notif {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-notif span {
    font-size: 36px;
    display: block;
    margin-bottom: 12px;
}

/* ================== Overlay ================== */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    display: none;
}

#overlay.show {
    display: block;
}

/* ================== Mobile Responsive ================== */
@media (max-width: 1024px) {
    #notification-panel {
        position: fixed;
        right: -300px;
        top: 0;
        height: 100%;
        z-index: 95;
        transition: right 0.3s ease;
    }

    #notification-panel.open {
        right: 0;
    }
}

@media (max-width: 768px) {
    #mobile-header {
        display: flex;
    }

    #app {
        padding-top: 56px;
    }

    #sidebar {
        position: fixed;
        left: -320px;
        top: 56px;
        height: calc(100% - 56px);
        z-index: 95;
        transition: left 0.3s ease;
    }

    #sidebar.open {
        left: 0;
    }

    #sidebar .sidebar-top {
        display: none;
    }

    #chat-header .back-btn {
        display: block;
    }

    .message {
        max-width: 85%;
    }

    #notification-panel {
        width: 100%;
        right: -100%;
    }
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ================== Safe Area for iOS ================== */
@supports (padding: max(0px)) {
    #input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    #mobile-header {
        padding-top: env(safe-area-inset-top);
        height: calc(56px + env(safe-area-inset-top));
    }
}

/* ================== Thread Delete Button ================== */
.thread-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
    opacity: 0.5;
    transition: all 0.15s;
}

.thread-item:hover .thread-delete-btn {
    opacity: 1;
}

.thread-delete-btn:hover {
    background: var(--danger);
    opacity: 1;
}

/* Loading spinner animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}