/* =============================================
   CONTENT FACTORY — Premium Dark UI
   Inspired by Linear / Vercel / Stripe dashboards
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #050508;
    --surface: rgba(20, 20, 30, 0.6);
    --surface-2: rgba(30, 30, 45, 0.4);
    --surface-3: rgba(45, 45, 65, 0.6);
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --glass: rgba(10, 10, 15, 0.75);
    --blur: blur(24px);
    --text: #ffffff;
    --text-muted: #9ca3af;
    --text-dim: #4b5563;
    --accent: #4f6ef7;
    --accent-hover: #3f5de6;
    --accent-subtle: rgba(79, 110, 247, 0.15);
    --green: #22c55e;
    --green-subtle: rgba(34, 197, 94, 0.12);
    --red: #ef4444;
    --red-subtle: rgba(239, 68, 68, 0.12);
    --amber: #f59e0b;
    --amber-subtle: rgba(245, 158, 11, 0.12);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html,
body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 99px;
}

/* ==========================
   TOP NAVIGATION BAR
   ========================== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: 60px;
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
}

.app-header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.3px;
    color: var(--text);
    flex-shrink: 0;
}

.app-header-logo .logo-mark {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-header-nav {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: center;
}

@media (max-width: 600px) {
    .app-header-nav {
        display: none;
    }
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--green);
    box-shadow: 0 0 8px rgba(34, 197, 94, .6);
}

.status-dot.offline {
    background: var(--red);
    box-shadow: 0 0 8px rgba(239, 68, 68, .6);
}

/* ==========================
   LAYOUT
   ========================== */
.app-body {
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding-top: 52px;
}

/* --------------- FACTORY VIEW (feed) --------------- */
#view-factory {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 32px 24px;
}

.factory-toolbar {
    width: 100%;
    max-width: 720px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.factory-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    flex: 1;
}

.feed {
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --------------- PARSER VIEW (sidebar + content) --------------- */
#view-parser {
    display: none;
    width: 100%;
    max-width: 1080px;
    padding: 32px 24px;
    gap: 24px;
}

/* ==========================
   SIDEBAR
   ========================== */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 12px 12px 6px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: var(--transition);
}

.sidebar-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar-item.active {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
}

.sidebar-item .item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-dim);
}

.sidebar-item.active .item-icon {
    color: var(--accent);
}

/* ==========================
   MAIN CONTENT AREA
   ========================== */
.content-area {
    flex: 1;
    min-width: 0;
}

.content-panel {
    display: none;
}

.content-panel.active {
    display: block;
}

/* ==========================
   CARD
   ========================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.card+.card {
    margin-top: 12px;
}

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

.card-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.2px;
    color: var(--text);
}

.card-desc {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ==========================
   FORM ELEMENTS
   ========================== */
.form-row {
    margin-bottom: 16px;
}

.form-row:last-child {
    margin-bottom: 0;
}

label,
.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.1px;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="time"],
input[type="email"],
select,
textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    padding: 9px 12px;
    transition: var(--transition);
    outline: none;
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-dim);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.help-text {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 5px;
    line-height: 1.45;
}

/* ==========================
   BUTTONS
   ========================== */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
}

button:active,
.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-2);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: var(--red-subtle);
    color: var(--red);
    border: 1px solid var(--red);
}

.btn-danger:hover {
    background: var(--red);
    color: #fff;
}

.btn-success {
    background: var(--green-subtle);
    color: var(--green);
    border: 1px solid var(--green);
}

.btn-success:hover {
    background: var(--green);
    color: #fff;
}

.btn-sm {
    padding: 5px 11px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

button[disabled],
.btn[disabled] {
    opacity: 0.45;
    pointer-events: none;
}

/* ==========================
   FACTORY TOOLBAR & COMPOSE
   ========================== */
.compose-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.compose-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-dim);
    flex: 1;
}

/* ==========================
   DRAFT CARDS
   ========================== */
.draft-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
}

.draft-card:hover {
    border-color: var(--border-strong);
}

.draft-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    gap: 6px;
}

