/* Google Fonts Import: Blinker (station brand) and Outfit (high-impact title font) */
@import url('https://fonts.googleapis.com/css2?family=Blinker:wght@300;400;600;700;800&family=Outfit:wght@300;400;500;600;700;800;900&display=swap');

:root {
    --bg-color: #080d1a;
    --panel-bg: rgba(15, 23, 42, 0.65);
    --panel-border: rgba(23, 173, 180, 0.18);
    --primary-color: #17adb4;
    --primary-hover: #1cd4dc;
    --primary-glow: rgba(23, 173, 180, 0.35);
    --secondary-color: #0b1329;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dark: #1f2937;
    --accent-red: #ef4444;
    --accent-green: #10b981;
    --border-radius-sm: 8px;
    --border-radius-md: 14px;
    --border-radius-lg: 20px;
    --box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --transition-speed: 0.25s;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
    --font-station: 'Blinker', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 10% 20%, rgba(23, 173, 180, 0.12) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(13, 23, 42, 0.8) 0px, transparent 50%);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header Styles */
header {
    background: rgba(10, 17, 34, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--panel-border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-container h1 {
    font-family: var(--font-station);
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #ffffff 30%, var(--primary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-container span {
    font-family: var(--font-station);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid var(--panel-border);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    background: rgba(15, 23, 42, 0.8);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

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

.status-dot.connected {
    background-color: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.disconnected {
    background-color: var(--accent-red);
    box-shadow: 0 0 8px var(--accent-red);
}

.btn-settings {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition-speed) ease;
}

.btn-settings:hover {
    background: rgba(23, 173, 180, 0.1);
    border-color: var(--primary-color);
}

/* Main Layout */
.app-container {
    display: grid;
    grid-template-columns: 380px 1fr;
    flex-grow: 1;
    height: calc(100vh - 72px);
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--panel-border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

/* Custom Scrollbar for Sidebar */
.sidebar::-webkit-scrollbar,
.main-workspace::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track,
.main-workspace::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb,
.main-workspace::-webkit-scrollbar-thumb {
    background: rgba(23, 173, 180, 0.3);
    border-radius: 10px;
}
.sidebar::-webkit-scrollbar-thumb:hover,
.main-workspace::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    border-bottom: 1px solid rgba(23, 173, 180, 0.15);
    padding-bottom: 0.5rem;
    margin-bottom: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="url"],
input[type="number"],
textarea,
select {
    background: rgba(10, 17, 34, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
    color: var(--text-main);
    padding: 0.75rem;
    font-size: 0.9rem;
    font-family: var(--font-body);
    transition: all var(--transition-speed) ease;
    width: 100%;
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(23, 173, 180, 0.25);
    background: rgba(10, 17, 34, 0.9);
}

.url-input-container {
    display: flex;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #108d92 100%);
    border: none;
    color: #ffffff;
    padding: 0.75rem 1.2rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition-speed) ease;
    box-shadow: 0 4px 14px rgba(23, 173, 180, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary-color) 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(23, 173, 180, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: #374151;
    color: #9ca3af;
    cursor: not-allowed;
    box-shadow: none;
}

/* History Dropdown / List */
.history-container {
    background: rgba(10, 17, 34, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem;
    max-height: 160px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background var(--transition-speed) ease;
}

.history-item:hover {
    background: rgba(23, 173, 180, 0.15);
}

.history-item-details {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
    padding-right: 0.5rem;
}

.btn-delete-history {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 4px;
}

.btn-delete-history:hover {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

/* Images Grid */
.images-container {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.images-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    padding-right: 2px;
}

.image-thumb {
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    position: relative;
    background: #000;
}

.image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-thumb.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

.image-thumb.ai-selected {
    border-color: #f59e0b;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
}

.image-thumb.selected::after {
    content: '✓';
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: var(--primary-color);
    color: white;
    font-size: 8px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-select-btn {
    position: absolute;
    top: 4px;
    left: 4px;
    border: 1px solid rgba(0, 0, 0, 0.35);
    background: rgba(8, 13, 26, 0.75);
    color: #e5e7eb;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
    z-index: 3;
}

.thumb-select-btn.active {
    background: rgba(245, 158, 11, 0.95);
    color: #111827;
    border-color: rgba(255, 255, 255, 0.45);
}

/* File Upload Styles */
.file-upload-btn {
    border: 1px dashed var(--panel-border);
    border-radius: var(--border-radius-sm);
    padding: 0.8rem;
    text-align: center;
    cursor: pointer;
    background: rgba(23, 173, 180, 0.03);
    transition: all var(--transition-speed) ease;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.file-upload-btn:hover {
    border-color: var(--primary-color);
    background: rgba(23, 173, 180, 0.08);
    color: var(--text-main);
}

.btn-generate-ai {
    width: 100%;
    justify-content: center;
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(23, 173, 180, 0.08);
    font-weight: 600;
}

.btn-generate-ai:hover {
    background: rgba(23, 173, 180, 0.16);
    color: #d6fdff;
}

.ai-feedback-input {
    min-height: 74px;
    font-size: 0.82rem;
    line-height: 1.35;
}

.btn-iterate-ai {
    width: 100%;
    justify-content: center;
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.04);
}

.btn-iterate-ai:hover {
    background: rgba(255, 255, 255, 0.1);
}

.ai-selection-hint {
    margin-top: 0.15rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Workspace Area */
.main-workspace {
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    background: #070c17;
}

.card {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-md);
    box-shadow: var(--box-shadow);
    padding: 1.5rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Facebook Post Box */
.fb-post-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.fb-post-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.fb-post-textarea {
    width: 100%;
    min-height: 120px;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    border-color: rgba(255, 255, 255, 0.08);
}

/* Graphics Production Area */
.graphics-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 1200px) {
    .graphics-section {
        grid-template-columns: 1fr;
    }
}

.graphic-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.graphic-title {
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.graphic-title span {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

.canvas-wrapper {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    position: relative;
    overflow: auto;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

canvas {
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    background: #1e293b;
    max-width: 100%;
    height: auto;
    display: block;
}

/* Range Input styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 0 8px var(--primary-glow);
    transition: background 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease;
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--secondary-color);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-md);
    box-shadow: var(--box-shadow);
    width: 480px;
    max-width: 90%;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-speed) ease;
}

.modal-backdrop.show .modal {
    transform: scale(1);
}

.modal-header {
    background: rgba(10, 17, 34, 0.6);
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-weight: 600;
    font-size: 1.1rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    background: rgba(10, 17, 34, 0.6);
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
}

/* Loading overlays */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(8, 13, 26, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease;
    gap: 1.5rem;
}

.loading-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(23, 173, 180, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    box-shadow: 0 0 15px rgba(23, 173, 180, 0.2);
}

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

.loading-text {
    font-size: 1.1rem;
    color: var(--primary-color);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: var(--font-station);
}

/* Notification Banners */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-sm);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    z-index: 1500;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 500;
    font-size: 0.9rem;
    max-width: 380px;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification.success {
    background: #064e3b;
    color: #a7f3d0;
    border: 1px solid #059669;
}

.notification.error {
    background: #7f1d1d;
    color: #fca5a5;
    border: 1px solid #dc2626;
}

.notification.info {
    background: #1e3a8a;
    color: #bfdbfe;
    border: 1px solid #2563eb;
}

/* DB Warning Banner */
.db-warning-banner {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fef3c7;
    padding: 0.8rem 1.5rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.db-warning-banner span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.db-warning-banner button {
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fef3c7;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.2s;
}

.db-warning-banner button:hover {
    background: rgba(245, 158, 11, 0.35);
}

.color-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.color-picker-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.color-picker-wrapper input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 100%;
    height: 35px;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
}

/* Responsive collapse on smaller screens */
@media (max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
        height: auto;
        overflow: visible;
    }
    .main-workspace {
        height: auto;
        overflow: visible;
    }
}
