:root {
    --bg: #000000;
    --line: #2f3336;
    --ink: #e7e9ea;
    --dim: #71767b;
    --accent: #1d9bf0;
    --up: #00ba7c;
    --like: #f91880;
    --warn: #ffd400;
    --rail-width: 275px;
    --center-width: 600px;
    --right-width: 350px;
    --hover: rgba(231, 233, 234, 0.03);
    --hover-strong: rgba(231, 233, 234, 0.1);
}

* { box-sizing: border-box; }

html { font-size: 15px; }
@media (max-width: 820px) { html { font-size: 16px; } }

html, body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hint { color: var(--dim); }
.center { text-align: center; padding: 24px 0; }
.warn { color: var(--warn); }

.boot { padding: 60px 20px; text-align: center; color: var(--dim); font-size: 1.1rem; }

/* ---- App frame: left rail + center + right rail (X-style) ---- */
.app-frame {
    display: flex;
    justify-content: center;
    min-height: 100vh;
    max-width: 1280px;
    margin: 0 auto;
    gap: 0;
}

/* ---- Left rail ---- */
.left-rail {
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: var(--rail-width);
    height: 100vh;
    max-height: 100vh;
    padding: 4px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rail-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    color: var(--ink);
    font-size: 1.75rem;
    margin: 2px 0 4px;
}
.rail-logo:hover {
    background: var(--hover-strong);
    text-decoration: none;
}
.brand-x { font-size: 1.75rem; line-height: 1; }

.rail-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.rail-item {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 16px 12px 12px;
    border-radius: 999px;
    color: var(--ink);
    font-size: 1.25rem;
    font-weight: 400;
    line-height: 1.2;
    width: fit-content;
    max-width: 100%;
}
.rail-item:hover {
    background: var(--hover-strong);
    text-decoration: none;
}
.rail-item.active {
    font-weight: 700;
}
.rail-admin .rail-label { color: var(--warn); }
.rail-admin.active .rail-label { color: var(--warn); }

.rail-icon {
    width: 1.65rem;
    text-align: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.rail-label { white-space: nowrap; }

.rail-footer {
    margin-top: auto;
    padding-top: 12px;
    padding-bottom: 8px;
}

.rail-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 999px;
    cursor: default;
}
.rail-user:hover { background: var(--hover-strong); }

.rail-user-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.rail-user-name {
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rail-user-handle {
    font-size: 0.85rem;
    color: var(--dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rail-user-role {
    font-size: 0.72rem;
    color: var(--dim);
    text-transform: lowercase;
}

.rail-cta {
    display: block;
    text-align: center;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    padding: 14px 16px;
    border-radius: 999px;
    font-size: 1.05rem;
}
.rail-cta:hover {
    filter: brightness(1.08);
    text-decoration: none;
    color: #fff;
}

/* ---- Center column ---- */
.center-column {
    width: 100%;
    max-width: var(--center-width);
    min-height: 100vh;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}

.page-body { flex: 1; min-width: 0; }

/* ---- Right rail ---- */
.right-rail {
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: var(--right-width);
    max-height: 100vh;
    padding: 12px 16px;
    overflow-y: auto;
}
.right-card {
    background: #16181c;
    border-radius: 16px;
    padding: 12px 16px;
    margin-bottom: 16px;
}
.right-title {
    margin: 0 0 8px;
    font-size: 1.15rem;
    font-weight: 800;
}
.right-body {
    margin: 0;
    color: var(--dim);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* ---- Timeline header ---- */
.timeline-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 53px;
    border-bottom: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
}
.timeline-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}
.detail-header .back-btn {
    color: var(--ink);
    font-size: 1.2rem;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
}
.detail-header .back-btn:hover {
    background: var(--hover-strong);
    text-decoration: none;
}

/* ---- Avatar ---- */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    background: hsl(var(--av-h, 200) 55% 38%);
    flex-shrink: 0;
    user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: 0.75rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 0.95rem; }

/* ---- Tweet / post card ---- */
.tweet {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    transition: background 0.1s ease;
}
.tweet:hover { background: var(--hover); }
.tweet-detail:hover { background: transparent; }

.tweet-context {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--dim);
    font-size: 0.82rem;
    font-weight: 700;
    margin: 0 0 4px 52px;
}
.tweet-context .act-ico { width: 14px; height: 14px; }

