/* ============ Tadawel Stories (Instagram-style) ============ */

/* ---------- Tray ---------- */
.stories-tray-wrap {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 14px 12px;
    margin-bottom: 18px;
    align-self: start; /* grid child of .app: don't stretch to row height (was pushing feed below fold) */
}
.stories-tray {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px;
}
.stories-tray::-webkit-scrollbar { display: none; }
.stories-tray[hidden] { display: none; }
.st-empty { color: var(--text-3); font-size: 13px; padding: 4px 6px; }

.st-item {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    background: none; border: none; cursor: pointer;
    flex: 0 0 auto; width: 72px; padding: 0; color: var(--text);
}
.st-ring {
    width: 66px; height: 66px; border-radius: 50%;
    padding: 3px; position: relative;
    background: var(--surface-3);
    transition: transform .1s;
}
.st-item:active .st-ring { transform: scale(.94); }
.st-ring.unseen {
    background: linear-gradient(45deg, #f59e0b, #ef4444, #ec4899, #8b5cf6);
}
.st-ring.seen { background: var(--line); }
.st-ring.dashed { background: none; border: 2px dashed var(--text-3); padding: 2px; }
.st-ava {
    width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
    border: 3px solid var(--surface); background: var(--surface-3);
}
.st-name {
    font-size: 11.5px; color: var(--text-2); max-width: 72px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600;
}
.st-item.is-mine .st-name { color: var(--text); }
.st-count {
    position: absolute; top: -4px; inset-inline-end: -4px;
    min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
}

/* ---------- Stories hub list ---------- */
.stories-list { display: flex; flex-direction: column; gap: 8px; }
.st-row {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 10px 14px; cursor: pointer; width: 100%;
    color: var(--text); text-align: start;
}
.st-row:hover { border-color: var(--accent); }
.st-row img { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; }
.st-row-meta { flex: 1; min-width: 0; line-height: 1.3; }
.st-row-meta b { display: block; font-size: 14px; }
.st-row-meta span { font-size: 12px; color: var(--text-3); }
.story-hint { color: var(--text-3); font-size: 13px; margin: 10px 2px 16px; }

/* ---------- Viewer modal ---------- */
.stv-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0, 0, 0, .96);
    display: flex; align-items: center; justify-content: center;
    animation: stvFade .15s ease-out;
}
@keyframes stvFade { from { opacity: 0; } to { opacity: 1; } }
.stv-shell {
    position: relative;
    width: min(430px, 100vw);
    height: min(92vh, 100dvh - 20px);
    max-height: 860px;
    background: #10131c;
    border-radius: 16px;
    overflow: hidden;
    display: flex; flex-direction: column;
}
@media (max-width: 640px) {
    .stv-shell { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; }
}
.stv-progress { display: flex; gap: 4px; padding: 10px 12px 0; position: absolute; top: 0; left: 0; right: 0; z-index: 6; }
.stv-seg { flex: 1; height: 2.5px; border-radius: 2px; background: rgba(255,255,255,.28); overflow: hidden; }
.stv-seg i { display: block; height: 100%; width: 0%; background: #fff; }

.stv-head {
    position: absolute; top: 16px; left: 0; right: 0; z-index: 6;
    display: flex; align-items: center; gap: 10px; padding: 8px 12px;
    background: linear-gradient(rgba(0,0,0,.55), transparent);
}
.stv-head img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.7); }
.stv-head-meta { flex: 1; min-width: 0; line-height: 1.25; }
.stv-head-meta b { color: #fff; font-size: 14px; display: flex; align-items: center; gap: 5px; }
.stv-head-meta span { color: rgba(255,255,255,.72); font-size: 12px; }
.stv-vbadge { width: 14px; height: 14px; flex-shrink: 0; }
.stv-iconbtn {
    background: none; border: none; color: #fff; cursor: pointer;
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; font-size: 20px;
}
.stv-iconbtn:hover { background: rgba(255,255,255,.14); }
.stv-iconbtn svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.stv-stage {
    flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
    background: #000; user-select: none; min-height: 0;
}
.stv-stage img, .stv-stage video {
    max-width: 100%; max-height: 100%; width: 100%; height: 100%;
    object-fit: contain; background: #000;
}
.stv-caption {
    position: absolute; bottom: 74px; left: 14px; right: 14px; z-index: 5;
    color: #fff; font-size: 15px; font-weight: 600; text-align: center;
    text-shadow: 0 1px 6px rgba(0,0,0,.85);
    background: rgba(0,0,0,.28); border-radius: 12px; padding: 8px 12px;
    word-break: break-word;
}
.stv-tap { position: absolute; top: 0; bottom: 0; z-index: 4; }
.stv-tap.prev { left: 0; width: 38%; }
.stv-tap.next { right: 0; width: 62%; }
.stv-loading {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,.7); z-index: 3; pointer-events: none;
}
.stv-spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
    animation: stvSpin .8s linear infinite;
}
@keyframes stvSpin { to { transform: rotate(360deg); } }

