/* ============================================
   INSTABKHR - Unified Stylesheet
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    color-scheme: light;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-alt: #f7f9fc;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-2: #6b7280;
    --danger: #dc2626;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
}

body.dark-mode {
    --bg: #111827;
    --surface: #1f2937;
    --surface-alt: #111827;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #374151;
    --accent: #60a5fa;
    --accent-2: #9ca3af;
    --danger: #ef4444;
    --shadow: 0 2px 8px rgba(0,0,0,0.35);
    color-scheme: dark;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s ease, color 0.2s ease;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { margin: 0 0 10px; line-height: 1.3; }

/* --- Topbar / Navbar --- */
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar .nav-left,
.topbar .nav-right {
    display: flex;
    gap: 6px;
    align-items: center;
}
.topbar .nav-right { justify-content: flex-end; }
.topbar .brand {
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-align: center;
    color: var(--text);
}
.nav-link {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    border-radius: var(--radius-pill);
    transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); }
.nav-link.active { background: var(--surface-alt); color: var(--accent); }
.nav-link.danger {
    color: #ffffff;
    background: var(--danger);
}
.nav-link.danger:hover { background: #b91c1c; }
.topbar-btn {
    border: 0;
    border-radius: var(--radius-pill);
    padding: 5px 10px;
    background: var(--accent-2);
    color: #fff;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: filter 0.15s ease;
}
.topbar-btn:hover { filter: brightness(0.92); }

/* --- Scaled-down icons across the board --- */
.nav-link i,
.topbar-btn i,
.btn i,
.stat-pill i,
.bio-card i,
.meta i,
.upload-picker i,
.comment-toggle i,
.upload-badge i {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    stroke-width: 2.2;
}

/* --- Page Layout --- */
.page {
    max-width: 760px;
    margin: 0 auto;
    padding: 20px;
}
.page.wide {
    max-width: 1000px;
}
.page.admin-page {
    max-width: 1100px;
}

/* --- Cards & Containers --- */
.card,
.feed-item,
.upload-zone,
.post-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.feed-item,
.upload-zone {
    padding: 16px;
    margin-bottom: 16px;
}
.card {
    padding: 18px;
}

/* --- Flash Messages --- */
.flash-container {
    max-width: 760px;
    margin: 16px auto 0;
    padding: 0 20px;
}
.flash {
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    word-wrap: break-word;
    border: 1px solid;
}
.flash-success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.flash-error { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
.flash-info { background: #d1ecf1; color: #0c5460; border-color: #bee5eb; }

/* --- Typography --- */
.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 14px;
}
.form-title {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 10px;
}

/* --- Forms & Inputs --- */
.form-control {
    font-family: 'Noto Sans', sans-serif;
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-sizing: border-box;
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.9rem;
}
textarea {
    width: 100%;
    min-height: 74px;
    margin-top: 10px;
    box-sizing: border-box;
    padding: 10px;
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Noto Sans', sans-serif;
    font-size: 0.9rem;
    resize: vertical;
}
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 10px;
    margin: 6px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-sizing: border-box;
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.9rem;
}

/* --- Buttons --- */
.btn {
    padding: 7px 14px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-pill);
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(0.95); }
.btn.small { padding: 5px 10px; font-size: 0.78rem; }
.btn.full { width: 100%; }
.danger { background: var(--danger); }
.secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn.liked { background: #e53935; color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Upload Zone --- */
.upload-zone { text-align: center; }
.upload-picker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
    cursor: pointer;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}
