/*
  styles.css — SLIM
  Only what Tailwind CDN cannot express:
  - CSS custom properties for JS theme-switching
  - JS-toggled state classes (.show, .active, .liked, .loaded)
  - Chat bubble shapes
  - Skeleton shimmer
  - Animations referenced by name
  - Safe-area bottom utility
  Everything else → Tailwind utility classes in the markup.
*/

/* ── Design tokens (readable by JS theme.js) ────────────────── */
:root {
    --accent:        #00d4aa;
    --accent-rgb:    0, 212, 170;
    --bg:            #0c0e14;
    --bg-2:          #13151f;
    --bg-3:          #1c1f2e;
    --ink:           #eceef5;
    --ink-muted:     #6b7099;
    --border:        rgba(255,255,255,0.07);
    --border-hi:     rgba(255,255,255,0.13);
    --danger:        #f05070;
    --ok:            #22c55e;
    --warn:          #f59e0b;
    /* Aliases for legacy JS references */
    --warning-color: #f59e0b;
    --error-color:   #f05070;
    --text-secondary:#6b7099;
}

/* ── Theme variants ──────────────────────────────────────────── */
/* theme.js sets --accent-color on :root when user picks a custom accent.
   If no custom accent is set, the theme class's --accent value below wins.
   If a custom accent IS set, the JS also sets --accent directly on :root
   so it cascades through to all consumers. */

body.theme-dark {
    --bg:        #0c0e14;
    --bg-2:      #13151f;
    --bg-3:      #1c1f2e;
    --ink:       #eceef5;
    --ink-muted: #6b7099;
    --border:    rgba(255,255,255,0.07);
    --border-hi: rgba(255,255,255,0.13);
}
body.theme-amoled {
    --bg:        #000000;
    --bg-2:      #0a0a0a;
    --bg-3:      #111111;
    --ink:       #f0f2f8;
    --ink-muted: #5a6080;
    --border:    rgba(255,255,255,0.05);
    --border-hi: rgba(255,255,255,0.10);
}
body.theme-light {
    --bg:        #f0f2f7;
    --bg-2:      #ffffff;
    --bg-3:      #e8eaf0;
    --ink:       #1a1c28;
    --ink-muted: #6b7280;
    --border:    rgba(0,0,0,0.08);
    --border-hi: rgba(0,0,0,0.15);
}
body.theme-sepia {
    --bg:        #f2e8d6;
    --bg-2:      #eae0cc;
    --bg-3:      #ddd4bc;
    --ink:       #4a3728;
    --ink-muted: #8b7355;
    --border:    rgba(0,0,0,0.09);
    --border-hi: rgba(0,0,0,0.16);
}

/* ── Base ───────────────────────────────────────────────────── */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }

/* Safe-area bottom padding for nav-aware containers */
.pb-safe { padding-bottom: max(80px, calc(70px + env(safe-area-inset-bottom))); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* ── Toast states (toggled by JS) ───────────────────────────── */
.toast { transform: translateY(16px); opacity: 0; transition: all .25s ease; pointer-events: none; }
.toast.show { transform: translateY(0); opacity: 1; pointer-events: auto; }

.post-detail-main {
    /* Clear both 70px Nav + ~60px Comment Bar + Safe Area */
    padding-bottom: calc(130px + env(safe-area-inset-bottom));
}

.reply-line { 
    width: 3px; 
    align-self: stretch; /* Takes full height of the parent container */
    background: var(--accent); 
    border-radius: 2px; 
    flex-shrink: 0; 
}

/* ── Post card liked state ──────────────────────────────────── */
.like-btn.liked i { color: var(--danger); }
.like-btn.liked { color: var(--danger); }

/* ── Nav active dot (JS sets .active) ──────────────────────── */
.nav-item.active { color: var(--accent) !important; }

/* ── Code inputs ────────────────────────────────────────────── */
.code-input.error   { border-color: var(--danger) !important; animation: shake .4s ease; }
.code-input.success { border-color: var(--ok) !important; }
.code-input::-webkit-outer-spin-button,
.code-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.code-input[type=number] { -moz-appearance: textfield; }

/* ── Chat bubble shapes (legacy, overridden by pages.css) ──────── */
.message-bubble-in {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 4px 18px 18px 18px;
    color: var(--ink);
}
.message-bubble-out {
    background: #0e3331;
    border: 1px solid rgba(var(--accent-rgb), .2);
    border-radius: 18px 4px 18px 18px;
    color: var(--ink);
}

/* ── Skeleton shimmer ───────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes shimmer   { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
@keyframes fadeSlideIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
@keyframes shake     { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-5px)} 40%,80%{transform:translateX(5px)} }
@keyframes spin      { to{transform:rotate(360deg)} }
@keyframes pulse     { 0%,100%{opacity:1} 50%{opacity:.45} }
@keyframes typingBounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-7px)} }
@keyframes slideUp   { from{opacity:0;transform:translateY(40px)} to{opacity:1;transform:translateY(0)} }
@keyframes fadeIn    { from{opacity:0} to{opacity:1} }

/* ── Loading spinner ────────────────────────────────────────── */
.loading-spinner {
    border-radius: 50%;
    border: 2.5px solid var(--bg-3);
    border-top-color: var(--accent);
    animation: spin .7s linear infinite;
}
.loading-spinner.small  { width:18px; height:18px; border-width:2px; }
.loading-spinner.medium { width:36px; height:36px; }
.loading-spinner.large  { width:52px; height:52px; border-width:3px; }

/* ── Bottom sheet modal (JS adds .open) ─────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.72);
    backdrop-filter: blur(12px);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 9999;
    animation: fadeIn .2s ease;
}
.modal-container {
    width: 100%; max-width: 600px; max-height: 90vh;
    background: var(--bg-2);
    border: 1px solid var(--border-hi);
    border-radius: 22px 22px 0 0;
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -8px 40px rgba(0,0,0,.6);
    animation: slideUp .32s cubic-bezier(.32,1,.3,1);
}
.modal-container::before {
    content: ''; display: block;
    width: 36px; height: 4px;
    background: var(--bg-3); border-radius: 2px;
    margin: 12px auto 0; flex-shrink: 0;
}
@media (min-width:640px) {
    .modal-overlay { align-items: center; }
    .modal-container { border-radius: 22px; max-width: 480px; }
    .modal-container::before { display: none; }
}

/* ── Pull-to-refresh indicator ──────────────────────────────── */
.ptr-indicator {
    position: fixed; top: -56px; left: 0; right: 0; height: 56px;
    background: var(--accent); color: #071a16;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    font-size: .88rem; font-weight: 600; z-index: 9998;
    transition: transform .2s ease;
}
.ptr-indicator.refreshing { transform: translateY(56px); }
.ptr-indicator.refreshing .ptr-icon { animation: spin 1s linear infinite; }

/* ── Typing dots ────────────────────────────────────────────── */
.typing-dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: typingBounce 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

/* ── Theme-aware scrollbar ──────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

#chat-page {
    height: 100vh;
    /* Subtract the height of your bottom-nav (70px) */
    padding-bottom: 70px; 
}

