* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0a;
    color: #e7e9ea;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
}

.container {
    width: 100%;
    max-width: 600px;
}

.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.header h1 span { color: #1d9bf0; }

.header p {
    color: #71767b;
    font-size: 14px;
}

.mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 1px solid #2f3336;
}

.mode-tab {
    flex: 1;
    padding: 14px;
    text-align: center;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: #71767b;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.mode-tab:hover { color: #e7e9ea; background: rgba(231, 233, 234, 0.04); }
.mode-tab.active { color: #e7e9ea; border-bottom-color: #1d9bf0; }

.card {
    background: #16181c;
    border: 1px solid #2f3336;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #71767b;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

textarea, input[type="text"], input[type="number"] {
    width: 100%;
    background: #0a0a0a;
    border: 1px solid #2f3336;
    border-radius: 12px;
    color: #e7e9ea;
    font-size: 16px;
    padding: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

textarea { resize: vertical; }

textarea:focus, input[type="text"]:focus, input[type="number"]:focus {
    outline: none;
    border-color: #1d9bf0;
}

textarea::placeholder,
input[type="text"]::placeholder,
input[type="number"]::placeholder { color: #555b61; }

/* Spinners render as a light strip on the dark surface — the field is typed into. */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.tweet-input { min-height: 60px; margin-bottom: 16px; }
.context-input { min-height: 100px; }

.reply-section { display: none; }
.reply-section.visible { display: block; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 9999px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: #1d9bf0;
    color: #fff;
    width: 100%;
    margin-top: 20px;
}

.btn-primary:hover { background: #1a8cd8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    color: #1d9bf0;
    border: 1px solid #1d9bf0;
    padding: 10px 20px;
}

.btn-secondary:hover { background: rgba(29, 155, 240, 0.1); }

.btn-copy {
    background: #1d9bf0;
    color: #fff;
    padding: 10px 20px;
}

.btn-copy:hover { background: #1a8cd8; }

.btn-danger {
    background: transparent;
    color: #f4212e;
    border: 1px solid #f4212e;
    padding: 6px 14px;
    font-size: 13px;
}

.btn-danger:hover { background: rgba(244, 33, 46, 0.1); }

.result-card {
    display: none;
    background: #16181c;
    border: 1px solid #2f3336;
    border-radius: 16px;
    padding: 24px;
    margin-top: 16px;
}

.result-card.visible { display: block; }

.draft-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.draft-header h3 { font-size: 16px; font-weight: 700; }

.char-count {
    font-size: 13px;
    color: #71767b;
    font-weight: 600;
}

.char-count.over { color: #f4212e; }

.draft-text {
    background: #0a0a0a;
    border: 1px solid #2f3336;
    border-radius: 12px;
    padding: 16px;
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 16px;
    min-height: 60px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.response-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.response-logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
    margin-top: 2px;
}

.response-text {
    flex: 1;
}

.draft-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.image-debug {
    display: none;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid #2f3336;
    border-radius: 10px;
    background: #0a0a0a;
    color: #9aa0a6;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.vision-status {
    margin-top: 8px;
    font-size: 12px;
    color: #71767b;
    font-weight: 600;
}

/* --- Follow-up Thread --- */

.followup-section {
    display: none;
    margin-top: 16px;
}

.followup-section.visible { display: block; }

.followup-thread {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.followup-msg {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.followup-msg.user {
    background: rgba(29, 155, 240, 0.15);
    color: #1d9bf0;
    margin-left: 40px;
}

.followup-msg.ai {
    background: #1e2025;
    color: #e7e9ea;
    margin-right: 40px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.followup-input-row {
    display: flex;
    gap: 10px;
}

.followup-input-row input {
    flex: 1;
}

.followup-input-row .btn {
    flex-shrink: 0;
    margin-top: 0;
    width: auto;
    padding: 12px 20px;
}

.spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner.visible { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1d9bf0;
    color: #fff;
    padding: 12px 24px;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 14px;
    transition: transform 0.3s ease;
    z-index: 100;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* --- History Panel --- */

.history-panel {
    display: none;
}

.history-panel.visible { display: block; }

.generator-panel.hidden { display: none; }

.search-bar {
    margin-bottom: 16px;
}

.history-item {
    background: #16181c;
    border: 1px solid #2f3336;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 10px;
    transition: border-color 0.2s;
}

.history-item:hover { border-color: #2f3336; }

.history-text {
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.history-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-meta {
    font-size: 12px;
    color: #71767b;
}

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

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 9999px;
    cursor: pointer;
    border: none;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-sm-copy {
    background: rgba(29, 155, 240, 0.1);
    color: #1d9bf0;
}

.btn-sm-copy:hover { background: rgba(29, 155, 240, 0.2); }

.empty-state {
    text-align: center;
    color: #71767b;
    padding: 40px 20px;
    font-size: 14px;
}

/* --- Publish section --- */

textarea.draft-text { width: 100%; font-family: inherit; resize: vertical; }
textarea.draft-text:focus { outline: none; border-color: #1d9bf0; }

.platform-row {
    border: 1px solid #2f3336;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
}

.platform-row.disconnected { opacity: 0.45; }
.platform-row.disconnected .not-connected { color: #ffad1f; font-size: 12px; font-weight: 600; }

.platform-check {
    display: flex; align-items: center; gap: 10px;
    color: #e7e9ea; font-size: 15px; font-weight: 600;
    text-transform: none; letter-spacing: 0; margin: 0; cursor: pointer;
}

.platform-check input { width: 16px; height: 16px; accent-color: #1d9bf0; }
.platform-check.sub { font-size: 13px; font-weight: 400; color: #9aa0a6; }

.platform-opts { display: none; margin-top: 10px; padding-left: 26px; }
.platform-row.checked .platform-opts { display: block; }

.pub-hint { font-size: 12px; color: #71767b; display: block; margin-top: 6px; }
.pub-hint.over { color: #f4212e; font-weight: 600; }

.image-preview-block img {
    width: 100%; max-width: 320px; border-radius: 12px;
    border: 1px solid #2f3336; display: block; margin-top: 4px;
}

.post-results { margin-top: 14px; }

.post-result-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 10px; margin-bottom: 6px;
    font-size: 14px; border: 1px solid #2f3336;
}

.post-result-row.ok { border-color: rgba(0,186,124,0.4); color: #00ba7c; }
.post-result-row.err { border-color: rgba(244,33,46,0.4); color: #f4212e; }
.post-result-row a { color: #1d9bf0; }
.post-result-row .err-text { color: #9aa0a6; font-size: 12px; }

/* --- Playground --- */

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
    padding: 8px 16px;
    border-radius: 9999px;
    border: 1px solid #2f3336;
    background: transparent;
    color: #71767b;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.pill:hover { color: #e7e9ea; border-color: #1d9bf0; }
.pill.active { background: rgba(29,155,240,0.15); color: #1d9bf0; border-color: #1d9bf0; }

.brand-row {
    display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.brand-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: #1d9bf0; flex-shrink: 0; }
.brand-row input[type="text"] { flex: 1; padding: 10px 14px; font-size: 14px; }
.brand-row input[type="text"]:disabled { opacity: 0.4; text-decoration: line-through; }
.brand-row select {
    flex-shrink: 0; padding: 9px 8px; font-size: 13px; border-radius: 10px;
    background: #0a0a0a; border: 1px solid #2f3336; color: #71767b; font-family: inherit;
    cursor: pointer;
}
.brand-row select:focus { outline: none; border-color: #1d9bf0; }
.brand-row .brand-del {
    flex-shrink: 0; border: none; background: transparent; color: #71767b;
    font-size: 20px; line-height: 1; cursor: pointer; padding: 0 6px;
}
.brand-row .brand-del:hover { color: #f4212e; }
.brand-empty { color: #71767b; font-size: 13px; padding: 6px 0 10px; }

#pgCustomWrap { display: none; align-items: center; gap: 10px; margin-top: 10px; }
#pgCustomWrap.visible { display: flex; }
#pgCustomChars {
    width: 110px; padding: 9px 12px; font-size: 14px; border-radius: 10px;
    background: #0a0a0a; border: 1px solid #2f3336; color: #e7e9ea; font-family: inherit;
}
#pgCustomChars:focus { outline: none; border-color: #1d9bf0; }

.pg-post-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pg-post-row .btn { flex: 1 1 40%; padding: 12px 10px; font-size: 14px; }
.pg-post-row .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Activity charts --- */

.chart-tip {
    position: fixed; z-index: 400; display: none; pointer-events: none;
    background: #0a0a0a; border: 1px solid #2f3336; border-radius: 10px;
    padding: 8px 11px; font-size: 13px; line-height: 1.5; color: #e7e9ea;
    max-width: 260px; box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.chart-tip b { color: #fff; }

.chart-empty {
    color: #71767b; font-size: 14px; text-align: center; padding: 48px 12px;
}

.stat-row {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px; margin-bottom: 18px;
}
.stat-tile {
    background: #0a0a0a; border: 1px solid #2f3336; border-radius: 14px; padding: 14px 16px;
}
.stat-label {
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
    color: #71767b; margin-bottom: 6px;
}
.stat-value { font-size: 28px; font-weight: 700; color: #e7e9ea; line-height: 1.1; }
.stat-sub { font-size: 12px; color: #71767b; margin-top: 4px; }
.stat-spark { margin-top: 8px; height: 28px; }

.chart-block { margin-bottom: 6px; }
.chart-head {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.chart-title { font-size: 15px; font-weight: 600; color: #e7e9ea; }
.chart-note { font-size: 12px; color: #71767b; }

.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #71767b; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: 130px 1fr 56px; gap: 10px; align-items: center; }
.hbar-label { font-size: 13px; color: #e7e9ea; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: #0a0a0a; border-radius: 6px; height: 18px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 6px; min-width: 3px; }
.hbar-value { font-size: 13px; color: #71767b; text-align: right; }

.activity-filters {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px;
}
.activity-filters select {
    background: #0a0a0a; border: 1px solid #2f3336; border-radius: 10px; color: #e7e9ea;
    font-size: 14px; padding: 9px 12px; font-family: inherit; cursor: pointer;
}
.activity-filters select:focus { outline: none; border-color: #1d9bf0; }

.post-cell-text {
    color: #71767b; font-size: 12px; max-width: 320px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.plat-dot {
    display: inline-block; width: 9px; height: 9px; border-radius: 3px;
    margin-right: 7px; flex-shrink: 0;
}

/* --- Image crop modal --- */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0, 0, 0, 0.75);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}

.modal-card {
    background: #16181c;
    border: 1px solid #2f3336;
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
}

.crop-stage {
    background: #0a0a0a;
    border-radius: 12px;
    overflow: hidden;
    max-height: 55vh;
}

.crop-stage img { max-width: 100%; display: block; }

.image-actions {
    display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap;
}
.image-actions .btn { padding: 8px 16px; font-size: 13px; }

/* --- Topbar (shared by index, admin, and setup) --- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    font-size: 13px;
    color: #71767b;
}
.topbar a { color: #1d9bf0; text-decoration: none; white-space: nowrap; }
.topbar a:hover { text-decoration: underline; }
.topbar form { display: inline; }

/* Long emails must be able to break rather than shove the actions off-screen. */
.topbar-user { min-width: 0; overflow-wrap: anywhere; }
.topbar-actions {
    display: flex; align-items: center; gap: 14px;
    flex-wrap: wrap; flex-shrink: 0;
}

/* --- Mobile --- */
@media (max-width: 600px) {
    body { padding: 20px 12px; }

    /* Side by side, the email wraps and collides with the links. Stack instead. */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 20px;
    }
    .topbar-actions { width: 100%; }
    .card, .result-card { padding: 16px; border-radius: 14px; }
    .header { margin-bottom: 20px; }
    .header h1 img { height: 30px !important; }
    .mode-tabs { margin-bottom: 16px; }
    .mode-tab { padding: 12px 6px; font-size: 14px; }
    .btn-primary { margin-top: 14px; padding: 14px 20px; }
    .draft-text { padding: 14px; font-size: 15px; }
    .draft-actions {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: stretch;
    }
    .draft-actions .btn {
        flex: 1 1 100%;
        padding: 12px 16px;
        font-size: 14px;
        white-space: nowrap;
    }
    .followup-msg.user { margin-left: 20px; }
    .followup-msg.ai { margin-right: 20px; }
    .followup-input-row .btn { padding: 12px 16px; }
}