.upload-picker input[type="file"] { display: none; }
.upload-actions { display: flex; gap: 8px; margin-top: 10px; }
.progress-track { margin-top: 10px; width: 100%; height: 6px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; display: none; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #00bcd4); transition: width 0.2s ease; }
.progress-text { margin-top: 4px; color: var(--muted); font-size: 0.78rem; }
.pill-text { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

/* --- Post Header & Author --- */
.post-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.author-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }

/* --- Avatars --- */
/* --- Avatars --- */
.avatar, .mini-avatar {
    border-radius: 50% !important; /* Forces them to stay perfect circles */
    object-fit: cover !important;  /* Prevents stretching */
    background: linear-gradient(135deg, var(--accent), #38bdf8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    border: 2px solid var(--border);
    flex-shrink: 0 !important;     /* Prevents flexbox from squishing them into ovals */
}
.avatar {
    width: 40px !important;        /* Forces strict width */
    height: 40px !important;       /* Forces strict height */
    font-size: 0.85rem;
}
.mini-avatar {
    width: 28px !important;        /* Forces strict width */
    height: 28px !important;       /* Forces strict height */
    font-size: 0.7rem;
}

/* --- Feed & Post Images --- */
.feed-item img:not(.avatar):not(.mini-avatar),
.post-main-image,
.post-card img:not(.avatar):not(.mini-avatar) {
    max-width: 100%;
    border-radius: 12px;
    height: auto;
    display: block;
    margin-top: 10px;
    object-fit: contain;
}
body.uniform-image-size .feed-item img,
body.uniform-image-size .post-main-image,
body.uniform-image-size .post-card img {
    height: 320px;
    object-fit: cover;
}

/* --- Caption --- */
.caption { margin-top: 10px; color: var(--text); white-space: pre-wrap; line-height: 1.6; }
.caption.empty { color: var(--muted); font-style: italic; }
.caption p { margin: 0 0 8px; }
.caption p:last-child { margin-bottom: 0; }
.caption ul, .caption ol { margin: 4px 0; padding-left: 20px; }
.caption pre { background: var(--surface-alt); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; margin: 8px 0; }
.caption code { background: var(--surface-alt); padding: 2px 5px; border-radius: 4px; font-size: 0.85rem; }
.caption pre code { background: none; padding: 0; }
.caption a { color: var(--accent); text-decoration: underline; }
.caption strong { font-weight: 700; }
.caption em { font-style: italic; }

/* --- Actions Bar --- */
.actions { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

/* --- Markdown Toolbar --- */
.md-toolbar {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
    padding: 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}
.md-toolbar button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 4px 7px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: background 0.15s, color 0.15s;
}
.md-toolbar button:hover {
    background: var(--border);
    color: var(--text);
}
.md-toolbar button i { width: 12px; height: 12px; }
.md-toolbar .separator {
    width: 1px;
    background: var(--border);
    margin: 0 3px;
}

/* --- Comment System --- */
.comment-form { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.comment-input {
    flex: 1;
    min-width: 140px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 7px 12px;
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.85rem;
}
.comment-list { margin-top: 10px; display: grid; gap: 6px; }
.comment-item {
    padding: 10px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.comment-author { display: flex; gap: 8px; align-items: flex-start; flex: 1; min-width: 0; }
.comment-body { min-width: 0; flex: 1; }
.comment-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.comment-content { white-space: pre-wrap; line-height: 1.5; color: var(--text); font-size: 0.88rem; }
.comment-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.comment-toggle { margin-top: 12px; }
.comment-toggle summary { cursor: pointer; font-weight: 700; color: var(--accent); font-size: 0.88rem; }
.comment-toggle[open] summary { margin-bottom: 8px; }
.comments-dropdown { margin-top: 12px; }
.comments-dropdown summary { cursor: pointer; font-weight: 700; color: var(--accent); font-size: 0.88rem; }
.comments-dropdown[open] summary { margin-bottom: 8px; }

/* --- Profile Page --- */
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar.large {
    width: 68px;
    height: 68px;
    font-size: 1.2rem;
}
.profile-name { font-size: 1.2rem; font-weight: 700; }
.profile-handle { color: var(--muted); font-size: 0.88rem; }
.bio-card {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: var(--surface-alt);
    margin: 10px 0 16px;
}
.bio-card i { color: var(--accent); margin-top: 2px; }
.bio-card .bio-text { color: var(--muted); line-height: 1.6; font-size: 0.88rem; }
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.82rem;
}
.post-list { display: grid; gap: 14px; }
.post-card { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; display: flex; align-items: center; gap: 5px; }
.meta i { width: 13px; height: 13px; }

/* --- Account Page --- */
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; font-weight: 700; font-size: 0.88rem; }
.field input,
.field textarea { width: 100%; padding: 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); box-sizing: border-box; background: var(--surface-alt); color: var(--text); font-size: 0.9rem; }
.field textarea { min-height: 90px; resize: vertical; }
.avatar-preview {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 10px;
    border: 2px solid var(--border);
}
.upload-shell {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 10px;
    background: var(--surface-alt);
    margin-bottom: 12px;
    cursor: pointer;
}
.upload-shell input[type="file"] { display: none; }
.upload-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
}
.upload-copy { display: flex; flex-direction: column; gap: 1px; }
.upload-copy strong { font-size: 0.88rem; }
.upload-copy span { color: var(--muted); font-size: 0.8rem; }