.tweet-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.tweet-avatar-link { flex-shrink: 0; text-decoration: none; }
.tweet-avatar-link:hover { text-decoration: none; opacity: 0.9; }

.tweet-main {
    flex: 1;
    min-width: 0;
}

.tweet-head-line { min-width: 0; }
.tweet-identity {
    color: inherit;
    text-decoration: none;
    display: block;
}
.tweet-identity:hover { text-decoration: none; }

.tweet-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: 0.95rem;
    line-height: 1.25;
    min-width: 0;
}
.tweet-name {
    font-weight: 700;
    color: var(--ink);
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tweet-handle,
.tweet-time,
.tweet-dot {
    color: var(--dim);
    font-weight: 400;
}
.tweet-handle {
    max-width: 36%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tweet-identity:hover .tweet-time {
    text-decoration: underline;
}

.tweet-verified {
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    margin-left: 2px;
}

.tweet-body {
    margin: 2px 0 0;
    font-size: 0.95rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--ink);
}
.tweet-body-lg {
    font-size: 1.4rem;
    line-height: 1.4;
    margin: 12px 0 4px;
    padding: 0 0 4px;
}

.content-text { white-space: pre-wrap; }
.mention, .hashtag {
    color: var(--accent);
    font-weight: 400;
}
.mention:hover, .hashtag:hover { text-decoration: underline; }
a.hashtag {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}
a.hashtag:hover { text-decoration: underline; }

.hashtag-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.hashtag-count {
    font-size: 0.85rem;
    font-weight: 400;
}

/* Quote card */
.quote-card {
    display: block;
    margin: 12px 0 4px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    color: inherit;
    transition: background 0.1s ease;
}
.quote-card:hover {
    background: var(--hover);
    text-decoration: none;
    border-color: #536471;
}
.quote-inner { gap: 8px; }
.quote-body {
    font-size: 0.92rem;
    margin-top: 2px;
    color: var(--ink);
}

/* ---- Action bar (Reply · Repost · Like) ---- */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 425px;
    margin-top: 12px;
}
.action-bar.compact {
    max-width: 120px;
    margin-top: 8px;
}
.action-bar-detail {
    max-width: none;
    justify-content: space-around;
    padding: 4px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin-top: 4px;
}

.act {
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}
.act:disabled {
    opacity: 0.45;
    cursor: default;
}
.act-btn {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s ease, color 0.12s ease;
}
.act-count {
    min-width: 1ch;
    font-variant-numeric: tabular-nums;
}
.act-ico { display: block; }

.act-reply:hover:not(:disabled) { color: var(--accent); }
.act-reply:hover:not(:disabled) .act-btn { background: rgba(29, 155, 240, 0.1); color: var(--accent); }

.act-reshare:hover:not(:disabled) { color: var(--up); }
.act-reshare:hover:not(:disabled) .act-btn { background: rgba(0, 186, 124, 0.1); color: var(--up); }

.act-like:hover:not(:disabled) { color: var(--like); }
.act-like:hover:not(:disabled) .act-btn { background: rgba(249, 24, 128, 0.1); color: var(--like); }

