/* ═══════════════════════════════════════════════════════════════════════════
   HelpDeck PWA 3.0 — Dashboard Layout (Card / Cloud Style)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Main Layout ── */
.dashboard-layout {
    display: flex;
    width: 100%;
    height: 100%;
    background: transparent;
    gap: 0;
}

/* ══════════ SIDEBAR ══════════ */
.sidebar {
    width: 340px;
    min-width: 340px;
    height: 100%;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* ── Sidebar Header ── */
.sidebar-header {
    padding: calc(16px + var(--safe-top)) 16px 12px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

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

.avatar-circle {
    width: 44px; height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
    color: white;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.avatar-circle.sm {
    width: 38px; height: 38px;
    font-size: 15px;
    border-radius: 12px;
}

.avatar-circle img,
img.avatar-circle {
    object-fit: cover;
    border-radius: inherit;
}

.online-dot {
    position: absolute;
    bottom: -1px; right: -1px;
    width: 11px; height: 11px;
    background: var(--success);
    border: 2px solid var(--bg-surface-solid);
    border-radius: 50%;
    z-index: 2;
}

.user-info h3 { font-size: 15px; font-weight: 600; }
.user-info p  { font-size: 12px; color: var(--text-secondary); }

/* ── Tabs ── */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-smooth);
    font-family: inherit;
}

.tab-btn.active {
    background: var(--accent-surface);
    color: var(--accent-secondary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.tab-btn:not(.active):hover {
    color: var(--text-secondary);
}

/* ── Search Bar ── */
.search-bar {
    padding: 8px 12px;
    flex-shrink: 0;
}

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

.search-wrapper svg {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
    width: 16px; height: 16px;
}

.search-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: var(--radius-full);
    padding: 9px 12px 9px 36px;
    font-size: 13px;
    outline: none;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.search-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

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

/* ── Sidebar Content ── */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-section-title {
    padding: 12px 16px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* ── Contact Card ── */
.contact-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    min-height: 60px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-smooth);
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: visible;
}

.contact-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.03), transparent);
    pointer-events: none;
    border-radius: inherit;
}

.contact-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-card-hover);
}

.contact-card.active {
    background: var(--bg-card-active);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary), var(--shadow-card);
}

.contact-avatar {
    position: relative;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.3;
}

.contact-name .emoji-badge {
    font-size: 13px;
    flex-shrink: 0;
}

.contact-dept {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.pin-badge {
    position: absolute;
    top: 6px; right: 8px;
    color: var(--accent-secondary);
    opacity: 0.8;
    z-index: 2;
}

/* ── Ticket Card ── */
.ticket-card {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-smooth);
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.ticket-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-card-hover);
}

.ticket-card.active {
    background: var(--bg-card-active);
    border-color: var(--accent-primary);
}

.ticket-status-bar {
    width: 4px;
    flex-shrink: 0;
    border-radius: 4px 0 0 4px;
}

.ticket-status-bar.new      { background: var(--status-new); }
.ticket-status-bar.progress  { background: var(--status-progress); }
.ticket-status-bar.closed    { background: var(--status-closed); }

.ticket-body {
    flex: 1;
    padding: 12px 14px;
    min-width: 0;
}

.ticket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.ticket-number {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-secondary);
    font-variant-numeric: tabular-nums;
}

.ticket-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.ticket-user {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.ticket-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticket-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ticket-badge.new {
    background: rgba(245, 158, 11, 0.15);
    color: var(--status-new);
}

.ticket-badge.progress {
    background: var(--accent-surface);
    color: var(--accent-secondary);
}

.ticket-badge.closed {
    background: rgba(100, 116, 139, 0.15);
    color: var(--status-closed);
}

/* ── Create Ticket Button ── */
.create-ticket-area {
    padding: 12px;
    flex-shrink: 0;
}

.create-ticket-btn {
    width: 100%;
    padding: 14px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}

.create-ticket-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-secondary);
    background: var(--accent-surface);
}

/* ── Sidebar Footer ── */
.sidebar-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-indicator .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--warning);
    transition: background var(--transition-fast);
}

.status-indicator.online .dot { background: var(--success); }
.status-indicator.offline .dot { background: var(--danger); }

