/* ======================================================
   Bag Design Generator - Dark Theme Stylesheet
   ====================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-surface: #16213e;
    --bg-card: #1e2a47;
    --bg-input: #0d1b2a;
    --accent-primary: #e94560;
    --accent-secondary: #0f3460;
    --accent-hover: #ff6b81;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b80;
    --border-color: #2a2a45;
    --border-light: #3a3a55;
    --success: #2ecc71;
    --error: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;
    --sidebar-width: 240px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: all 0.3s ease;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
}

a { color: var(--accent-primary); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ======================================================
   Sidebar
   ====================================================== */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent-primary);
    font-weight: 700;
    font-size: 15px;
}

.sidebar-toggle { display: none; background: none; border: none; color: var(--text-secondary); cursor: pointer; }

.nav-menu {
    list-style: none;
    padding: 15px 10px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    margin-bottom: 4px;
    transition: var(--transition);
    font-size: 14px;
}

.nav-link:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-secondary);
    color: var(--accent-primary);
    font-weight: 600;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* ======================================================
   Main Content
   ====================================================== */
.content {
    min-height: 100vh;
    padding: 30px;
}

.content.with-sidebar {
    margin-left: var(--sidebar-width);
}

.content.full-width {
    margin-left: 0;
}

/* ======================================================
   Buttons
   ====================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover:not(:disabled) { opacity: 0.9; }

.btn-danger {
    background: var(--error);
    color: white;
}
.btn-danger:hover:not(:disabled) { opacity: 0.9; }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-outline:hover:not(:disabled) {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-block { width: 100%; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
}

.logout-btn { font-size: 11px; padding: 4px 10px; }

/* ======================================================
   Forms
   ====================================================== */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

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

select {
    -webkit-appearance: none;
    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='%23a0a0b8'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: flex;
    gap: 15px;
}
.form-row .form-group { flex: 1; }

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ======================================================
   Alerts
   ====================================================== */
.alert {
    padding: 12px 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    border: 1px solid;
}

.alert-error { background: rgba(231,76,60,0.1); border-color: var(--error); color: #ff6b6b; }
.alert-success { background: rgba(46,204,113,0.1); border-color: var(--success); color: #5dde8f; }
.alert-info { background: rgba(52,152,219,0.1); border-color: var(--info); color: #6bb5e8; }
.alert-warning { background: rgba(243,156,18,0.1); border-color: var(--warning); color: #f5c842; }

.alert-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.6;
}
.alert-close:hover { opacity: 1; }

/* ======================================================
   Login Page
   ====================================================== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

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

.login-header h1 {
    font-size: 22px;
    margin-top: 15px;
    color: var(--text-primary);
}

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

.login-form .form-group { margin-bottom: 20px; }

.login-form .btn-block {
    margin-top: 10px;
    padding: 12px;
    font-size: 15px;
}

/* ======================================================
   Dashboard
   ====================================================== */
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 30px;
    max-width: 1600px;
}

.generation-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 25px;
}

.generation-panel h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.prompt-textarea {
    min-height: 120px;
    font-size: 15px;
    line-height: 1.5;
}

/* Suggestion chips */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.suggestion-chip {
    padding: 6px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.suggestion-chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(233, 69, 96, 0.08);
}

#generate-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    margin-top: 10px;
}

/* Status indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    margin-top: 15px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 14px;
}

.status-indicator.hidden { display: none; }

/* Result panel */
.result-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 25px;
    display: flex;
    flex-direction: column;
}

.result-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.result-container img {
    max-width: 100%;
    max-height: 600px;
    object-fit: contain;
    border-radius: 4px;
}

.placeholder-text {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

.placeholder-text p { margin-bottom: 8px; }

.result-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.result-actions.hidden { display: none; }

/* Recent history strip */
.recent-history {
    margin-top: 30px;
    grid-column: 1 / -1;
}

.recent-history h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.history-strip {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 10px;
}

.history-thumb {
    flex-shrink: 0;
    width: 160px;
    height: 80px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.history-thumb:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

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

/* ======================================================
   Spinner
   ====================================================== */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

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

/* ======================================================
   Settings / Provider Cards
   ====================================================== */
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
}

.settings-header h2 {
    font-size: 20px;
}

.provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.provider-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: var(--transition);
    position: relative;
}

.provider-card:hover {
    border-color: var(--border-light);
}

.provider-card.is-default {
    border-color: var(--accent-primary);
}

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

.provider-name {
    font-size: 16px;
    font-weight: 600;
}

.provider-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-openai { background: rgba(16,163,127,0.15); color: #10a37f; }
.badge-stability { background: rgba(138,43,226,0.15); color: #b06cff; }
.badge-flux { background: rgba(255,165,0,0.15); color: #ffa500; }
.badge-custom { background: rgba(52,152,219,0.15); color: #3498db; }

.default-badge {
    background: rgba(233,69,96,0.15);
    color: var(--accent-primary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 8px;
}

.provider-details {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.provider-details div {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    word-break: break-all;
}

.provider-details .label {
    color: var(--text-muted);
    min-width: 70px;
    font-size: 12px;
}

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

.provider-actions .btn { font-size: 12px; padding: 6px 12px; }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}
.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

/* ======================================================
   Modal
   ====================================================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

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

.modal-header h3 { font-size: 17px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

.modal-body { padding: 25px; }

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ======================================================
   History Page
   ====================================================== */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
}

.history-filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.history-filters select,
.history-filters input {
    width: auto;
    min-width: 160px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.design-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
}

.design-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.design-card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-bottom: 1px solid var(--border-color);
}

.design-card-body { padding: 15px; }

.design-card-prompt {
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.design-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-completed { background: rgba(46,204,113,0.15); color: var(--success); }
.status-failed { background: rgba(231,76,60,0.15); color: var(--error); }
.status-pending, .status-generating_2d, .status-generating_3d, .status-composing {
    background: rgba(243,156,18,0.15); color: var(--warning);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 30px;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
    transition: var(--transition);
}

.pagination a:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.pagination .active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* ======================================================
   Toast Notifications
   ====================================================== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--info); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ======================================================
   Image Viewer Modal
   ====================================================== */
.image-viewer {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 250;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.image-viewer.active { display: flex; }

.image-viewer img {
    max-width: 95%;
    max-height: 95vh;
    object-fit: contain;
}

/* ======================================================
   Empty State
   ====================================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 15px; opacity: 0.5; }
.empty-state p { margin-bottom: 8px; }

/* ======================================================
   Responsive
   ====================================================== */
@media (max-width: 1024px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle { display: block; }
    .content.with-sidebar { margin-left: 0; }
    .provider-grid { grid-template-columns: 1fr; }
    .history-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .mobile-menu-btn {
        display: flex;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 99;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        padding: 8px;
        color: var(--text-primary);
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .mobile-menu-btn { display: none; }
}