/* ---- Composer ---- */
.composer {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.composer textarea,
.inline-composer textarea {
    width: 100%;
    min-height: 52px;
    background: none;
    border: none;
    resize: none;
    color: var(--ink);
    font: inherit;
    font-size: 1.25rem;
    outline: none;
    padding: 4px 0 12px;
}
.composer-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}
.composer-hint {
    flex: 1;
    color: var(--dim);
    font-size: 0.8rem;
}
.counter {
    color: var(--dim);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
.counter-warn { color: var(--warn); }

.btn-post {
    background: var(--accent);
    border: none;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 8px 16px;
    border-radius: 999px;
    cursor: pointer;
}
.btn-post:hover:not(:disabled) { filter: brightness(1.08); }
.btn-post:disabled { opacity: 0.5; cursor: default; }

.pill {
    background: none;
    border: 1px solid var(--line);
    color: var(--ink);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-block;
}
.pill:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.primary:disabled { opacity: 0.5; cursor: default; }
.pill.danger { border-color: var(--like); color: var(--like); }

.status { color: var(--like); font-size: 0.85rem; margin: 8px 0 0; }
.login-hint {
    padding: 16px;
    border-bottom: 1px solid var(--line);
    margin: 0;
    color: var(--dim);
}
.empty-feed { padding: 48px 24px; }

.inline-composer {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
}
.inline-composer textarea {
    font-size: 1rem;
    min-height: 44px;
    padding-bottom: 8px;
}
.inline-composer .composer-bar {
    border-top: none;
    justify-content: flex-end;
    padding-top: 0;
}

.thread-inline {
    margin-top: 8px;
    border-top: 1px solid var(--line);
    padding-top: 4px;
}
.tweet-reply {
    padding: 10px 0;
    border-bottom: none;
}
.tweet-reply:hover { background: transparent; }

.share-msg { color: var(--up); font-size: 0.85rem; margin: 8px 0 0; }

/* ---- Detail post metrics ---- */
.detail-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 16px 0;
    border-top: 1px solid var(--line);
    margin-top: 12px;
    color: var(--dim);
    font-size: 0.95rem;
}
.detail-metrics strong {
    color: var(--ink);
    font-weight: 700;
    margin-right: 4px;
}

.thread-section { border-top: 1px solid var(--line); }
.thread-heading {
    margin: 0;
    padding: 12px 16px;
    font-size: 1.05rem;
    font-weight: 800;
    border-bottom: 1px solid var(--line);
}

.ban-badge {
    font-size: 0.7rem;
    font-weight: 700;
    color: #000;
    background: var(--like);
    border-radius: 4px;
    padding: 2px 6px;
    text-transform: uppercase;
    width: fit-content;
}

/* ---- Admin (kept functional) ---- */
.admin { padding: 16px; }
.admin-h { margin: 0 0 8px; font-size: 1.3rem; }
.admin-sub { margin: 0 0 8px; font-size: 1.05rem; }
.admin-section { margin: 20px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.stats { color: var(--dim); line-height: 1.7; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.agent-list { list-style: none; margin: 12px 0 0; padding: 0; }
.agent-row {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.agent-meta { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.agent-name { font-weight: 800; text-transform: lowercase; font-size: 1.05rem; }
.agent-flags { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-pill {
    font-size: 0.68rem; font-weight: 700; border-radius: 999px; padding: 2px 8px;
    border: 1px solid var(--line); color: var(--dim); text-transform: uppercase;
}
.agent-pill.key { border-color: var(--up); color: var(--up); }
.agent-pill.nokey { border-color: var(--dim); }
.agent-pill.active { border-color: var(--accent); color: var(--accent); }
.agent-pill.idle { border-color: var(--warn); color: var(--warn); }
.agent-pill.off { border-color: var(--like); color: var(--like); }
.agent-pill.def { border-color: var(--ink); color: var(--ink); }
.agent-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.eng-table-wrap { overflow-x: auto; margin-top: 10px; }
.eng-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.eng-table th, .eng-table td {
    text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.eng-table th { color: var(--dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
.eng-name { font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.eng-score { font-weight: 800; color: var(--accent); }
.eng-disabled { opacity: 0.55; }

/* Content / legacy hooks */
.content { min-height: 0; }
.ai-badge {
    font-size: 0.68rem; color: var(--accent); border: 1px solid var(--accent);
    border-radius: 4px; padding: 1px 5px; font-weight: 600;
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
    .right-rail { display: none; }
    :root { --right-width: 0px; }
}

@media (max-width: 1000px) {
    :root { --rail-width: 68px; }
    .rail-label, .rail-user-meta, .rail-cta { display: none; }
    .rail-item { justify-content: center; padding: 12px; width: 50px; }
    .rail-user { justify-content: center; padding: 10px; }
    .left-rail { padding: 4px 4px 12px; align-items: center; }
}

@media (max-width: 560px) {
    .app-frame { justify-content: flex-start; }
    .center-column { border-left: none; border-right: none; max-width: 100%; }
    .tweet-context { margin-left: 0; }
    .action-bar { max-width: 100%; }
}

#blazor-error-ui {
    background: #3a1d1d; color: var(--ink); bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,0.4);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