/* Adjust for mobile safe areas (notches) */
@supports (padding: env(safe-area-inset-bottom)) {
    #chat-page {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}

/* Ensure the message input stays visible and doesn't shrink */
.message-input-area {
    background: var(--bg-2);
    z-index: 40; /* Sit below header (40) but above content */
}

/* ── Ensure messages list is a flex column (pages.css has full chat CSS) ── */
/* ── View Transitions ────────────────────────────────────────── */
@keyframes vt-fade-in  { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
@keyframes vt-fade-out { from { opacity:1; transform:none; } to { opacity:0; transform:translateY(-4px); } }
::view-transition-old(root) { animation: vt-fade-out .18s ease forwards; }
::view-transition-new(root) { animation: vt-fade-in  .22s ease forwards; }

/* ── Back-to-top button ──────────────────────────────────────── */
.back-to-top {
    position: fixed;
    bottom: calc(84px + env(safe-area-inset-bottom));
    right: 18px;
    z-index: 9990;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--bg-2);
    border: 1px solid var(--border-hi);
    color: var(--ink-muted);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
    opacity: 0; pointer-events: none;
    transform: translateY(12px) scale(.88);
    transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.56,.64,1);
}
.back-to-top.visible { opacity: 1; pointer-events: auto; transform: none; }
.back-to-top:hover   { color: var(--accent); border-color: var(--accent); }

/* ── Unread jump button (chat) ───────────────────────────────── */
.unread-jump-btn {
    position: absolute;
    bottom: 16px; left: 50%; transform: translateX(-50%) translateY(16px);
    z-index: 40;
    display: flex; align-items: center; gap: 6px;
    padding: 7px 16px;
    border-radius: 999px;
    background: var(--accent);
    color: #071a16;
    font-size: 12px; font-weight: 700;
    box-shadow: 0 4px 16px rgba(var(--accent-rgb),.45);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, transform .2s cubic-bezier(.34,1.56,.64,1);
    white-space: nowrap;
}
.unread-jump-btn.visible { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

/* ── Like pop animation ──────────────────────────────────────── */
@keyframes like-pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.36); }
    70%  { transform: scale(.88); }
    100% { transform: scale(1); }
}
.like-btn.like-pop { animation: like-pop .4s cubic-bezier(.36,.07,.19,.97); }

/* ── Swipe-to-reply visual feedback ─────────────────────────── */
.message { will-change: transform; }
.message.swipe-ready .message-bubble::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(var(--accent-rgb), .08);
    pointer-events: none;
}

/* ── Post draft banner ───────────────────────────────────────── */
.draft-banner {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: rgba(var(--accent-rgb), .08);
    border: 1px solid rgba(var(--accent-rgb), .18);
    border-radius: 10px;
    margin-bottom: 10px;
    opacity: 0; height: 0; overflow: hidden;
    transition: opacity .2s ease, height .2s ease;
}
.draft-banner.visible { opacity: 1; height: 38px; }

/* ── Nav icon spring animation ───────────────────────────────── */
@keyframes nav-tap {
    0%   { transform: scale(1); }
    35%  { transform: scale(.76); }
    65%  { transform: scale(1.22); }
    100% { transform: scale(1); }
}
.nav-item:active .icon-container { animation: nav-tap .32s cubic-bezier(.36,.07,.19,.97); }

/* ── Virtual scroll spacers ──────────────────────────────────── */
.vs-spacer-top, .vs-spacer-bot { flex-shrink: 0; }

/* ── Message container needs relative position for jump btn ─── */
.chat-main { position: relative; }