.btn-icon {
    width: 34px; height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

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

/* ══════════ CHAT AREA ══════════ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    position: relative;
    overflow: hidden;
    background: rgba(8, 14, 30, 0.3);
}

.empty-chat-state {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 16px;
    text-align: center;
    padding: 24px;
}

.active-chat {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.empty-icon {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-chat-state h3 {
    font-size: 20px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Chat Header ── */
.chat-header {
    height: calc(64px + var(--safe-top));
    padding: var(--safe-top) 20px 0;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.chat-title-info { flex: 1; }

.chat-title-info h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-title-info h3 .emoji-badge { font-size: 16px; }

.chat-title-info p {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-title-info p.online { color: var(--success); }

.chat-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Chat Messages ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Message Bubbles ── */
.msg-row {
    display: flex;
    width: 100%;
    animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-row.own { justify-content: flex-end; }
.msg-row.system { justify-content: center; }

.msg-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 16px 16px 16px 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-card);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg-row.own .msg-bubble {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    border: none;
    border-radius: 16px 16px 6px 16px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.msg-row.system .msg-bubble {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    max-width: 85%;
    border-radius: var(--radius-sm);
    text-align: center;
    box-shadow: none;
}

.msg-bubble .msg-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-secondary);
    margin-bottom: 2px;
}

.msg-row.own .msg-bubble .msg-sender { display: none; }

.msg-bubble .msg-text {
    font-size: 14px;
    line-height: 1.5;
}

.msg-bubble .msg-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    cursor: pointer;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 4px;
}

.msg-row.own .msg-meta { color: rgba(255, 255, 255, 0.65); }

.typing-indicator {
    padding: 8px 20px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    flex-shrink: 0;
}

/* ── Chat Input ── */
.chat-input-area {
    padding: 8px 16px;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chat-input-area .input-field,
.chat-input-area textarea.input-field {
    border-radius: var(--radius-full);
    padding: 11px 18px;
    background: var(--bg-input);
    font-size: 14px;
    resize: none;
    overflow-y: auto;
    max-height: 120px;
    line-height: 1.4;
}

/* ── Ticket Actions Bar ── */
.ticket-actions-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.ticket-actions-bar .ticket-info-chip {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Create Ticket Modal ── */
.ticket-form-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: viewEnter 0.2s ease-out;
}

.ticket-form-card {
    width: 100%;
    max-width: 460px;
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ticket-form-card h3 {
    font-size: 18px;
    font-weight: 600;
}

.ticket-form-card textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 14px;
    outline: none;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color var(--transition-fast);
}

.ticket-form-card textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.ticket-form-card textarea::placeholder { color: var(--text-muted); }

.ticket-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ══════════ MOBILE ══════════ */
@media (max-width: 768px) {
    .dashboard-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: 100%;
    }

    .chat-area {
        position: absolute;
        inset: 0;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        background: var(--bg-base);
    }

    .chat-area.open {
        transform: translateX(0);
    }

    .chat-input-area {
        padding-bottom: 8px;
    }

    .group-info-panel {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100% !important;
        min-width: 100% !important;
        z-index: 30;
        border-left: none;
    }
}


/* ── Unread Badge ── */
.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--danger);
    color: white;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    animation: viewEnter 0.2s ease-out;
}
/* ── Section Labels ── */
.section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 8px 12px 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


@media (display-mode: standalone) {
  .install-banner { display: none !important; }
}

.msg-status { font-size: 10px; margin-left: 6px; color: var(--text-muted); }
.msg-row.pending .msg-bubble { opacity: 0.5; }

.load-older-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: var(--bg-surface);
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--accent-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
}
.load-older-btn:hover { background: var(--bg-surface-hover); }


/* Group info panel (right sidebar for group chats) */
.group-info-panel {
    width: 260px;
    min-width: 260px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    flex-shrink: 0;
}
.group-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 14px 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.group-info-header h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.group-info-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.info-tab {
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
}
.info-tab.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}
.group-info-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.group-member-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
}
.group-member-row:hover {
    background: var(--bg-surface-hover);
}
.member-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.member-dot.online {
    background: var(--success);
}
.member-dot.offline {
    background: var(--text-muted);
}
.member-name {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    flex: 1;
}
.member-dept {
    font-size: 11px;
    color: var(--text-muted);
}
.group-media-thumb {
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    transition: opacity .15s;
}
.group-media-thumb:hover {
    opacity: .8;
}
.group-info-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border-subtle);
}
.group-info-footer .btn {
    width: 100%;
}
/* Context menu */
.context-menu {
    background: var(--bg-surface);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,.15);
    padding: 4px;
    min-width: 160px;
}
.ctx-item {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}
.ctx-item:hover {
    background: var(--bg-surface-hover);
}
.ctx-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 4px 8px;
}
.ctx-danger {
    color: var(--color-error);
}