/* --- Login / Register Forms --- */
.auth-card {
    min-height: calc(100vh - 60px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.auth-card .card {
    width: 100%;
    max-width: 340px;
    padding: 28px;
}
.auth-card .card h2 {
    font-size: 1.2rem;
    margin-bottom: 14px;
}
.auth-card .card input {
    width: 100%;
    padding: 10px;
    margin: 6px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-sizing: border-box;
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.9rem;
}
.auth-card .card button[type="submit"] {
    width: 100%;
    padding: 10px;
    margin-top: 8px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}
.auth-card .link {
    display: block;
    margin-top: 12px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--accent);
}

/* --- Gallery Grid --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}
.grid-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
    position: relative;
    border: 1px solid var(--border);
}
.grid-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}
body.uniform-image-size .grid-item img {
    height: 260px;
    object-fit: cover;
}
.info-overlay {
    padding: 10px;
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--surface);
    border-top: 1px solid var(--border);
}

/* --- Admin Dashboard --- */
.admin-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.admin-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}
.admin-section {
    margin-bottom: 28px;
}
.admin-section-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.admin-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.85rem;
}
.admin-table th,
.admin-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.admin-table th {
    background: var(--surface-alt);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr:hover td { background: var(--surface-alt); }
.admin-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
}
.admin-badge.admin { background: #7c3aed; }
.admin-post-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.admin-post-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface-alt);
}
.admin-post-info {
    flex: 1;
    min-width: 0;
}
.admin-post-meta {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 4px;
}
.admin-post-caption {
    font-size: 0.85rem;
    white-space: pre-wrap;
    max-height: 60px;
    overflow: hidden;
}
.reset-form {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.reset-form input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.78rem;
    background: var(--surface-alt);
    color: var(--text);
    text-align: center;
}
.reset-form button {
    padding: 4px 8px;
}

/* --- Responsive Design --- */

/* Tablet */
@media (max-width: 768px) {
    .topbar { padding: 10px 16px; }
    .page { padding: 16px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
    .admin-table th,
    .admin-table td { padding: 8px 10px; font-size: 0.8rem; }
}

/* Mobile */
@media (max-width: 600px) {
    .topbar {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 8px 14px;
    }
    .topbar .nav-left,
    .topbar .nav-right {
        justify-content: center;
        flex-wrap: wrap;
        gap: 4px;
    }
    .topbar .brand {
        order: -1;
        margin-bottom: 2px;
        font-size: 0.9rem;
    }
    .nav-link .btn-label { display: none; }
    .nav-link { padding: 5px 8px; font-size: 0; gap: 0; }
    .nav-link i { width: 16px; height: 16px; }
    .topbar-btn .btn-label { display: none; }
    .topbar-btn { padding: 6px 8px; font-size: 0; gap: 0; }
    .topbar-btn i { width: 16px; height: 16px; }
    .page { padding: 12px; }
    .page.admin-page { padding: 12px; }
    .feed-item,
    .upload-zone,
    .card { padding: 12px; }
    .actions,
    .upload-actions,
    .comment-form { flex-direction: column; align-items: stretch; }
    .btn { width: 100%; }
    .comment-input { width: 100%; }
    .comment-actions { flex-direction: column; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
    .grid-item img { height: 150px; }
    .admin-table-wrap { font-size: 0.78rem; }
    .admin-post-item { flex-direction: column; }
    .admin-post-thumb { width: 100%; height: 120px; }
    .auth-card .card { padding: 20px; }
    .flash-container { padding: 0 12px; }
    .reset-form { flex-wrap: wrap; }
}

/* Small mobile */
@media (max-width: 380px) {
    .topbar .nav-left { gap: 2px; }
    .topbar .nav-right { gap: 2px; }
    .brand { font-size: 0.8rem !important; }
    .avatar { width: 36px; height: 36px; font-size: 0.78rem; }
}
