/* ===========================================================
   NexPers Support Tickets — Frontend
   Self-contained, RTL-first, matches the store's purple theme.
   =========================================================== */
.bst-app,
.bst-app * { box-sizing: border-box; }

.bst-app {
    --bst-primary: #06b6d4;
    --bst-primary-d: #0891b2;
    --bst-grad: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    --bst-bg: #ffffff;
    --bst-soft: #f8f7ff;
    --bst-border: #e8e5f5;
    --bst-text: #1a1a2e;
    --bst-muted: #64748b;
    --bst-radius: 16px;

    direction: rtl;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    min-height: 600px;
    height: 72vh;
    max-height: 820px;
    background: var(--bst-bg);
    border: 1px solid var(--bst-border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px -28px rgba(6, 182, 212, 0.35);
    font-family: 'Vazirmatn', 'Vazir', Tahoma, sans-serif;
    color: var(--bst-text);
}
.bst-hidden { display: none !important; }

/* ---------- Sidebar ---------- */
.bst-sidebar {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--bst-border);
    background: var(--bst-soft);
    min-height: 0;
}
.bst-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--bst-border);
}
.bst-sidebar-head h2 { font-size: 18px; font-weight: 800; margin: 0; }

.bst-stats {
    display: flex;
    gap: 8px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--bst-border);
    flex-wrap: wrap;
}
.bst-stat {
    font-size: 12px;
    color: var(--bst-muted);
    background: #fff;
    border: 1px solid var(--bst-border);
    border-radius: 10px;
    padding: 6px 10px;
}
.bst-stat b { color: var(--bst-text); font-weight: 800; }
.bst-stat-open b { color: #2563eb; }
.bst-stat-answered b { color: #16a34a; }

.bst-ticket-list { flex: 1; overflow-y: auto; padding: 10px; min-height: 0; }
.bst-empty-list { color: var(--bst-muted); text-align: center; padding: 40px 16px; font-size: 14px; }

.bst-ticket-item {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    text-align: right;
    background: #fff;
    border: 1px solid var(--bst-border);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all .2s ease;
    font-family: inherit;
}
.bst-ticket-item:hover { border-color: var(--bst-primary); transform: translateY(-1px); }
.bst-ticket-item.is-active { border-color: var(--bst-primary); background: rgba(6, 182, 212, 0.06); box-shadow: inset 3px 0 0 var(--bst-primary); }
.bst-ti-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.bst-ti-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bst-ti-subject { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bst-ti-meta { font-size: 11px; color: var(--bst-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bst-ti-ref { font-weight: 700; color: var(--bst-primary); }
.bst-ti-status {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 800;
    color: var(--c, #64748b);
    background: color-mix(in srgb, var(--c, #64748b) 12%, #fff);
    border-radius: 20px;
    padding: 3px 9px;
    align-self: flex-start;
}

/* ---------- Main ---------- */
.bst-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bst-pane { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }

/* Welcome */
.bst-pane-welcome { align-items: center; justify-content: center; text-align: center; color: var(--bst-muted); padding: 30px; }
.bst-welcome-inner svg { color: var(--bst-primary); opacity: .5; }
.bst-welcome-inner h3 { margin: 16px 0 6px; color: var(--bst-text); font-size: 18px; }
.bst-welcome-inner p { margin: 0; font-size: 14px; max-width: 320px; }

/* New ticket form */
.bst-pane-new { overflow-y: auto; }
.bst-pane-head { padding: 20px 24px; border-bottom: 1px solid var(--bst-border); }
.bst-pane-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.bst-form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.bst-field { display: flex; flex-direction: column; gap: 7px; }
.bst-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bst-field label { font-size: 13px; font-weight: 700; color: var(--bst-muted); }
.bst-field label span { color: #dc2626; }
.bst-field input[type=text],
.bst-field select,
.bst-field textarea {
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    padding: 12px 14px;
    border: 1.5px solid var(--bst-border);
    border-radius: 12px;
    background: #fff;
    color: var(--bst-text);
    outline: none;
    transition: border-color .2s ease;
}
.bst-field input:focus,
.bst-field select:focus,
.bst-field textarea:focus { border-color: var(--bst-primary); }
.bst-field textarea { resize: vertical; line-height: 1.8; }
.bst-form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 4px; }
.bst-form-msg { font-size: 13px; font-weight: 700; }
.bst-form-msg.is-error { color: #dc2626; }
.bst-form-msg.is-ok { color: #16a34a; }

/* Buttons */
.bst-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    padding: 11px 20px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all .2s ease;
}
.bst-btn-primary { background: var(--bst-grad); color: #fff; box-shadow: 0 8px 20px -6px rgba(6, 182, 212, .5); }
.bst-btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px -6px rgba(6, 182, 212, .6); }
.bst-btn-ghost { background: #fff; border: 1.5px solid var(--bst-border); color: var(--bst-text); }
.bst-btn-ghost:hover { border-color: var(--bst-primary); color: var(--bst-primary); }
.bst-btn[disabled] { opacity: .6; cursor: not-allowed; transform: none; }
.bst-new-btn { padding: 9px 14px; font-size: 13px; }

/* ---------- Thread ---------- */
.bst-thread-head { padding: 16px 22px; border-bottom: 1px solid var(--bst-border); background: var(--bst-soft); }
.bst-thread-head-inner { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.bst-ref { font-size: 12px; font-weight: 800; color: var(--bst-primary); }
.bst-thread-subject { margin: 2px 0 0; font-size: 16px; font-weight: 800; }
.bst-status {
    font-size: 12px; font-weight: 800; color: var(--c, #64748b);
    background: color-mix(in srgb, var(--c, #64748b) 13%, #fff);
    border: 1px solid color-mix(in srgb, var(--c, #64748b) 30%, #fff);
    border-radius: 20px; padding: 5px 14px; white-space: nowrap;
}

.bst-thread-body { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 16px; background: #fbfaff; min-height: 0; }

.bst-msg { display: flex; gap: 10px; max-width: 80%; }
.bst-msg-customer { align-self: flex-start; flex-direction: row; }
.bst-msg-agent { align-self: flex-end; flex-direction: row-reverse; }
.bst-avatar, .bst-msg-avatar img { width: 40px; height: 40px; border-radius: 50%; display: block; }
.bst-msg-avatar { flex-shrink: 0; }
.bst-msg-body {
    background: #fff;
    border: 1px solid var(--bst-border);
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .04);
}
.bst-msg-agent .bst-msg-body { background: linear-gradient(135deg, rgba(6,182,212,.10), rgba(217,70,239,.08)); border-color: rgba(6,182,212,.25); }
.bst-msg-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.bst-msg-author { font-size: 13px; font-weight: 800; }
.bst-badge-agent { font-size: 10px; font-weight: 800; color: #fff; background: var(--bst-grad); border-radius: 20px; padding: 2px 8px; }
.bst-msg-time { font-size: 11px; color: var(--bst-muted); }
.bst-msg-text { font-size: 14px; line-height: 1.9; color: #334155; word-break: break-word; }
.bst-msg-text p { margin: 0 0 6px; }
.bst-msg-text p:last-child { margin: 0; }
.bst-attach { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--bst-primary); text-decoration: none; }
.bst-attach:hover { text-decoration: underline; }

/* Reply box */
.bst-reply-form { display: flex; align-items: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--bst-border); background: #fff; }
.bst-reply-form textarea {
    flex: 1; font-family: inherit; font-size: 14px; line-height: 1.7;
    padding: 12px 16px; border: 1.5px solid var(--bst-border); border-radius: 14px;
    resize: none; outline: none; max-height: 140px; transition: border-color .2s ease;
}
.bst-reply-form textarea:focus { border-color: var(--bst-primary); }
.bst-reply-attach { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--bst-border); color: var(--bst-muted); cursor: pointer; flex-shrink: 0; transition: all .2s ease; }
.bst-reply-attach:hover { border-color: var(--bst-primary); color: var(--bst-primary); }
.bst-reply-attach input { display: none; }
.bst-reply-attach.has-file { border-color: #16a34a; color: #16a34a; }
.bst-send-btn { width: 44px; height: 44px; padding: 0; flex-shrink: 0; }
.bst-send-btn svg { transform: scaleX(-1); }
.bst-thread-closed { padding: 18px; text-align: center; color: var(--bst-muted); font-weight: 700; border-top: 1px solid var(--bst-border); background: var(--bst-soft); }

/* Login / spinner */
.bst-login-notice { padding: 40px; text-align: center; background: #f8f7ff; border: 1px solid #e8e5f5; border-radius: 16px; font-family: 'Vazirmatn', Tahoma, sans-serif; }
.bst-login-notice a { color: #06b6d4; font-weight: 800; }
.bst-loading { text-align: center; color: #94a3b8; padding: 30px; font-size: 13px; }

/* ---------- Floating launcher ---------- */
.bst-launcher {
    position: fixed; inset-inline-start: 22px; bottom: 22px; z-index: 9990;
    display: inline-flex; align-items: center; gap: 9px;
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    color: #fff; text-decoration: none; font-family: 'Vazirmatn', Tahoma, sans-serif;
    font-weight: 800; font-size: 14px; padding: 13px 20px; border-radius: 50px;
    box-shadow: 0 12px 30px -8px rgba(6, 182, 212, .6);
    transition: transform .25s ease, box-shadow .25s ease;
}
.bst-launcher:hover { transform: translateY(-3px); box-shadow: 0 18px 40px -8px rgba(6, 182, 212, .7); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .bst-app { grid-template-columns: 1fr; height: auto; max-height: none; min-height: 0; }
    .bst-sidebar { border-left: none; border-bottom: 1px solid var(--bst-border); }
    .bst-ticket-list { max-height: 320px; }
    .bst-main { min-height: 520px; }
    .bst-app.bst-show-thread .bst-sidebar { display: none; }
    .bst-msg { max-width: 92%; }
    .bst-field-row { grid-template-columns: 1fr; }
    .bst-launcher .bst-launcher-label { display: none; }
    .bst-launcher { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
    .bst-app *, .bst-launcher { transition: none !important; }
}
