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

:root {
    --bg: #0b0d17;
    --sidebar: #111421;
    --card: #151927;
    --card2: #1a1e2e;
    --border: rgba(255,255,255,.08);

    --primary: #6c63ff;
    --primary2: #8d7cff;

    --text: #f4f5ff;
    --muted: #8e94aa;

    --user: #24283b;
}

body {
    font-family: Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

button,
textarea {
    font-family: inherit;
}


/* ================================
   APP
================================ */

.app {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
}


/* ================================
   SIDEBAR
================================ */

.sidebar {
    width: 290px;
    height: 100vh;

    background:
        linear-gradient(
            180deg,
            #121522,
            #0e101a
        );

    border-left: 1px solid var(--border);

    display: flex;
    flex-direction: column;

    padding: 24px 18px;
}


.brand {
    display: flex;
    align-items: center;
    gap: 12px;

    margin-bottom: 28px;
}

.brand-icon,
.ai-avatar,
.welcome-icon {
    display: flex;
    align-items: center;
    justify-content: center;

    background:
        linear-gradient(
            135deg,
            var(--primary),
            var(--primary2)
        );

    color: white;

    box-shadow:
        0 10px 30px rgba(108,99,255,.25);
}


.brand-icon {
    width: 44px;
    height: 44px;

    border-radius: 14px;

    font-size: 22px;
}


.brand h2 {
    font-size: 15px;
    margin-bottom: 4px;
}

.brand span {
    font-size: 11px;
    color: var(--muted);
}


/* New Chat */

.new-chat {
    width: 100%;

    border: 1px solid rgba(255,255,255,.1);

    background:
        linear-gradient(
            135deg,
            rgba(108,99,255,.2),
            rgba(141,124,255,.08)
        );

    color: white;

    padding: 13px;

    border-radius: 12px;

    cursor: pointer;

    transition: .2s;

    font-size: 13px;
}

.new-chat span {
    font-size: 18px;
    margin-left: 5px;
}

.new-chat:hover {
    background: rgba(108,99,255,.3);
}


/* History */

.history-title {
    font-size: 11px;
    color: var(--muted);

    margin:
        30px 8px 12px;
}

.chat-history {
    flex: 1;

    overflow-y: auto;
}

.chat-history::-webkit-scrollbar {
    width: 4px;
}

.chat-history::-webkit-scrollbar-thumb {
    background: #303448;
    border-radius: 20px;
}


.history-item {
    padding: 12px;

    border-radius: 10px;

    cursor: pointer;

    margin-bottom: 5px;

    color: #c8cad7;

    font-size: 12px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    transition: .2s;
}

.history-item:hover {
    background: rgba(255,255,255,.05);
}

.history-item.active {
    background: rgba(108,99,255,.13);
    color: white;
}


.delete-history {
    opacity: 0;

    color: #ff6b7a;

    background: none;

    border: none;

    cursor: pointer;
}

.history-item:hover .delete-history {
    opacity: 1;
}


/* Sidebar bottom */

.sidebar-bottom {
    border-top: 1px solid var(--border);

    padding-top: 15px;
}

.status {
    color: var(--muted);

    font-size: 11px;

    display: flex;
    align-items: center;

    gap: 7px;
}

.status-dot {
    width: 7px;
    height: 7px;

    background: #42d392;

    border-radius: 50%;

    box-shadow:
        0 0 10px #42d392;
}


/* ================================
   MAIN
================================ */

.main {
    flex: 1;

    display: flex;
    flex-direction: column;

    min-width: 0;
}


/* Header */

.topbar {
    height: 76px;

    border-bottom: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 30px;

    background:
        rgba(11,13,23,.8);

    backdrop-filter: blur(15px);
}

.current-chat {
    display: flex;
    align-items: center;

    gap: 12px;
}

.current-chat strong {
    display: block;

    font-size: 14px;

    margin-bottom: 4px;
}

.current-chat small {
    color: var(--muted);

    font-size: 10px;
}

.ai-avatar {
    width: 38px;
    height: 38px;

    border-radius: 12px;

    font-size: 17px;
}


.clear-chat {
    background: transparent;

    border: 1px solid var(--border);

    color: var(--muted);

    border-radius: 9px;

    padding: 9px 13px;

    font-size: 11px;

    cursor: pointer;

    transition: .2s;
}

.clear-chat:hover {
    color: #ff6978;

    border-color:
        rgba(255,105,120,.3);
}


/* ================================
   CHAT
================================ */

.chat-container {
    flex: 1;

    display: flex;
    flex-direction: column;

    min-height: 0;

    position: relative;
}


.messages {
    flex: 1;

    overflow-y: auto;

    padding:
        40px
        max(20px, calc((100vw - 950px) / 2));

    scroll-behavior: smooth;
}


.messages::-webkit-scrollbar {
    width: 5px;
}

.messages::-webkit-scrollbar-thumb {
    background: #292d40;

    border-radius: 20px;
}


/* Welcome */

.welcome {
    max-width: 700px;

    margin: 60px auto;

    text-align: center;
}

.welcome-icon {
    width: 70px;
    height: 70px;

    border-radius: 22px;

    margin:
        0 auto 25px;

    font-size: 32px;
}

.welcome h1 {
    font-size: 30px;

    margin-bottom: 12px;
}

.welcome p {
    color: var(--muted);

    font-size: 13px;

    line-height: 2;
}


.suggestions {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 10px;

    margin-top: 30px;
}

.suggestion {
    padding: 15px;

    background: var(--card);

    border:
        1px solid var(--border);

    color: #d6d8e4;

    border-radius: 12px;

    text-align: right;

    cursor: pointer;

    transition: .2s;

    font-size: 12px;
}

.suggestion:hover {
    border-color:
        rgba(108,99,255,.5);

    transform:
        translateY(-2px);

    background:
        rgba(108,99,255,.08);
}


/* ================================
   MESSAGE
================================ */

.message {
    display: flex;

    gap: 12px;

    margin-bottom: 25px;

    max-width: 850px;

    margin-left: auto;
    margin-right: auto;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    flex-shrink: 0;

    width: 34px;
    height: 34px;

    border-radius: 11px;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 13px;
}

.message.ai .message-avatar {
    background:
        linear-gradient(
            135deg,
            var(--primary),
            var(--primary2)
        );
}

.message.user .message-avatar {
    background: #303548;
}


.message-content {
    max-width: 75%;

    padding: 13px 16px;

    border-radius: 15px;

    font-size: 13px;

    line-height: 2;

    white-space: pre-wrap;
}

.message.user .message-content {
    background: var(--user);

    border-top-left-radius: 4px;
}

.message.ai .message-content {
    background: var(--card);

    border:
        1px solid var(--border);

    border-top-right-radius: 4px;
}


/* ================================
   TYPING
================================ */

.typing {
    max-width: 850px;

    margin:
        0 auto 15px;

    display: flex;

    gap: 10px;

    align-items: center;
}

.typing-content {
    display: flex;

    gap: 4px;

    background: var(--card);

    padding: 13px 16px;

    border-radius: 14px;
}

.typing-content span {
    width: 5px;
    height: 5px;

    background: #8c91a7;

    border-radius: 50%;

    animation:
        typing 1.2s infinite;
}

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

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

@keyframes typing {

    0%, 60%, 100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-5px);
    }
}

