/**
 * JUZKO Forum - Main Stylesheet
 * Modern, dark, minimal design
 */

/* ==================== CSS Variables ==================== */
:root {
    /* Colors — Unified with Library/Keyshop palette */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1a1f27;
    --bg-card: #161b22;
    --bg-hover: #1f242c;

    --text-primary: #f0f6fc;
    --text-secondary: #a0a0a0;
    --text-muted: #8b949e;

    --accent: #58a6ff;
    --accent-hover: #4a9eff;
    --accent-dim: rgba(88, 166, 255, 0.15);

    --danger: #ff4757;
    --warning: #ffa502;
    --success: #2ed573;
    --info: #3498db;

    --border-color: #30363d;
    --border-light: #3a424b;

    /* Rank colors — used by .user-rank-* helpers on wrappers to drive
       avatar border / accent colors. Mirrors the badge color in rank-class
       CSS below so the "premium frame" matches the badge text color. */
    --rank-color-admin: var(--danger);    /* red  #ff4757 */
    --rank-color-mod:   var(--accent);    /* blue #58a6ff */
    --rank-color-elite: #ffd700;          /* gold */
    --rank-color-user:  var(--border-color);

    /* Typography */
    --font-main: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Sizing */
    --sidebar-width: 280px;
    --header-height: 48px;
    --border-radius: 0px;
    --border-radius-sm: 0px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    /* Transitions */
    --transition: 0.2s ease;
}

/* ==================== Reset & Base ==================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* ==================== Layout ==================== */
.wrapper {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

.main-container {
    display: flex;
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    gap: 20px;
}

.content {
    flex: 1;
    min-width: 0;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
}

/* ==================== Header (now handled by shared topbar) ==================== */
/* Old .header removed — unified topbar.php is used instead */

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    color: var(--accent);
    font-size: 1.8rem;
}

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

.nav-link {
    padding: 8px 16px;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-weight: 500;
    transition: all var(--transition);
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.user-name {
    font-weight: 500;
    color: var(--text-primary);
}

.user-profile-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: opacity var(--transition);
}

.user-profile-link:hover {
    opacity: 0.8;
}

.user-profile-link:hover .user-name {
    color: var(--accent);
}

.admin-icon {
    font-size: 1.4rem;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.admin-icon:hover {
    opacity: 1;
}

.header-icon-btn {
    font-size: 1.5rem;
    text-decoration: none;
    opacity: 0.8;
    transition: opacity var(--transition), transform var(--transition);
    padding: 4px;
}

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



/* ==================== Footer ==================== */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer a {
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--accent);
}

/* ==================== Cards ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.card-header {
    background: var(--bg-tertiary);
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 20px;
}

/* ==================== Buttons ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: #000;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #000;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #ff6b7a;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* ==================== Forms ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: all var(--transition);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

/* ==================== Alerts (Toast-style) ==================== */
.alert {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 1000;
    padding: 15px 20px;
    border-radius: var(--border-radius);
    border-left: 4px solid;
    box-shadow: var(--shadow-lg);
    animation: alertSlideIn 0.3s ease, alertFadeOut 0.5s ease 4s forwards;
    max-width: 400px;
}

.alert-success {
    background: rgba(46, 213, 115, 0.95);
    border-color: var(--success);
    color: #000;
}

.alert-error {
    background: rgba(255, 71, 87, 0.95);
    border-color: var(--danger);
    color: #fff;
}

.alert-warning {
    background: rgba(255, 165, 2, 0.95);
    border-color: var(--warning);
    color: #000;
}

.alert-info {
    background: rgba(52, 152, 219, 0.95);
    border-color: var(--info);
    color: #fff;
}

@keyframes alertSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes alertFadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* ==================== Forum List ==================== */
.category {
    margin-bottom: 30px;
}

.category-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-left: 4px;
}

.forum-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.forum-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto 180px;
    gap: 20px;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: all var(--transition);
}

.forum-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.forum-icon {
    width: 44px;
    height: 44px;
    background: var(--accent-dim);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 1.2rem;
}

.forum-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.forum-info h3 a {
    color: var(--text-primary);
}

.forum-info h3 a:hover {
    color: var(--accent);
}

.forum-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.forum-stats {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.forum-stats strong {
    display: block;
    color: var(--text-primary);
    font-size: 1rem;
}

.forum-last-post {
    font-size: 0.8rem;
    color: var(--text-muted);
    max-width: 180px;
}

.forum-last-post a {
    color: var(--text-secondary);
}

/* ==================== Topic List ==================== */
.topic-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 2px;
}