.stv-replybar {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: #10131c; z-index: 7;
}
.stv-replybar input {
    flex: 1; background: transparent; border: 1.5px solid rgba(255,255,255,.4);
    border-radius: 999px; color: #fff; padding: 10px 16px; font-size: 14px;
}
.stv-replybar input::placeholder { color: rgba(255,255,255,.55); }
.stv-replybar button {
    background: none; border: none; color: var(--accent-2, #22d3ee);
    font-weight: 800; font-size: 14px; padding: 8px 6px; cursor: pointer;
}
.stv-replybar button:disabled { opacity: .4; cursor: default; }
.stv-loginhint { flex: 1; text-align: center; color: rgba(255,255,255,.75); font-size: 13px; }
.stv-loginhint a { color: #22d3ee; font-weight: 700; }
.stv-statsbtn {
    display: inline-flex; align-items: center; gap: 6px;
    background: none; border: none; color: #fff; font-size: 13px; font-weight: 700;
    cursor: pointer; padding: 8px 12px;
}
.stv-statsbtn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 1.8; }
.stv-delbtn { color: #ff8080; }

/* ---------- Viewers sheet ---------- */
.stv-viewers {
    position: absolute; inset: 0; z-index: 9;
    background: rgba(8, 10, 16, .98);
    display: flex; flex-direction: column; animation: stvFade .12s;
}
.stv-viewers-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.12); }
.stv-viewers-head b { color: #fff; font-size: 15px; }
.stv-viewers-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.stv-viewer { display: flex; align-items: center; gap: 12px; padding: 9px 16px; }
.stv-viewer img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.stv-viewer b { color: #fff; font-size: 14px; display: block; }
.stv-viewer span { color: rgba(255,255,255,.55); font-size: 12px; }
.stv-viewer .when { margin-inline-start: auto; color: rgba(255,255,255,.45); font-size: 12px; }
.stv-none { color: rgba(255,255,255,.5); text-align: center; padding: 34px 16px; font-size: 14px; }

/* ---------- Create modal ---------- */
.stc-overlay {
    position: fixed; inset: 0; z-index: 2100;
    background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 16px;
    animation: stvFade .15s;
}
.stc-box {
    width: min(480px, 100%);
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); overflow: hidden;
    display: flex; flex-direction: column; max-height: 92vh;
}
.stc-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.stc-head b { font-size: 15px; }
.stc-stage {
    aspect-ratio: 9 / 14; max-height: 56vh; background: var(--surface-3);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; overflow: hidden; position: relative;
}
.stc-stage img, .stc-stage video { width: 100%; height: 100%; object-fit: contain; }
.stc-placeholder { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--text-3); font-size: 14px; font-weight: 600; }
.stc-placeholder svg { width: 44px; height: 44px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.stc-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.stc-note { color: var(--text-3); font-size: 12px; }
.stc-actions { display: flex; gap: 8px; }
.stc-actions .btn { flex: 1; }

@media (max-width: 720px) {
    .stories-tray-wrap { border-radius: var(--radius); padding: 12px 10px; }
    .st-item { width: 68px; }
    .st-ring { width: 60px; height: 60px; }
}

/* ---------- Viewers sheet (Instagram "Seen by N") ---------- */
.viewers-list { max-height: 58vh; overflow-y: auto; padding: 6px 0; }
.viewer-row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; }
.viewer-row .avatar-sm { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.viewer-meta { flex: 1; min-width: 0; }
.viewer-meta b { display: block; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-meta span { font-size: 12px; color: var(--text-3); display: block; }
.viewer-time { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.stv-follow {
    flex-shrink: 0; border: 1px solid var(--accent); color: var(--accent);
    background: transparent; border-radius: 999px; padding: 5px 14px;
    font-size: 12px; font-weight: 700; cursor: pointer; transition: all .15s;
}
.stv-follow:hover { background: rgba(var(--accent-rgb), .12); }
.stv-follow.following { border-color: transparent; background: var(--surface-3); color: var(--text-2); }
