/* ==========================================================================
   Discussion , the comments under a lesson and on a course page
   (App\Livewire\Discussion, resources/views/livewire/discussion.blade.php).

   Same palette and radii as the lesson page's own blocks (reading-lesson.css):
   brand #4242d6, ink #1c1c6e, hairlines #e5e7eb. Every horizontal offset is a
   logical property, so the thread rail, the reply indent and the badges sit
   on the reading edge in Arabic without a single [dir=rtl] override.
   ========================================================================== */

[x-cloak] { display: none !important; }

.discussion {
    --d-brand: #4242d6;
    --d-brand-hover: #3434b8;
    --d-brand-soft: #eef0ff;
    --d-ink: #1c1c6e;
    --d-text: #374151;
    --d-muted: #6b7280;
    --d-line: #e5e7eb;
    --d-hair: #eef0f6;
    --d-field: #fafbff;

    margin-top: 24px;
    padding: 28px;
    background: #fff;
    border: 1px solid var(--d-line);
    border-radius: 20px;
    color: var(--d-text);
}

/* ── Heading ─────────────────────────────────────────────────────────── */
.discussion__heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.discussion__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--d-ink);
}

.discussion__title i { color: var(--d-brand); font-size: 26px; }

.discussion__count {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--d-brand-soft);
    color: var(--d-brand);
    font-size: 13px;
    font-weight: 600;
}

.discussion__lede {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--d-muted);
}

/* ── Avatars ─────────────────────────────────────────────────────────── */
.d-avatar {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    object-fit: cover;
    background: var(--d-brand-soft);
}

.d-avatar--md { width: 44px; height: 44px; font-size: 16px; }
.d-avatar--sm { width: 34px; height: 34px; font-size: 13px; }

.d-avatar--initials {
    background: hsl(var(--d-hue) 70% 93%);
    color: hsl(var(--d-hue) 45% 28%);
    font-weight: 700;
    letter-spacing: .02em;
    user-select: none;
}

/* ── Writing ─────────────────────────────────────────────────────────── */
.d-compose,
.d-replybox {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.d-compose { margin-top: 20px; }
.d-replybox { margin-top: 14px; }
.d-compose__main { flex: 1; min-width: 0; }

.d-composer__field {
    display: block;
    width: 100%;
    min-height: 84px;
    padding: 12px 14px;
    border: 1px solid var(--d-line);
    border-radius: 14px;
    background: var(--d-field);
    color: var(--d-text);
    font: inherit;
    font-size: 15px;
    line-height: 1.65;
    resize: none;
    overflow-y: hidden;
    /* Each line takes its own direction as it is typed. */
    unicode-bidi: plaintext;
    text-align: start;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.d-replybox .d-composer__field { min-height: 64px; }

.d-composer__field::placeholder { color: #9ca3af; }

.d-composer__field:focus {
    outline: none;
    border-color: var(--d-brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgb(66 66 214 / .12);
}

.d-composer__field[aria-invalid="true"] { border-color: #d92d20; }

.d-composer__to {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--d-muted);
}

.d-composer__to-name { font-weight: 600; color: var(--d-brand); }

.d-composer__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 10px;
}

.d-composer__hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--d-muted);
}

.d-composer__hint kbd {
    padding: 1px 6px;
    border: 1px solid var(--d-line);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: #fff;
    color: var(--d-text);
    font: 600 11px/1.5 inherit;
    direction: ltr;
}

.d-composer__count {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--d-muted);
    direction: ltr;
    unicode-bidi: isolate;
}

