/* Telegram-like Channel - Public & Admin */

:root {
    --bg-page: #0e1621;
    --bg-bubble: #182533;
    --bg-bubble-border: #242f3d;
    --text-primary: #e4e4e4;
    --text-meta: #6d7a8a;
    --accent: #2b5278;
    --font: 'Vazirmatn', 'Tahoma', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    direction: rtl;
}

/* ----- Public header ----- */
.site-header {
    background: var(--bg-bubble);
    border-bottom: 1px solid var(--bg-bubble-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.channel-name {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
}

.admin-link {
    color: var(--text-meta);
    text-decoration: none;
    font-size: 0.9rem;
}

.admin-link:hover {
    color: var(--text-primary);
}

/* ----- Main content (channel feed) ----- */
/* قاب ثابت: فقط داخلش اسکرول می‌شود، پست‌ها از پایین به بالا */
.main-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
    height: calc(100vh - 56px); /* قد منهای هدر */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ظرف پست‌ها: برعکس — جدیدترین پایین، قدیمی‌ها بالا */
#posts-container {
    display: flex;
    flex-direction: column-reverse;
    flex: 1;
    min-height: min-content;
    padding-bottom: 0.5rem;
}

/* لودینگ «پست‌های قدیمی‌تر» بالای قاب */
#loading {
    flex-shrink: 0;
}

/* اسکرول‌بار مثل تلگرام — باریک، گرد، تیره */
.main-content {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-bubble-border) transparent;
}
.main-content::-webkit-scrollbar {
    width: 8px;
}
.main-content::-webkit-scrollbar-track {
    background: transparent;
}
.main-content::-webkit-scrollbar-thumb {
    background: var(--bg-bubble-border);
    border-radius: 4px;
}
.main-content::-webkit-scrollbar-thumb:hover {
    background: #3d4a5c;
}
.main-content::-webkit-scrollbar-thumb:active {
    background: var(--text-meta);
}

/* جداکننده تاریخ (مثل تلگرام) */
.date-separator {
    text-align: center;
    margin: 1rem 0 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-meta);
    background: rgba(36, 47, 61, 0.6);
    border-radius: 12px;
    display: inline-block;
    align-self: center;
    flex-shrink: 0;
}

/* ----- Message bubble (Telegram style) ----- */
.message-bubble {
    background: var(--bg-bubble);
    border: 1px solid var(--bg-bubble-border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-top: 1rem; /* در حالت column-reverse فاصله بین پست‌ها */
    margin-bottom: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.message-content {
    margin-bottom: 0.5rem;
}

.msg-text {
    margin: 0;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.msg-text:not(:first-child) {
    margin-top: 0.5rem;
}

.msg-media {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}

.msg-media + .msg-text {
    margin-top: 0.5rem;
}

.message-bubble video.msg-media,
.message-bubble audio.msg-media {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
}

.message-bubble audio.msg-media {
    height: 40px;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.message-meta {
    gap: 0.5rem;
}

.message-meta .time {
    font-size: 0.8rem;
    color: var(--text-meta);
}

/* سه‌نقطه و منوی ادمین زیر پست (صفحه اصلی کانال) */
.post-actions-channel {
    position: relative;
    margin-right: auto;
}
.post-actions-trigger {
    background: none;
    border: none;
    color: var(--text-meta);
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
}
.post-actions-trigger:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}
.post-actions-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 120px;
    background: var(--bg-bubble);
    border: 1px solid var(--bg-bubble-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 20;
    overflow: hidden;
}
.post-actions-channel.open .post-actions-dropdown {
    display: block;
}
.post-actions-dropdown a,
.post-actions-dropdown button {
    display: block;
    width: 100%;
    text-align: right;
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
}
.post-actions-dropdown a:hover,
.post-actions-dropdown button:hover {
    background: rgba(255,255,255,0.08);
}
.post-actions-dropdown .post-action-delete {
    color: #c07070;
}

/* ریپلای به پست — لینک بالای پست در فید */
.reply-to-link {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    color: var(--text-meta);
    border-right: solid 2px #b5b5b5;
    padding-right: 5px;
    min-height: 25px;
}
.reply-to-link a {
    color: var(--accent);
    text-decoration: none;
}
.reply-to-link a:hover {
    text-decoration: underline;
}

/* بنر ریپلای در صفحه پست جدید (ادمین) */
.reply-to-banner {
    margin: 0 0 1rem 0;
    padding: 0.5rem 0.75rem;
    background: rgba(43, 82, 120, 0.2);
    border: 1px solid var(--accent);
    border-radius: 8px;
    font-size: 0.95rem;
}
.reply-to-banner a {
    color: var(--accent);
    text-decoration: none;
}
.reply-to-banner a:hover {
    text-decoration: underline;
}

/* ----- Empty state ----- */
.empty-feed {
    text-align: center;
    color: var(--text-meta);
    padding: 2rem 1rem;
}

/* ----- Admin panel ----- */
.admin-header {
    background: var(--bg-bubble);
    border-bottom: 1px solid var(--bg-bubble-border);
    margin: -1rem -1rem 1rem -1rem;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.admin-header a,
.admin-header .admin-user {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.95rem;
}

.admin-header a:hover {
    text-decoration: underline;
}

.admin-links {
    display: flex;
    gap: 1rem;
}

.admin-page {
    max-width: 700px;
    margin: 0 auto;
    padding: 1rem;
}

.admin-page h1 {
    font-size: 1.4rem;
    margin-top: 0;
    margin-bottom: 1rem;
}

/* ----- Forms ----- */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-meta);
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 1rem;
    border: 1px solid var(--bg-bubble-border);
    border-radius: 8px;
    background: var(--bg-bubble);
    color: var(--text-primary);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-family: var(--font);
    font-size: 0.95rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    background: var(--accent);
    color: var(--text-primary);
}

.btn:hover {
    filter: brightness(1.1);
}

.btn-danger {
    background: #8b2635;
}

.btn-danger:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--bg-bubble-border);
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-error {
    background: rgba(139, 38, 53, 0.3);
    border: 1px solid #8b2635;
    color: #f0a0a0;
}

.alert-success {
    background: rgba(34, 80, 50, 0.3);
    border: 1px solid #2a5a3a;
    color: #a0d0b0;
}

/* ----- Dashboard table / list ----- */
.post-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.post-list li {
    background: var(--bg-bubble);
    border: 1px solid var(--bg-bubble-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.post-list .post-info {
    flex: 1;
    min-width: 0;
}

.post-list .post-type {
    font-size: 0.8rem;
    color: var(--text-meta);
    margin-bottom: 0.25rem;
}

.post-list .post-preview {
    font-size: 0.95rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.post-list .post-date {
    font-size: 0.8rem;
    color: var(--text-meta);
    margin-top: 0.25rem;
}

.post-list .post-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.post-list .post-actions a,
.post-list .post-actions button {
    font-size: 0.85rem;
}

/* ----- Login page ----- */
.login-box {
    max-width: 360px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: var(--bg-bubble);
    border: 1px solid var(--bg-bubble-border);
    border-radius: 12px;
}

.login-box h1 {
    margin-top: 0;
    margin-bottom: 1.25rem;
    text-align: center;
    font-size: 1.25rem;
}

.login-box .btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* ----- Delete form (inline) ----- */
.delete-form {
    display: inline;
}

.delete-form button {
    background: none;
    border: none;
    font-family: var(--font);
    cursor: pointer;
    color: #c07070;
    padding: 0;
    font-size: inherit;
    text-decoration: underline;
}

.delete-form button:hover {
    color: #e09090;
}
