/* ==========================================================
   TP Chat – Public Stylesheet
   ========================================================== */

/* ── Custom Properties (Light Mode Default) ──────────────── */
:root {
    --tpc-bg:           #f8fafc;
    --tpc-surface:      #ffffff;
    --tpc-surface2:     #f1f5f9;
    --tpc-border:       rgba(0,0,0,0.08);
    --tpc-border-hover: rgba(0,0,0,0.16);

    --tpc-accent:       #6c63ff;
    --tpc-accent-glow:  rgba(108,99,255,0.25);
    --tpc-accent-hover: #5a52d5;
    --tpc-accent-light: rgba(108,99,255,0.08);

    --tpc-success:      #10b981;
    --tpc-success-bg:   rgba(16,185,129,0.12);
    --tpc-error:        #ef4444;
    --tpc-error-bg:     rgba(239,68,68,0.12);
    --tpc-info:         #3b82f6;
    --tpc-info-bg:      rgba(59,130,246,0.12);

    --tpc-text:         #1e293b;
    --tpc-text-muted:   #64748b;
    --tpc-text-dim:     #94a3b8;

    --tpc-bubble-mine:    #6c63ff;
    --tpc-bubble-theirs:  #f1f5f9;

    --tpc-radius-sm:  6px;
    --tpc-radius:     12px;
    --tpc-radius-lg:  20px;
    --tpc-radius-xl:  28px;

    --tpc-font:       'Inter', system-ui, -apple-system, sans-serif;
    --tpc-shadow:     0 4px 20px rgba(0,0,0,0.05);
    --tpc-shadow-sm:  0 2px 8px rgba(0,0,0,0.03);
}



/* ── Base Reset ─────────────────────────────────────────── */
.tpchat-contact-wrap,
.tpchat-inbox-wrap,
.tpchat-thread-wrap {
    font-family: var(--tpc-font);
    color: var(--tpc-text);
    max-width: 760px;
    margin: 0 auto;
    padding: 0 0 40px;
    line-height: 1.6;
}

/* ── Notices ────────────────────────────────────────────── */
.tpchat-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--tpc-radius);
    font-size: 0.875rem;
    margin-bottom: 20px;
}
.tpchat-notice svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}
.tpchat-notice--success { background: var(--tpc-success-bg); color: var(--tpc-success); border: 1px solid rgba(34,211,165,0.3); }
.tpchat-notice--error   { background: var(--tpc-error-bg);   color: var(--tpc-error);   border: 1px solid rgba(248,113,113,0.3); }
.tpchat-notice--info    { background: var(--tpc-info-bg);    color: var(--tpc-info);    border: 1px solid rgba(96,165,250,0.3); flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────────────────── */
.tpchat-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--tpc-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: all 0.2s ease;
}
.tpchat-btn svg { width: 16px; height: 16px; }
.tpchat-btn--primary {
    background: var(--tpc-accent);
    color: #fff;
    box-shadow: 0 0 20px var(--tpc-accent-glow);
}
.tpchat-btn--primary:hover {
    background: var(--tpc-accent-hover);
    box-shadow: 0 0 28px var(--tpc-accent-glow);
    transform: translateY(-1px);
    color: #fff;
    text-decoration: none;
}
.tpchat-btn--sm   { padding: 6px 14px; font-size: 0.8rem; }
.tpchat-btn--full { width: 100%; justify-content: center; }

/* ── Badge ──────────────────────────────────────────────── */
.tpchat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--tpc-accent);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}
.tpchat-badge--unread {
    padding: 4px 12px;
    border-radius: var(--tpc-radius);
    font-size: 0.8rem;
    height: auto;
}

/* ── Avatar ─────────────────────────────────────────────── */
.tpchat-avatar {
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.tpchat-avatar--sm { width: 32px !important; height: 32px !important; }

/* ── Form Elements ──────────────────────────────────────── */
.tpchat-field      { margin-bottom: 16px; }
.tpchat-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--tpc-text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tpchat-textarea {
    width: 100%;
    background: var(--tpc-surface2);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius);
    color: var(--tpc-text);
    padding: 12px 16px;
    font-size: 0.95rem;
    font-family: var(--tpc-font);
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}
.tpchat-textarea:focus {
    outline: none;
    border-color: var(--tpc-accent);
    box-shadow: 0 0 0 3px var(--tpc-accent-glow);
}
.tpchat-textarea::placeholder { color: var(--tpc-text-dim); }
.tpchat-char-counter {
    text-align: right;
    font-size: 0.75rem;
    color: var(--tpc-text-dim);
    margin-top: 4px;
}