.hidden {
    display: none;
}


/* ================================
   INPUT
================================ */

.input-wrapper {
    width: min(850px, calc(100% - 40px));

    margin:
        0 auto 22px;
}

.input-box {
    background: #151925;

    border:
        1px solid rgba(255,255,255,.1);

    border-radius: 18px;

    padding: 14px;

    box-shadow:
        0 15px 50px rgba(0,0,0,.25);

    transition: .2s;
}

.input-box:focus-within {
    border-color:
        rgba(108,99,255,.5);

    box-shadow:
        0 15px 60px rgba(108,99,255,.08);
}

textarea {
    width: 100%;

    resize: none;

    background: transparent;

    border: none;

    outline: none;

    color: white;

    font-size: 13px;

    line-height: 1.8;

    max-height: 150px;
}

textarea::placeholder {
    color: #686e82;
}


.input-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-top: 8px;
    direction: ltr;
}

.hint {
    color: #5e6478;

    font-size: 9px;
}

.send-btn {
    width: 38px;
    height: 38px;

    border: none;

    border-radius: 11px;

    background:
        linear-gradient(
            135deg,
            var(--primary),
            var(--primary2)
        );

    color: white;

    cursor: pointer;

    transition: .2s;
}

.send-btn:hover {
    transform: scale(1.06);
}

.send-btn:disabled {
    opacity: .4;

    cursor: not-allowed;

    transform: none;
}