.draft-source {
    color: var(--text-dim);
    letter-spacing: -0.1px;
}

.virality-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 99px;
    letter-spacing: 0.3px;
}

.virality-high {
    background: var(--green-subtle);
    color: var(--green);
}

.virality-mid {
    background: var(--amber-subtle);
    color: var(--amber);
}

.virality-low {
    background: var(--red-subtle);
    color: var(--red);
}

.draft-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 120px;
}

.draft-col {
    padding: 14px 16px;
    overflow-y: auto;
    max-height: 200px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    white-space: pre-wrap;
}

.draft-col+.draft-col {
    border-left: 1px solid var(--border);
}

.draft-col-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.draft-col .editable {
    color: var(--text);
    outline: none;
}

.draft-hashtags {
    padding: 7px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--accent);
}

.draft-actions {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.status-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 99px;
}

.status-draft {
    background: var(--surface-3);
    color: var(--text-muted);
}

.status-published {
    background: var(--green-subtle);
    color: var(--green);
}

.status-scheduled {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* ==========================
   EMPTY STATE
   ========================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.empty-state .empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* ==========================
   ANALYTICS DASHBOARD (ELITE)
   ========================== */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.analytics-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-height: 320px;
    transition: var(--transition);
}

.analytics-card:hover {
    border-color: var(--border-strong);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.chart-container {
    flex: 1;
    position: relative;
    margin-top: 16px;
    min-height: 200px;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-widget {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    overflow: hidden;
}

.stat-widget::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
    background: var(--accent);
    opacity: 0.03;
    filter: blur(30px);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}

/* --- Engagement Gadgets --- */
.engagement-bar {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.eng-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 99px;
}

.eng-icon {
    font-size: 14px;
}

.relevance-glow {
    position: relative;
}

.relevance-high {
    color: var(--green);
    text-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
}

.sentiment-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

.sentiment-urgent {
    background: var(--red-subtle);
    color: var(--red);
}

.sentiment-question {
    background: var(--accent-subtle);
    color: var(--accent);
}

.sentiment-feedback {
    background: var(--amber-subtle);
    color: var(--amber);
}

.sentiment-neutral {
    background: var(--surface-3);
    color: var(--text-dim);
}

/* ==========================
   MODAL
   ========================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    justify-content: center;
    align-items: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 90%;
    max-width: 580px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 24px;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}

.modal-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 3px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* ==========================
   POOL CARD (CF/DF group)
   ========================== */
.pool-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    margin-bottom: 16px;
}

.pool-card-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
}

/* ==========================
   TABLE / LIST
   ========================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 11px 12px;
    font-size: 13px;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--surface-2);
}

/* ==========================
   BOTTOM NAVIGATION (TMA)
   ========================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: var(--glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-top: 1px solid var(--border);
    display: none;
    grid-template-columns: repeat(3, 1fr);
    z-index: 300;
    padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 600px) {
    .bottom-nav {
        display: grid;
    }

    .sidebar {
        display: none;
    }

    #view-parser {
        flex-direction: column;
        padding-bottom: 100px;
    }

    #view-factory {
        padding-bottom: 100px;
    }

    .content-area {
        width: 100%;
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: var(--transition);
}

.bottom-nav-item svg {
    width: 20px;
    height: 20px;
    opacity: 0.6;
    transition: var(--transition);
}

.bottom-nav-item.active {
    color: var(--accent);
}

.bottom-nav-item.active svg {
    opacity: 1;
}

.bottom-nav-item:active svg {
    transform: scale(0.9);
}

/* ==========================
   GLASS CARDS
   ========================== */
.card,
.draft-card,
.pool-card,
.sidebar-item.active,
.stat-block {
    background: var(--surface);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* ==========================
   LOG OUTPUT
   ========================== */
.log-output {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    height: 240px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
}

/* ==========================
   SECTION DIVIDER
   ========================== */
hr.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ==========================
   LEGACY COMPAT (old styles used via JS-generated HTML)
   ========================== */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.tab-btn.active {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
}

.form-group {
    margin-bottom: 16px;
}

.container {
    width: 100%;
}