.topic-item:hover {
    background: var(--bg-hover);
}

.topic-author-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.topic-title {
    font-weight: 500;
}

.topic-title a {
    color: var(--text-primary);
}

.topic-title a:hover {
    color: var(--accent);
}

.topic-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.topic-badges {
    display: flex;
    gap: 6px;
}

.badge {
    padding: 3px 8px;
    border-radius: var(--border-radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-pinned {
    background: var(--accent-dim);
    color: var(--accent);
}

.badge-locked {
    background: rgba(255, 71, 87, 0.15);
    color: var(--danger);
}

/* ==================== Posts ==================== */
.post {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.post-author {
    background: var(--bg-tertiary);
    padding: 20px;
    text-align: center;
    border-right: 1px solid var(--border-color);
}

.post-author-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
}

.post-author-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.post-author-rank {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: var(--border-radius-sm);
    display: inline-block;
}

.rank-admin {
    background: rgba(255, 71, 87, 0.15);
    color: var(--danger);
}

.rank-mod {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

.rank-user {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.rank-elite {
    background: rgba(255, 215, 0, 0.15);
    color: #ffd700;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.3);
}

.post-author-posts {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 10px;
}

.post-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.post-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.post-actions {
    display: flex;
    gap: 8px;
}

.post-action {
    padding: 4px 8px;
    border-radius: var(--border-radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.post-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.post-body {
    flex: 1;
    line-height: 1.7;
}

.post-body p {
    margin-bottom: 1em;
}

.post-body p:last-child {
    margin-bottom: 0;
}

/* Spoiler */


.sidebar-widget {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    overflow: hidden;
}

.sidebar-widget-title {
    background: var(--bg-tertiary);
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-widget-body {
    padding: 16px;
}

.shoutbox-frame {
    width: 100%;
    height: 400px;
    border: none;
    border-radius: var(--border-radius-sm);
}

/* ==================== Pagination ==================== */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
}

.pagination a,
.pagination span {
    padding: 8px 14px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pagination a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.pagination .active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
}

/* ==================== Utilities ==================== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-muted);
}

.text-accent {
    color: var(--accent);
}

.mt-1 {
    margin-top: 8px;
}

.mt-2 {
    margin-top: 16px;
}

.mt-3 {
    margin-top: 24px;
}

.mb-1 {
    margin-bottom: 8px;
}

.mb-2 {
    margin-bottom: 16px;
}

.mb-3 {
    margin-bottom: 24px;
}

.d-flex {
    display: flex;
}

.gap-1 {
    gap: 8px;
}

.gap-2 {
    gap: 16px;
}

.justify-between {
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

/* ==================== Admin Panel Responsive ==================== */

/* ---------- Admin: Tablet / Phone (≤ 768px) ---------- */
@media (max-width: 768px) {

    /* Sidebar → horizontal top nav */
    .admin-layout {
        grid-template-columns: 1fr !important;
    }

    .admin-sidebar {
        border-right: none !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding: 12px 0 !important;
    }

    .admin-sidebar-header {
        padding: 0 16px 10px !important;
        margin-bottom: 10px !important;
    }

    .admin-sidebar-header h2 {
        font-size: 0.9rem !important;
    }

    .admin-sidebar-header p {
        display: none;
    }

    .admin-nav {
        display: flex !important;
        flex-wrap: wrap;
        gap: 4px;
        padding: 0 12px;
    }

    .admin-nav a {
        padding: 8px 12px !important;
        font-size: 0.82rem;
        border-left: none !important;
        border-radius: var(--border-radius);
        white-space: nowrap;
    }

    .admin-nav a.active {
        border-left: none !important;
        background: var(--accent-dim) !important;
        color: var(--accent) !important;
    }

    /* "Back to forum" link — inline with other nav items */
    .admin-nav a[style*="margin-top"] {
        margin-top: 0 !important;
        border-top: none !important;
        padding-top: 8px !important;
    }

    /* Admin content — full width, tighter padding */
    .admin-content {
        padding: 16px !important;
    }

    .admin-content h1 {
        font-size: 1.3rem;
        margin-bottom: 16px !important;
    }

    /* Stat grid — 2 columns on phone */
    .stat-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .stat-card {
        padding: 14px !important;
    }

    .stat-card-value {
        font-size: 1.5rem !important;
    }

    .stat-card-label {
        font-size: 0.78rem !important;
    }

    /* Dashboard 2-column grid → stack */
    .admin-content>div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Admin tables — horizontal scroll wrapper */
    .admin-content table {
        min-width: 600px;
    }

    .admin-content .card-body[style*="overflow-x"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Forms — stack grid columns */
    .admin-content div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Buttons row — wrap */
    .admin-content .d-flex.gap-1 {
        flex-wrap: wrap;
    }
}

/* ---------- Admin: smaller phone (≤ 480px) ---------- */
@media (max-width: 480px) {

    .admin-nav a {
        padding: 6px 10px !important;
        font-size: 0.78rem;
    }

    .admin-content {
        padding: 12px !important;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .stat-card {
        padding: 10px !important;
    }

    .stat-card-value {
        font-size: 1.3rem !important;
    }
}

/* ==================== Responsive ==================== */

/* ---------- Tablet / small desktop (≤ 1024px) ---------- */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        order: -1;
    }
}

/* ---------- Tablet / large phone (≤ 768px) ---------- */
@media (max-width: 768px) {

    /* --- Header / Navigation --- */
    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 15px;
        gap: 10px;
    }

    .nav {
        order: 3;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .nav-link {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    /* --- Main container --- */
    .main-container {
        padding: 12px;
        gap: 12px;
    }

    /* --- Forum list (index.php) — IPBoard compact rows --- */
    .forum-item {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 12px;
        padding: 12px 14px;
    }

    .forum-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        display: flex;
        flex-shrink: 0;
    }

    .forum-info {
        flex: 1 1 0;
        min-width: 0;
    }

    .forum-info h3 {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .forum-description {
        font-size: 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Stats row — both stats appear inline after the main row */
    .forum-stats {
        display: inline-flex;
        align-items: baseline;
        gap: 3px;
        text-align: left;
        font-size: 0.78rem;
        color: var(--text-muted);
    }

    /* First stat aligns under text (after 36px icon + 12px gap) */
    .forum-item>.forum-stats:first-of-type {
        padding-left: 48px;
        margin-left: -12px;
    }

    .forum-stats strong {
        display: inline;
        margin-right: 2px;
        font-size: 0.82rem;
    }

    .forum-last-post {
        display: none;
    }

    /* --- Topic list (forum.php) — card layout --- */
    .card>div[style*="overflow-x"] {
        overflow-x: visible;
    }

    .card table {
        width: 100%;
    }

    .card table thead {
        display: none;
    }

    .card table tbody {
        display: flex;
        flex-direction: column;
    }

    .card table tbody tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 14px;
        column-gap: 12px;
        row-gap: 4px;
        border-bottom: 1px solid var(--border-color);
    }

    .card table tbody tr:last-child {
        border-bottom: none;
    }

    /* Topic TD — full width, avatar + title row */
    .card table tbody td:first-child {
        flex: 1 1 100%;
        padding: 0 !important;
    }

    /* Replies TD — inline badge */
    .card table tbody td:nth-child(2) {
        padding: 0 !important;
        font-size: 0.8rem;
        text-align: left;
        width: auto;
        min-width: auto;
    }

    .card table tbody td:nth-child(2)::before {
        content: "💬 ";
    }

    /* Last post TD — inline */
    .card table tbody td:nth-child(3) {
        padding: 0 !important;
        font-size: 0.78rem;
        width: auto;
        min-width: auto;
        margin-left: auto;
    }

    /* Topic avatar in table */
    .card table tbody td img[style*="border-radius: 50%"] {
        width: 32px !important;
        height: 32px !important;
    }

    /* --- Posts — stacked with horizontal author bar --- */
    .post {
        grid-template-columns: 1fr;
    }

    .post-author {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
    }

    .post-author-avatar {
        width: 40px;
        height: 40px;
        margin-bottom: 0;
    }

    .post-author-posts {
        display: none;
    }

    .post-content {
        padding: 14px 16px;
    }

    .post-header {
        font-size: 0.8rem;
        padding-bottom: 8px;
        margin-bottom: 8px;
    }

    .post-body {
        font-size: 0.95rem;
    }


    /* --- Category title --- */
    .category-title {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }

    /* --- Card header --- */
    .card-header {
        padding: 12px 14px;
        font-size: 0.9rem;
    }

    /* --- Pagination --- */
    .pagination {
        flex-wrap: wrap;
        gap: 3px;
    }

    .pagination a,
    .pagination span {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    /* --- Breadcrumb --- */
    nav[style*="margin-bottom: 20px"] {
        font-size: 0.82rem !important;
        margin-bottom: 12px !important;
    }

    /* --- Topic header flex --- */
    .d-flex.justify-between.align-center.mb-2 {
        gap: 8px;
    }

    .d-flex.justify-between.align-center.mb-2 h1 {
        font-size: 1.25rem;
    }

    /* --- Buttons --- */
    .btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}

/* ---------- Big phone + tablet (380–768px) — pokaż last-post + stats w siatce ---------- */
@media (min-width: 380px) and (max-width: 768px) {

    .forum-item {
        display: grid;
        grid-template-columns: auto 1fr auto 120px;
        grid-template-rows: auto auto;
        gap: 4px 14px;
        align-items: center;
        padding: 12px 14px;
    }

    .forum-icon {
        grid-column: 1;
        grid-row: 1 / span 2;
        align-self: center;
    }

    .forum-info {
        grid-column: 2 / span 2;
        grid-row: 1;
        min-width: 0;
    }

    /* Stats — wrocą do siatki w row 2 (override mobile padding/margin) */
    .forum-item > .forum-stats:first-of-type {
        grid-column: 2;
        grid-row: 2;
        padding-left: 0 !important;
        margin-left: 0 !important;
        text-align: left;
    }

    .forum-item > .forum-stats:nth-of-type(2) {
        grid-column: 3;
        grid-row: 2;
        text-align: left;
    }

    /* Last post wraca z niebytu, prawa kolumna, pełna wysokość */
    .forum-last-post {
        display: block;
        grid-column: 4;
        grid-row: 1 / span 2;
        max-width: 120px;
        font-size: 0.7rem;
        line-height: 1.3;
        align-self: center;
        text-align: right;
    }

    .forum-last-post a {
        display: inline-block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: bottom;
    }
}

/* ---------- Phone (≤ 480px) ---------- */
@media (max-width: 480px) {

    /* Tighter main container */
    .main-container {
        padding: 8px;
        gap: 8px;
    }

    /* Page title */
    h1 {
        font-size: 1.2rem !important;
        margin-bottom: 16px !important;
    }

    /* Forum list — hide stats and description */
    .forum-stats {
        display: none !important;
    }

    .forum-description {
        display: none !important;
    }

    .forum-item {
        grid-template-rows: auto;
        padding: 10px 12px;
    }

    /* Topic list — more compact */
    .card table tbody tr {
        padding: 10px 12px;
        gap: 6px;
    }

    .card table tbody td img[style*="border-radius: 50%"] {
        width: 28px !important;
        height: 28px !important;
    }

    /* Topic title font */
    .card table tbody td:first-child a[style*="font-weight: 500"] {
        font-size: 0.9rem;
    }

    /* Topic meta */
    .card table tbody td:first-child .text-muted {
        font-size: 0.75rem;
    }

    /* Posts — tighter */
    .post-author {
        padding: 10px 12px;
        gap: 10px;
    }

    .post-author-avatar {
        width: 36px;
        height: 36px;
    }

    .post-content {
        padding: 12px;
    }

    .post-body {
        font-size: 0.9rem;
        line-height: 1.6;
    }


    /* Card body */
    .card-body {
        padding: 14px;
    }

    /* Footer */
    .footer {
        padding: 14px 12px;
        font-size: 0.8rem;
    }

    /* Category */
    .category {
        margin-bottom: 20px;
    }

    /* Badges */
    .badge {
        padding: 2px 6px;
        font-size: 0.65rem;
    }

    /* Post actions */
    .post-actions {
        gap: 4px;
    }

    .post-action {
        padding: 3px 6px;
        font-size: 0.75rem;
    }
}

/* ---------- Tiny phone / iPhone SE 2016 (≤ 360px) ---------- */
@media (max-width: 360px) {

    /* Tightest container */
    .main-container {
        padding: 6px;
        gap: 6px;
    }

    /* Page title */
    h1 {
        font-size: 1.1rem !important;
    }

    /* Forum items — compact */
    .forum-icon {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }

    .forum-item {
        grid-template-columns: 28px 1fr;
        padding: 8px 10px;
        gap: 3px 8px;
    }

    .forum-info h3 {
        font-size: 0.88rem;
    }

    /* Topic list — max compact */
    .card table tbody tr {
        padding: 8px 10px;
    }

    .card table tbody td img[style*="border-radius: 50%"] {
        width: 24px !important;
        height: 24px !important;
    }

    .card table tbody td:nth-child(3) {
        display: none;
    }

    /* Posts */
    .post-author-avatar {
        width: 32px;
        height: 32px;
    }

    .post-author-name {
        font-size: 0.85rem;
    }

    .post-author-rank {
        font-size: 0.68rem;
        padding: 1px 6px;
    }

    .post-content {
        padding: 10px;
    }

    .post-body {
        font-size: 0.85rem;
        line-height: 1.55;
    }

    .post-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    /* Card header */
    .card-header {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    /* Card body */
    .card-body {
        padding: 10px;
    }

    /* Breadcrumb */
    nav[style*="margin-bottom: 20px"] {
        font-size: 0.78rem !important;
        margin-bottom: 8px !important;
    }

    /* Pagination — smaller */
    .pagination a,
    .pagination span {
        padding: 5px 8px;
        font-size: 0.78rem;
    }

    /* Buttons */
    .btn {
        padding: 7px 12px;
        font-size: 0.8rem;
    }

    .btn-sm {
        padding: 4px 8px;
        font-size: 0.72rem;
    }


    /* Footer */
    .footer {
        padding: 12px 8px;
        font-size: 0.75rem;
    }

    /* Hide username on tiny screens */
    .hide-on-tiny {
        display: none !important;
    }

    .logo span:not(.logo-icon) {
        display: none;
    }

    .user-menu {
        gap: 8px;
    }

    /* Alerts — full width on tiny */
    .alert {
        right: 6px;
        left: 6px;
        max-width: none;
        font-size: 0.85rem;
    }
}

/* ==================== Online User Links ==================== */
.online-user {
    text-decoration: none;
    transition: all var(--transition);
}

.online-user:hover {
    text-decoration: underline;
}

/* Admin users in online list */
.online-user.rank-admin {
    color: var(--danger);
}

.online-user.rank-admin:hover {
    color: #ff6b7a;
}

/* Mod users in online list */
.online-user.rank-mod {
    color: var(--accent);
}

.online-user.rank-mod:hover {
    color: var(--accent-hover);
}

/* Regular users in online list */
.online-user.rank-user {
    color: var(--text-secondary);
}

.online-user.rank-user:hover {
    color: var(--accent);
}

/* Elite users in online list */
.online-user.rank-elite {
    color: #ffd700;
    font-weight: 700;
}

.online-user.rank-elite:hover {
    color: #ffe44d;
}

/* @mentions */
.mention {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
    background: rgba(0, 212, 170, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
}
.mention:hover {
    background: rgba(0, 212, 170, 0.18);
    color: #00f0c0;
}

/* ==================== Rank-coloured avatar frames ====================
   Drop a .user-rank-{admin,mod,elite,user} class on any wrapper that
   contains an avatar (.post-author for forum posts, .profile-avatar-frame
   for the profile card). The avatar pulls border colour from --rank-color
   set by these helpers; if no rank class is set, the avatar falls back to
   --border-color as before.

   Precedence (matches the badge system): Elite > Admin > Mod > User. The
   PHP side picks the right class via rank_class()-style logic.
   =====================================================================*/

.user-rank-admin { --rank-color: var(--rank-color-admin); }
.user-rank-mod   { --rank-color: var(--rank-color-mod);   }
.user-rank-elite { --rank-color: var(--rank-color-elite); }
.user-rank-user  { --rank-color: var(--rank-color-user);  }

/* Forum post avatar (.post-author wraps the <img>). */
.post-author-avatar {
    border-color: var(--rank-color, var(--border-color));
}
/* Elite gets the same soft halo the library drawer uses, for parity. */
.user-rank-elite .post-author-avatar {
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.15);
}

/* Profile card avatar. Markup in profile.php was inline-styled; the wrapper
   div now carries .profile-avatar-frame + a .user-rank-* class, and the
   <img> inside uses .profile-avatar so we can target it from CSS. */
.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: contain;
    border: 2px solid var(--rank-color, var(--border-color));
    margin-bottom: 16px;
    transition: border-color 0.2s ease;
}
.user-rank-elite .profile-avatar {
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.15);
}

/* Profile card avatar wrapper — replaces the old inline `display:inline-block`.
   Lives on the <div> emitted by avatar_rank_attrs($user, 'profile-avatar-frame'). */
.profile-avatar-frame {
    display: inline-block;
    line-height: 0; /* avoid the extra baseline gap under the rounded <img> */
}

/* Custom-group users (display_group_id set) — colour is delivered inline as
   `--rank-color: #xxx` by avatar_rank_attrs(). This class exists so we can
   add optional polish (e.g. subtle halo) without per-group selectors. */
.user-rank-group {
    /* Tint the avatar ring with a low-alpha halo of the group colour. */
}
.user-rank-group .post-author-avatar,
.user-rank-group .profile-avatar,
.user-rank-group .self-avatar {
    /* color-mix is widely supported in evergreen browsers; falls back to
       a flat ring on older Safari/Chromium without breaking layout. */
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--rank-color) 18%, transparent);
}