.security-note {
    text-align: center;

    color: #50566a;

    font-size: 9px;

    margin-top: 8px;
}


/* Mobile menu */

.mobile-menu {
    display: none;

    font-size: 22px;

    cursor: pointer;
}


/* ================================
   MOBILE
================================ */

@media(max-width: 800px) {

    .sidebar {
        position: fixed;
        right: -300px;
        top: 0;
        z-index: 9999;
        transition: .3s;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
    }

    .sidebar.open {
        right: 0;
    }

    .mobile-menu {
        display: block;
    }

    .topbar {
        padding: 0 15px;
    }

    .messages {
        padding:
            25px 15px;
    }

    .welcome {
        margin-top: 30px;
    }

    .welcome h1 {
        font-size: 25px;
    }

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

    .message-content {
        max-width: 82%;
    }

    .input-wrapper {
        width: calc(100% - 20px);
    }

    .clear-chat {
        display: none;
    }
}





/* ================================
   AUTH PAGE
================================ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow-y: auto;
    padding: 20px;
}

.auth-box {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: 0 20px 80px rgba(0,0,0,.4);
    overflow: hidden;
}

.auth-box .brand {
    justify-content: center;
    margin-bottom: 24px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--card2);
    padding: 5px;
    border-radius: 12px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: .2s;
    font-family: inherit;
}

.auth-tab.active {
    background: var(--primary);
    color: white;
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.auth-form.active {
    display: flex;
}

.auth-form input {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 15px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 11px;
    color: white;
    font-size: 13px;
    outline: none;
    transition: .2s;
    font-family: inherit;
}

.auth-form input:focus {
    border-color: rgba(108,99,255,.6);
}

.auth-form input::placeholder {
    color: #686e82;
}

.auth-form button[type="submit"] {
    padding: 13px;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    border: none;
    border-radius: 11px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: .2s;
    margin-top: 4px;
    font-family: inherit;
}

.auth-form button[type="submit"]:hover {
    transform: translateY(-1px);
}

.auth-error {
    color: #ff6978;
    font-size: 11px;
    text-align: center;
    min-height: 16px;
}



/* ================================
   USER INFO / LOGOUT
================================ */

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    margin-bottom: 10px;
    border-radius: 10px;
    background: rgba(255,255,255,.03);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
}

.user-details {
    overflow: hidden;
}

.user-details strong {
    display: block;
    font-size: 12px;
    color: white;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-details small {
    font-size: 10px;
    color: var(--muted);
    direction: ltr;
    display: inline-block;
}

.logout-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(255,105,120,.2);
    color: #ff6978;
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;
    transition: .2s;
}

.logout-btn:hover {
    background: rgba(255,105,120,.1);
    border-color: rgba(255,105,120,.5);
}





.auth-form input {
    width: 100%;
    box-sizing: border-box;
}

.auth-box {
    overflow: hidden;
}



/* ================================
   ADMIN TAB
================================ */

.admin-tab.active,
.new-chat.active {
    background: rgba(108,99,255,.35);
    border-color: rgba(108,99,255,.6);
}

.knowledge-form {
    max-width: 850px;
    margin: 0 auto 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 22px;
}

.knowledge-form h3 {
    margin-bottom: 18px;
    font-size: 16px;
    color: white;
}

.knowledge-form label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin: 12px 0 6px;
}

.knowledge-form input[type="text"],
.knowledge-form input[type="file"],
.knowledge-form select,
.knowledge-form textarea {
    width: 100%;
    padding: 12px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

.knowledge-form textarea {
    resize: vertical;
    line-height: 1.8;
    min-height: 200px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.form-actions button {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
}

.form-actions #saveK {
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: white;
}

.form-actions #cancelK {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
}

.knowledge-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    margin-bottom: 14px;
    transition: .2s;
    max-width: 850px;
    margin-left: auto;
    margin-right: auto;
}

.knowledge-card:hover {
    border-color: rgba(108,99,255,.3);
}

.knowledge-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    gap: 10px;
}

.knowledge-cat {
    display: inline-block;
    font-size: 10px;
    padding: 3px 9px;
    background: rgba(108,99,255,.2);
    color: var(--primary2);
    border-radius: 20px;
    margin-left: 8px;
}

.knowledge-header strong {
    font-size: 14px;
    color: white;
}

.knowledge-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 15px;
    padding: 5px;
    opacity: 0.7;
    transition: .2s;
}

.knowledge-actions button:hover { opacity: 1; }