.d-composer__count.is-limit { color: #b42318; font-weight: 600; }

.d-composer__buttons {
    display: inline-flex;
    gap: 8px;
    margin-inline-start: auto;
}

.d-error {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: #b42318;
}

/* ── Buttons & links ─────────────────────────────────────────────────── */
.d-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.d-btn:focus-visible,
.d-action:focus-visible,
.d-link:focus-visible {
    outline: 2px solid var(--d-brand);
    outline-offset: 2px;
}

.d-btn--primary { background: var(--d-brand); color: #fff; }
.d-btn--primary:hover:not(:disabled) { background: var(--d-brand-hover); color: #fff; }

.d-btn--primary:disabled {
    background: #c9cbf2;
    color: #fff;
    cursor: not-allowed;
}

.d-btn--ghost {
    background: transparent;
    border-color: #d9dbf7;
    color: var(--d-brand);
}

.d-btn--ghost:hover:not(:disabled) { background: var(--d-brand-soft); }

.d-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--d-brand);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.d-link:hover { text-decoration: underline; }

.d-spin { display: inline-block; animation: d-spin .8s linear infinite; }

@keyframes d-spin { to { transform: rotate(360deg); } }

/* ── Guest and empty states ──────────────────────────────────────────── */
.d-guest {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    margin-top: 20px;
    padding: 16px 18px;
    border-radius: 14px;
    background: var(--d-brand-soft);
}

.d-guest__text { display: grid; gap: 2px; }
.d-guest__text strong { color: var(--d-ink); font-size: 15px; }
.d-guest__text span { color: var(--d-muted); font-size: 14px; }

.d-empty {
    display: grid;
    justify-items: center;
    gap: 6px;
    margin-top: 20px;
    padding: 28px 20px;
    border: 1px dashed #dfe1f2;
    border-radius: 16px;
    text-align: center;
}

.d-empty__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: 4px;
    border-radius: 50%;
    background: var(--d-brand-soft);
    color: var(--d-brand);
    font-size: 28px;
}

.d-empty__title { color: var(--d-ink); font-size: 16px; }
.d-empty__body { max-width: 420px; margin: 0; color: var(--d-muted); font-size: 14px; line-height: 1.6; }

/* ── Threads ─────────────────────────────────────────────────────────── */
.d-threads,
.d-replies__list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.d-threads { margin-top: 12px; }

.d-thread { padding: 18px 0; }
.d-thread + .d-thread { border-top: 1px solid var(--d-hair); }

.d-comment {
    display: flex;
    gap: 12px;
    /* Room for the focus flash to show around the comment. */
    margin: -8px;
    padding: 8px;
    border-radius: 14px;
    scroll-margin-top: 140px;
}

.d-comment__main { flex: 1; min-width: 0; }

.d-comment__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

.d-comment__author {
    color: var(--d-ink);
    font-size: 15px;
    font-weight: 700;
    unicode-bidi: isolate;
}

.d-comment__time {
    color: var(--d-muted);
    font-size: 13px;
}

.d-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.d-badge--instructor { background: var(--d-brand); color: #fff; }
.d-badge--team { background: var(--d-ink); color: #fff; }
.d-badge--you { background: #f1f2f6; color: var(--d-muted); }

.d-comment__to {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 2px 0 0;
    color: var(--d-muted);
    font-size: 13px;
}

.d-comment__to bdi { color: var(--d-brand); font-weight: 600; }

.d-comment__body {
    margin: 6px 0 0;
    color: var(--d-text);
    font-size: 15px;
    line-height: 1.7;
    /* The author's own line breaks, and each line in its own direction. */
    white-space: pre-line;
    unicode-bidi: plaintext;
    text-align: start;
    overflow-wrap: anywhere;
}

.d-comment__body.is-clamped {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 8;
    overflow: hidden;
}

.d-comment__more { margin-top: 4px; }

/* The instructor's answer is the one most readers came for. */
.d-comment--instructor .d-comment__body {
    padding: 10px 14px;
    border-inline-start: 3px solid var(--d-brand);
    border-radius: 4px 12px 12px 4px;
    background: #f6f6ff;
}

[dir="rtl"] .d-comment--instructor .d-comment__body { border-radius: 12px 4px 4px 12px; }

.d-comment__actions { margin-top: 6px; }

.d-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    margin-inline-start: -8px;
    padding: 4px 8px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--d-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.d-action:hover { background: var(--d-brand-soft); color: var(--d-brand); }

.d-replies {
    margin-top: 12px;
    margin-inline-start: 22px;
    padding-inline-start: 34px;
    border-inline-start: 2px solid var(--d-hair);
}

.d-replies__list { display: grid; gap: 14px; }
.d-replies__more { margin-bottom: 12px; }

.d-comment.is-focus { animation: d-flash 2.8s ease-out 1; }

@keyframes d-flash {
    0%, 35% { background: rgb(66 66 214 / .10); box-shadow: 0 0 0 1px rgb(66 66 214 / .25); }
    100% { background: transparent; box-shadow: 0 0 0 1px transparent; }
}

.d-more {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

/* ── Small screens ───────────────────────────────────────────────────── */
@media (max-width: 575px) {
    .discussion { padding: 18px 16px; border-radius: 16px; }
    .discussion__title { font-size: 19px; }
    .d-avatar--md { width: 38px; height: 38px; font-size: 14px; }
    .d-compose > .d-avatar { display: none; }
    .d-replies { margin-inline-start: 10px; padding-inline-start: 14px; }
    .d-btn { min-height: 44px; }
    .d-action { min-height: 40px; }
}

/* Keyboard shortcuts mean nothing on a phone. */
@media (hover: none) {
    .d-composer__hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .d-comment.is-focus { animation: none; background: rgb(66 66 214 / .08); }
    .d-spin { animation: none; }
    .d-composer__field, .d-btn, .d-action { transition: none; }
}
