:root {
    --bg: #F4F5F7;
    /* Slightly cooler technical grey */
    --surface: #FFFFFF;
    --text: #172B4D;
    /* Deep navy/slate for text */
    --text-secondary: #5E6C84;
    --primary: #0052CC;
    /* Jira/Atlassian Blue */
    --accent: #0052CC;
    --success: #36B37E;
    --warning: #FFAB00;
    --error: #FF5630;
    --border: #DFE1E6;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --modal-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --ease-squish: cubic-bezier(0.2, 0, 0, 1);
    --font-heading: 'Libre Baskerville', serif;
    --font-ui: 'Plus Jakarta Sans', -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    line-height: 1.5;
}

#app {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px 40px;
    margin: 0 auto;
}

.layout-container {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 40px;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

@media (max-width: 768px) {
    #app {
        padding: 16px;
    }

    .layout-container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        gap: 20px;
    }
}

/* Header Dashboard Style */
#main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    margin: -20px -40px 20px -40px;
    /* Offset parent padding */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.header-left,
.header-right,
.header-center {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

.divider-vertical {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.app-context {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.app-name {
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
}

.app-version {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Status Pill */
.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: background 0.3s ease;
}

.status-pill.idle .status-dot {
    background: var(--text-secondary);
}

.status-pill.working {
    border-color: var(--primary);
    background: #DEEBFF;
    color: var(--primary);
}

.status-pill.working .status-dot {
    background: var(--primary);
    animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
    0% {
        opacity: 0.5;
        transform: scale(0.9);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }

    100% {
        opacity: 0.5;
        transform: scale(0.9);
    }
}

/* Buttons */
.btn-compact {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    /* Squarer tech look */
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-compact:hover {
    background: #0047B3;
}

/* Card Stack */
#swipe-container {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    /* Ensure it doesn't overflow parent */
    min-height: 0;
}

.filter-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23172B4D' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding: 8px 36px 8px 16px !important;
    height: 38px;
    background-color: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-ui);
    font-weight: 600;
}

.filter-select:hover {
    background-color: var(--bg) !important;
    border-color: var(--primary) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.1);
}

.filter-select option {
    background: var(--surface);
    color: var(--text);
    padding: 10px;
}

.card-stack-filter-flash {
    animation: filterFlash 0.5s var(--ease-squish);
}

@keyframes filterFlash {
    0% {
        opacity: 0.5;
        transform: scale(0.98);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.form-divider {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    margin: 32px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

#card-stack {
    position: relative;
    width: 100%;
    max-width: 480px;
    /* Constrain width on desktop */
    height: 520px;
    /* Taller for modern phones */
    perspective: 1000px;
}

.card {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--surface);
    border-radius: 24px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--card-shadow);
    cursor: grab;
    transition: transform 0.4s var(--ease-squish), opacity 0.3s ease;
    user-select: none;
    touch-action: none;
    will-change: transform;
    overflow: hidden;
    animation: cardEntrance 0.6s var(--ease-squish);
}

@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9) rotateX(-5deg);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1) rotateX(0);
    }
}

.card:active {
    cursor: grabbing;
}

/* Category Tag */
.card .category {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
    display: inline-block;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 20px;
    align-self: flex-start;
}

/* Headline */
.card h2 {
    font-family: 'Libre Baskerville', serif;
    font-size: 1.6rem;
    line-height: 1.35;
    margin-bottom: 24px;
    color: var(--text);
    font-weight: 700;
}

/* Content Body */
.card .content {
    font-size: 1.05rem;
    line-height: 1.7;
    color: rgba(0, 0, 0, 0.7);
    flex: 1;
    overflow-y: auto;
    font-weight: 400;
}

/* Footer */
.card .footer {
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Controls */
#controls {
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 20px 0 30px;
}

.control-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 1.6rem;
    cursor: pointer;
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.control-btn:active {
    transform: scale(0.92);
}

.control-btn.skip {
    color: #FF3B30;
}

.control-btn.approve {
    color: #34C759;
}

/* Modal System */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    width: 90%;
    max-width: 420px;
    padding: 32px;
    border-radius: 28px;
    /* Softer, updated corners */
    box-shadow: var(--modal-shadow);
    max-height: 85vh;
    overflow-y: auto;
    animation: modalPop 0.3s var(--ease-squish);
}