.knowledge-preview {
    font-size: 12px;
    line-height: 1.9;
    color: var(--muted);
    white-space: pre-wrap;
}

.knowledge-date {
    display: block;
    margin-top: 10px;
    font-size: 10px;
    color: #50566a;
}



/* ================================
   IMAGE UPLOAD
================================ */

.left-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.right-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.attach-btn {
    cursor: pointer;
    opacity: 0.7;
    transition: all .25s ease;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    position: relative;
}

.attach-btn:hover {
    opacity: 1;
    background: rgba(108, 99, 255, 0.15);
    transform: scale(1.08);
    box-shadow: 0 0 0 1px rgba(108, 99, 255, 0.3);
}

.attach-btn img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
    filter: brightness(0) invert(0.7);
    transition: .2s;
}

.attach-btn:hover img {
    filter: brightness(0) invert(1);
}

.image-preview {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.image-preview.hidden {
    display: none !important;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.preview-item img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    display: block;
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ff4757;
    color: white;
    border: 2px solid var(--bg);
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.remove-image:hover {
    background: #ff2e44;
}

/* عکس‌های داخل پیام */
.message-images {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.message-images img {
    max-width: 150px;
    max-height: 150px;
    border-radius: 8px;
    object-fit: cover;
}


/* ================================
   SIDEBAR OVERLAY (موبایل)
================================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    opacity: 0;
    transition: opacity .3s;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}


/* ================================
   KNOWLEDGE SEARCH
================================ */

.knowledge-search-box {
    padding: 15px 20px 0;
    background: transparent;
    flex-shrink: 0;
}

.knowledge-search-box input {
    width: 100%;
    max-width: 850px;
    display: block;
    margin: 0 auto;
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: white;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: .2s;
}

.knowledge-search-box input:focus {
    border-color: rgba(108,99,255,.5);
    background: var(--card2);
}

.knowledge-search-box input::placeholder {
    color: #686e82;
}



/* ================================
   KNOWLEDGE STATS
================================ */

.knowledge-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 20px 20px 0;
    max-width: 850px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all .2s;
    user-select: none;
}

.stat-card:hover {
    border-color: rgba(108,99,255,.5);
    background: rgba(108,99,255,.08);
    transform: translateY(-2px);
}

.stat-card.stat-all {
    background: linear-gradient(135deg, rgba(108,99,255,.15), rgba(141,124,255,.05));
    border-color: rgba(108,99,255,.3);
}

.stat-icon {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}

.stat-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stat-info strong {
    font-size: 18px;
    color: white;
    line-height: 1.2;
}

.stat-info span {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* موبایل */
@media (max-width: 800px) {
    .knowledge-stats {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 8px;
        padding: 15px 15px 0;
    }

    .stat-card {
        padding: 10px;
        gap: 8px;
    }

    .stat-icon {
        font-size: 18px;
    }

    .stat-info strong {
        font-size: 15px;
    }

    .stat-info span {
        font-size: 9px;
    }
}

/* ================================
   ADMIN TOPBAR & BUTTONS
================================ */

.admin-topbar {
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.admin-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 11px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .25s ease;
    white-space: nowrap;
}

.admin-btn-icon {
    font-size: 15px;
    line-height: 1;
}

/* دکمه ساخت Embedding */
.admin-btn-embed {
    background: linear-gradient(135deg, rgba(108,99,255,.18), rgba(141,124,255,.08));
    border-color: rgba(108,99,255,.35);
    color: #c8c2ff;
}

.admin-btn-embed:hover {
    background: linear-gradient(135deg, rgba(108,99,255,.3), rgba(141,124,255,.15));
    border-color: rgba(108,99,255,.6);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(108,99,255,.2);
}

.admin-btn-embed:disabled {
    opacity: .6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* دکمه دانش جدید */
.admin-btn-new {
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: white;
    box-shadow: 0 8px 20px rgba(108,99,255,.25);
}

.admin-btn-new:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(108,99,255,.4);
}

.admin-btn-new:active {
    transform: translateY(0);
}

/* موبایل */
@media (max-width: 800px) {

    .admin-topbar {
        padding: 12px 15px;
        height: auto;
    }

    .admin-actions {
        width: 100%;
    }

    .admin-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 12px;
        font-size: 12px;
    }

    .admin-btn-text {
        display: none;
    }

    .admin-btn-icon {
        font-size: 18px;
    }
}

/* ================================
   IMAGE MODAL
================================ */

.image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-modal-content {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.image-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.image-modal-header h3 {
    font-size: 15px;
    color: white;
}

.image-modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}

.image-modal-close:hover {
    background: rgba(255,255,255,.05);
    color: white;
}

.image-modal-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
}

.image-modal-body label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.image-modal-input {
    width: 100%;
    padding: 12px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

.image-modal-input:focus {
    border-color: rgba(108,99,255,.5);
}

.image-doc-list {
    max-height: 180px;
    overflow-y: auto;
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.image-doc-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: #d6d8e4;
    transition: .15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.image-doc-item:hover {
    background: rgba(255,255,255,.04);
}

.image-doc-item.selected {
    background: rgba(108,99,255,.15);
    color: white;
}

.image-doc-item .doc-cat {
    font-size: 10px;
    color: var(--primary2);
    background: rgba(108,99,255,.15);
    padding: 2px 8px;
    border-radius: 20px;
}

.image-doc-empty {
    padding: 20px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

.image-modal-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.image-modal-preview .preview-item {
    position: relative;
}

.image-modal-preview img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

.image-modal-preview .remove-preview {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ff4757;
    color: white;
    border: 2px solid var(--card);
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-footer {
    padding: 15px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

.image-modal-footer .admin-btn {
    padding: 10px 18px;
}

/* دکمه‌ی افزودن تصویر */
.admin-btn-image {
    background: linear-gradient(135deg, rgba(255,180,50,.18), rgba(255,220,100,.08));
    border-color: rgba(255,180,50,.35);
    color: #ffd77a;
}

.admin-btn-image:hover {
    background: linear-gradient(135deg, rgba(255,180,50,.3), rgba(255,220,100,.15));
    border-color: rgba(255,180,50,.6);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(255,180,50,.2);
}

/* ================================
   IMAGE COUNT BADGE
================================ */

.image-count-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 8px;
    background: rgba(255, 180, 50, 0.15);
    color: #ffd77a;
    border-radius: 20px;
    margin-right: 6px;
}

/* ================================
   IMAGES MANAGER (نمایش عکس‌های سند)
================================ */

.knowledge-image-item {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    transition: .2s;
}

.knowledge-image-item:hover {
    border-color: rgba(108, 99, 255, 0.3);
}

.knowledge-image-item img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.knowledge-image-info {
    flex: 1;
    overflow: hidden;
}

.knowledge-image-desc {
    font-size: 12px;
    color: #d6d8e4;
    line-height: 1.8;
    margin-bottom: 6px;
}

.knowledge-image-date {
    font-size: 10px;
    color: var(--muted);
}

.delete-image-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 8px;
    opacity: 0.6;
    transition: .2s;
    flex-shrink: 0;
}

.delete-image-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* دکمه‌ی مدیریت عکس توی کارت */
.images-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 15px;
    padding: 5px;
    opacity: 0.7;
    transition: .2s;
}

.images-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* موبایل */
@media (max-width: 800px) {
    .knowledge-image-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .knowledge-image-item img {
        width: 100%;
        height: 150px;
    }

    .delete-image-btn {
        align-self: flex-end;
    }
}

/* ==========================================
   IMAGE ACTIONS
========================================== */

.image-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.image-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    opacity: 0.6;
    transition: .2s;
    border-radius: 8px;
}

.image-actions button:hover {
    opacity: 1;
    background: rgba(255,255,255,.05);
    transform: scale(1.1);
}

.knowledge-image-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

/* ==========================================
   MARKDOWN STYLES
========================================== */

.message-text {
    font-size: 13px;
    line-height: 2;
    color: #e8e9f3;
}

.message-text p {
    margin: 0 0 10px 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

/* هدرها */
.message-text .md-h1 {
    font-size: 18px;
    font-weight: bold;
    color: white;
    margin: 16px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.message-text .md-h2 {
    font-size: 16px;
    font-weight: bold;
    color: white;
    margin: 14px 0 8px;
}

.message-text .md-h3 {
    font-size: 14px;
    font-weight: bold;
    color: var(--primary2);
    margin: 12px 0 8px;
}

.message-text .md-h4 {
    font-size: 13px;
    font-weight: bold;
    color: var(--primary2);
    margin: 10px 0 6px;
}

/* بولد */
.message-text strong {
    color: white;
    font-weight: bold;
}

/* ایتالیک */
.message-text em {
    color: #d6d8e4;
    font-style: italic;
}

/* کد */
.message-text .md-code {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #a5d6a7;
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    white-space: pre-wrap;
    line-height: 1.8;
}

.message-text .md-inline-code {
    background: rgba(108, 99, 255, 0.15);
    color: var(--primary2);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    direction: ltr;
    display: inline-block;
}

/* لیست‌ها */
.message-text .md-ul {
    margin: 8px 0;
    padding-right: 22px;
    list-style: none;
}

.message-text .md-ul li {
    position: relative;
    margin-bottom: 6px;
    padding-right: 14px;
    line-height: 1.9;
}

.message-text .md-ul li::before {
    content: '◆';
    position: absolute;
    right: 0;
    color: var(--primary);
    font-size: 9px;
    top: 7px;
}

.message-text .md-ul li.md-oli {
    counter-increment: md-counter;
}

.message-text .md-ul {
    counter-reset: md-counter;
}

.message-text .md-ul li.md-oli::before {
    content: counter(md-counter) ".";
    color: var(--primary2);
    font-size: 11px;
    font-weight: bold;
    top: 2px;
}

/* خط جداکننده */
.message-text .md-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}



/* ================================
   APK PANEL
================================ */

.apk-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 20px 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.apk-tab {
    padding: 10px 18px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    border-radius: 10px 10px 0 0;
    transition: .2s;
    border-bottom: 2px solid transparent;
}

.apk-tab:hover {
    color: white;
    background: rgba(255,255,255,.03);
}

.apk-tab.active {
    color: white;
    background: var(--card);
    border-bottom-color: var(--primary);
}

/* کارت‌های شرکت */
.apk-company-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    margin-bottom: 14px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    transition: .2s;
}

.apk-company-card:hover {
    border-color: rgba(108,99,255,.3);
}

.apk-company-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.apk-company-title {
    font-size: 16px;
    font-weight: bold;
    color: white;
    margin-bottom: 4px;
}

.apk-company-meta {
    font-size: 11px;
    color: var(--muted);
}

.apk-company-stats {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
}

.apk-company-stats strong {
    color: white;
}

/* وضعیت اشتراک */
.apk-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: bold;
}

.apk-status-active {
    background: rgba(66, 211, 146, .15);
    color: #42d392;
}

.apk-status-warning {
    background: rgba(255, 215, 122, .15);
    color: #ffd77a;
}

.apk-status-expired {
    background: rgba(255, 105, 120, .15);
    color: #ff6978;
}

.apk-status-pending {
    background: rgba(108, 99, 255, .15);
    color: #8d7cff;
}

/* دکمه‌های عملیات */
.apk-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.apk-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 8px;
    opacity: .7;
    transition: .2s;
}