/* ── Empty State ────────────────────────────────────────── */
.tpchat-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--tpc-text-muted);
}
.tpchat-empty svg {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    display: block;
    opacity: 0.4;
}
.tpchat-empty p { font-size: 0.95rem; margin: 0; }

/* ==========================================================
   CONTACT FORM
   ========================================================== */
.tpchat-contact-card {
    background: var(--tpc-surface);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius-lg);
    padding: 28px;
    box-shadow: var(--tpc-shadow);
}
.tpchat-contact-card__header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--tpc-border);
}
.tpchat-contact-card__icon {
    width: 28px;
    height: 28px;
    color: var(--tpc-accent);
    flex-shrink: 0;
    margin-top: 2px;
}
.tpchat-contact-card__title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--tpc-text);
}
.tpchat-contact-card__listing {
    font-size: 0.85rem;
    color: var(--tpc-text-muted);
    margin: 0;
}
.tpchat-contact-card__listing strong { color: var(--tpc-text); }

/* ==========================================================
   INBOX OVERVIEW
   ========================================================== */
.tpchat-inbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--tpc-border);
}
.tpchat-inbox-header__left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.tpchat-inbox-header__left svg {
    width: 24px;
    height: 24px;
    color: var(--tpc-accent);
}
.tpchat-inbox-header__title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: var(--tpc-text);
}

.tpchat-conversation-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tpchat-conv-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--tpc-surface);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius-lg);
    text-decoration: none;
    color: var(--tpc-text);
    transition: all 0.2s ease;
    position: relative;
}
.tpchat-conv-item:hover {
    background: var(--tpc-surface2);
    border-color: var(--tpc-border-hover);
    transform: translateY(-1px);
    box-shadow: var(--tpc-shadow-sm);
    text-decoration: none;
    color: var(--tpc-text);
}
.tpchat-conv-item--unread {
    border-left: 3px solid var(--tpc-accent);
    background: var(--tpc-accent-light);
}

.tpchat-conv-item__avatar {
    position: relative;
    flex-shrink: 0;
}
.tpchat-conv-item__dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: var(--tpc-accent);
    border-radius: 50%;
    border: 2px solid var(--tpc-bg);
}
.tpchat-conv-item__body {
    flex: 1;
    min-width: 0;
}
.tpchat-conv-item__meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}
.tpchat-conv-item__name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--tpc-text);
}
.tpchat-conv-item__time {
    font-size: 0.75rem;
    color: var(--tpc-text-dim);
    white-space: nowrap;
}
.tpchat-conv-item__listing {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--tpc-text-muted);
    margin-bottom: 4px;
}
.tpchat-conv-item__preview {
    font-size: 0.85rem;
    color: var(--tpc-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tpchat-conv-item--unread .tpchat-conv-item__preview {
    color: var(--tpc-text);
    font-weight: 500;
}

/* ==========================================================
   THREAD VIEW
   ========================================================== */
.tpchat-thread-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--tpc-surface);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--tpc-shadow-sm);
}
.tpchat-back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--tpc-text-muted);
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
    padding: 6px 10px;
    border-radius: var(--tpc-radius-sm);
    border: 1px solid var(--tpc-border);
}
.tpchat-back-btn:hover { color: var(--tpc-text); text-decoration: none; border-color: var(--tpc-border-hover); }
.tpchat-back-btn svg   { width: 16px; height: 16px; }
.tpchat-thread-header__user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}
.tpchat-thread-header__name {
    display: block;
    font-weight: 700;
    font-size: 1rem;
    color: var(--tpc-text);
}
.tpchat-thread-header__listing {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--tpc-text-muted);
    margin-top: 2px;
}

/* ── Messages Container ─────────────────────────────────── */
.tpchat-messages {
    min-height: 300px;
    max-height: 520px;
    overflow-y: auto;
    padding: 20px;
    background: var(--tpc-surface);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius-lg);
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}
.tpchat-messages::-webkit-scrollbar       { width: 6px; }
.tpchat-messages::-webkit-scrollbar-track { background: transparent; }
.tpchat-messages::-webkit-scrollbar-thumb { background: var(--tpc-border); border-radius: 3px; }

/* ── Date Divider ───────────────────────────────────────── */
.tpchat-date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0 8px;
    color: var(--tpc-text-dim);
    font-size: 0.75rem;
}
.tpchat-date-divider::before,
.tpchat-date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--tpc-border);
}