@keyframes modalPop {
    0% {
        transform: scale(0.95);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content.wide {
    max-width: 480px;
}

h2 {
    margin-bottom: 24px;
    font-family: 'Libre Baskerville', serif;
    font-size: 1.4rem;
    color: var(--text);
    text-align: center;
}

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

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
}

select,
input[type="text"],
input[type="file"] {
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--bg);
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.file-drop-area {
    width: 100%;
    padding: 32px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    text-align: center;
    cursor: pointer;
    background: var(--bg);
    transition: all 0.2s;
}

.file-drop-area:hover {
    border-color: var(--primary);
    background: var(--surface);
}

.ingest-status {
    margin-top: 24px;
    text-align: center;
    color: var(--primary);
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Upload Tabs */
.tab-header {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 0;
    justify-content: center;
}

.tab-btn {
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    padding-bottom: 8px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--primary) !important;
    border-bottom: 2px solid var(--primary) !important;
    font-weight: 600;
}

/* Buttons */
.modal-actions {
    display: flex;
    justify-content: stretch;
    gap: 12px;
    margin-top: 32px;
}

.modal-actions button {
    flex: 1;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.1s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg);
    border: none;
    padding: 16px;
    border-radius: 14px;
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #E5E5EA;
}

/* --- RICH POST PREVIEW --- */
.post-preview-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Image Container */
.preview-image {
    width: 100%;
    aspect-ratio: 4 / 5;
    /* Social standard */
    border-radius: 16px;
    overflow: hidden;
    background: #FAFAFA;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.preview-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Ensures the whole image is seen */
    display: block;
}

img.generated-post-image {
    width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.preview-image-fallback {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    padding: 20px;
}

/* Text Content */
.preview-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-caption {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
}

.preview-hashtags {
    font-size: 0.85rem;
    color: var(--accent);
    /* Subtle blue for tags */
    font-weight: 500;
    margin-top: 8px;
}

/* Queue Section (Embedded) */
#queue-section {
    background: var(--surface);
    border-radius: 24px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    height: 100%;
    min-height: 0;
    /* Enable scrolling within flex item */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.section-header h3 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 0;
}

#queue-count {
    background: var(--text);
    color: var(--surface);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 24px;
    text-align: center;
}

#queue-list {
    flex: 1;
    overflow-y: auto;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Queue Items - Technical Look */
.queue-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: 8px;
    /* Sharper corners */
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.queue-item:hover {
    border-color: var(--primary);
    transform: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

.queue-item.active {
    border-left-color: var(--primary);
    background: #F4F5F7;
}

.queue-item.active.generating {
    border-left-color: var(--warning);
}

.queue-item.ready {
    border-left-color: var(--success);
}

.queue-item.failed {
    border-left-color: var(--error);
}

.job-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.job-title {
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.job-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.status-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-secondary);
}

.queue-item.generating .status-badge {
    color: var(--warning);
    background: #FFF7D6;
}

.queue-item.ready .status-badge {
    color: var(--success);
    background: #E3FCEF;
}

/* Progress Rail */
.progress-rail {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

/* Icons */
.job-icon {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Activity Animation */
.generating .job-icon {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

.empty-state {
    text-align: center;
    padding: 30px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Saved Posts Section */
.saved-posts-section {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.saved-posts-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* Spinners & Loading States */
.loading-state {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    animation: fadeIn 0.5s ease;
}

.empty-state-message {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    text-align: center;
    gap: 20px;
    padding: 40px;
    background: var(--surface);
    border-radius: 24px;
    border: 1px dashed var(--border);
    animation: fadeIn 0.5s ease;
}

.empty-state-message p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;
}

.empty-state-message .btn-secondary {
    width: 100%;
    background: var(--primary);
    color: white;
}

.empty-state-message .btn-secondary:hover {
    background: #0047B3;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

.mini-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.source-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.source-link {
    font-size: 0.75rem;
    text-decoration: underline;
    opacity: 0.8;
}

.source-link:hover {
    opacity: 1;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-ui);
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: var(--text);
    /* Dark Slate */
    border-left: 4px solid var(--success);
}

.toast.error {
    background: var(--text);
    border-left: 4px solid var(--error);
}

/* Queue Animations */
.queue-item {
    animation: slideIn 0.3s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}