.apk-actions button:hover {
    opacity: 1;
    background: rgba(255,255,255,.05);
}

/* فرم */
.apk-form {
    max-width: 700px;
    margin: 0 auto 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
}

.apk-form h3 {
    margin-bottom: 18px;
    font-size: 15px;
    color: white;
}

.apk-form label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin: 12px 0 6px;
}

.apk-form input[type="text"],
.apk-form input[type="tel"],
.apk-form input[type="number"],
.apk-form input[type="date"],
.apk-form input[type="password"],
.apk-form select,
.apk-form textarea {
    width: 100%;
    padding: 11px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

.apk-form textarea {
    resize: vertical;
    min-height: 150px;
    line-height: 1.8;
}

.apk-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.apk-form-actions button {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: .2s;
}

.apk-form-actions .save {
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: white;
}

.apk-form-actions .cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
}

/* موبایل */
@media (max-width: 800px) {
    .apk-tabs {
        overflow-x: auto;
        white-space: nowrap;
    }

    .apk-tab {
        padding: 8px 12px;
        font-size: 12px;
    }
}


/* ================================
   APK - کارت‌های آمار دانش
================================ */
.apk-stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
    transition: .2s;
    cursor: default;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.apk-stat-card:hover {
    border-color: rgba(108,99,255,.3);
    transform: translateY(-2px);
}

@media (max-width: 800px) {
    .apk-stat-card {
        padding: 8px 6px;
    }

    .apk-stat-card div:first-child {
        font-size: 15px !important;
    }

    .apk-stat-card div:nth-child(2) {
        font-size: 14px !important;
    }

    .apk-stat-card div:nth-child(3) {
        font-size: 9px !important;
    }
}