/* ── Message Bubble ─────────────────────────────────────── */
.tpchat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    margin-bottom: 4px;
    animation: tpchat-fadein 0.2s ease;
}
@keyframes tpchat-fadein {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tpchat-msg--mine   { align-self: flex-end; flex-direction: row-reverse; }
.tpchat-msg--theirs { align-self: flex-start; }

.tpchat-msg__avatar { flex-shrink: 0; align-self: flex-end; }

.tpchat-msg__inner  { display: flex; flex-direction: column; max-width: 100%; }
.tpchat-msg--mine .tpchat-msg__inner   { align-items: flex-end; }
.tpchat-msg--theirs .tpchat-msg__inner { align-items: flex-start; }

.tpchat-msg__bubble {
    padding: 10px 16px;
    border-radius: var(--tpc-radius-xl);
    font-size: 0.92rem;
    line-height: 1.55;
    word-break: break-word;
    max-width: 100%;
}
.tpchat-msg--mine .tpchat-msg__bubble {
    background: var(--tpc-bubble-mine);
    color: #fff;
    border-bottom-right-radius: var(--tpc-radius-sm);
    box-shadow: 0 2px 12px var(--tpc-accent-glow);
}
.tpchat-msg--theirs .tpchat-msg__bubble {
    background: var(--tpc-bubble-theirs);
    color: var(--tpc-text);
    border-bottom-left-radius: var(--tpc-radius-sm);
    border: 1px solid var(--tpc-border);
}

.tpchat-msg__meta {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--tpc-text-dim);
}
.tpchat-msg__sender { color: var(--tpc-text-muted); font-weight: 600; }
.tpchat-msg__sep    { opacity: 0.5; }
.tpchat-msg__read   { display: flex; align-items: center; color: var(--tpc-success); }
.tpchat-msg__read svg { display: block; }

/* ── Reply Form ─────────────────────────────────────────── */
.tpchat-reply-wrap {
    margin-top: 16px;
    background: var(--tpc-surface);
    border: 1px solid var(--tpc-border);
    border-radius: var(--tpc-radius-lg);
    padding: 16px 20px;
}
.tpchat-reply-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.tpchat-reply-textarea {
    flex: 1;
    resize: none;
    max-height: 160px;
    min-height: 44px;
    padding: 10px 14px;
    line-height: 1.5;
    overflow-y: auto;
}
.tpchat-send-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--tpc-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 0 16px var(--tpc-accent-glow);
    transition: all 0.2s ease;
    padding: 0;
}
.tpchat-send-btn:hover {
    background: var(--tpc-accent-hover);
    transform: scale(1.08);
    box-shadow: 0 0 24px var(--tpc-accent-glow);
}
.tpchat-send-btn svg { width: 18px; height: 18px; }
.tpchat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.tpchat-closed-note {
    text-align: center;
    color: var(--tpc-text-dim);
    font-size: 0.85rem;
    margin-top: 16px;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 600px) {
    .tpchat-contact-card  { padding: 20px 16px; }
    .tpchat-thread-header { padding: 12px 14px; gap: 10px; }
    .tpchat-messages      { padding: 14px 12px; max-height: 400px; }
    .tpchat-reply-wrap    { padding: 12px 14px; }
    .tpchat-msg           { max-width: 95%; }
    .tpchat-conv-item     { padding: 14px 16px; }
}

/* ==========================================================
   LOADING SPINNER (AJAX)
   ========================================================== */
.tpchat-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tpchat-spin 0.7s linear infinite;
}
@keyframes tpchat-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================
   Unread Badge
   ========================================================== */
.tpchat-unread-badge-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--tpc-text, #1e293b);
    transition: color 0.2s ease;
}
.tpchat-unread-badge-link:hover {
    color: var(--tpc-accent, #6c63ff);
}

.tpchat-unread-badge__label {
    font-family: var(--tpc-font, 'Inter', system-ui, sans-serif);
    font-size: 14px;
    font-weight: 500;
}

.tpchat-unread-badge__icon {
    display: block;
    flex-shrink: 0;
}

.tpchat-unread-badge__count {
    position: absolute;
    top: -6px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--tpc-error, #ef4444);
    color: #fff;
    font-family: var(--tpc-font, 'Inter', system-ui, sans-serif);
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: tpchat-badge-pop 0.3s ease;
    pointer-events: none;
}

@keyframes tpchat-badge-pop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
