/* Global Styles */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #f1f5f9;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.logo {
    padding: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i {
    color: var(--primary-color);
    font-size: 1.75rem;
}

.nav-menu {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s ease;
    gap: 0.75rem;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: white;
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
    border-right: 3px solid #818cf8;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.public-nav,
.public-footer {
    display: flex;
}

.private-nav,
.private-footer {
    display: none;
}

html.has-token .public-nav,
html.has-token .public-footer {
    display: none;
}

html.has-token .private-nav,
html.has-token .private-footer {
    display: flex;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.username {
    font-weight: 500;
    font-size: 0.875rem;
}

.role {
    font-size: 0.75rem;
    color: #94a3b8;
}

.logout-btn {
    color: #94a3b8;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.guest-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.guest-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
}

/* Header */
.content-header {
    background: var(--card-bg);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.header-left h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.breadcrumb {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.balance-widget {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    box-shadow: var(--shadow-lg);
}

.balance-label {
    font-size: 0.75rem;
    opacity: 0.9;
}

.balance-value {
    font-size: 1.75rem;
    font-weight: 700;
}

/* Content Body */
.content-body {
    padding: 2rem;
    flex: 1;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

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

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

.card-header h3 i {
    color: var(--primary-color);
}

.view-all {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.875rem;
}

.view-all:hover {
    text-decoration: underline;
}

.card-body {
    padding: 1.5rem;
}

/* Stats Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.75rem;
    box-shadow: var(--shadow);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.25rem 0;
}

.stat-change {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.stat-change.positive {
    color: var(--success-color);
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

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

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

.btn-outline:hover {
    background: var(--bg-color);
}

.btn-sm {
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
}

.btn-text-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.btn-text-link:hover {
    color: var(--primary-color);
}

/* Action Buttons */
.quick-actions {
    grid-column: 1 / -1;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Landing Page */
.landing-layout {
    display: grid;
    gap: 1.25rem;
}

.hero-section {
    text-align: center;
    padding: 1.5rem 0.5rem 0.5rem;
}

.hero-title {
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    line-height: 1.25;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    max-width: 32rem;
    margin: 0 auto 0.75rem;
}

.guest-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.85rem;
}

.guest-badge i {
    color: var(--primary-color);
}

/* Generator Card */
.generator-card {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow);
    padding: 1rem;
}

.generator-form {
    display: grid;
    gap: 0.875rem;
}

.prompt-box {
    display: grid;
    gap: 0.4rem;
}

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

.prompt-header label {
    font-weight: 600;
    font-size: 0.9rem;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#usage-prompt {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#usage-prompt:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* Quick Tags */
.quick-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag-btn {
    padding: 0.4rem 0.7rem;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tag-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.06);
}

.tag-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Ratio Selector */
.ratio-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ratio-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.ratio-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.ratio-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.7rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ratio-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.ratio-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.ratio-shape {
    display: inline-block;
    border: 1.5px solid currentColor;
    border-radius: 2px;
    opacity: 0.7;
}

.ratio-shape.sq {
    width: 12px;
    height: 12px;
}

.ratio-shape.ws {
    width: 16px;
    height: 9px;
}

.ratio-shape.po {
    width: 9px;
    height: 16px;
}

.ratio-shape.fs {
    width: 14px;
    height: 10.5px;
}

/* Generate Button */
.btn-generate {
    width: 100%;
    padding: 0.9rem 1rem;
    border-radius: 0.75rem;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: var(--shadow);
}

.btn-generate:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

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

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

/* Result Section */
.result-section {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow);
    padding: 1rem;
    display: grid;
    gap: 0.75rem;
}

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

.result-header h3 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.result-header h3 i {
    color: var(--primary-color);
}

.result-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.result-image-wrap {
    position: relative;
    width: 100%;
    border-radius: 0.75rem;
    overflow: hidden;
    background: var(--bg-color);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#generated-image {
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    display: block;
    border-radius: 0.75rem;
}

.image-skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: var(--bg-color);
}

.skeleton-shimmer {
    width: 60%;
    height: 60%;
    border-radius: 0.5rem;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.result-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.result-meta span {
    background: var(--bg-color);
    padding: 0.25rem 0.6rem;
    border-radius: 0.375rem;
}

.result-actions-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.result-actions-bar .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
}

/* Result Placeholder */
.result-placeholder {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow);
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.placeholder-art {
    font-size: 2.5rem;
    color: var(--border-color);
    margin-bottom: 0.5rem;
}

/* Recent Section */
.recent-section {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow);
    padding: 1rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.section-header h3 i {
    color: var(--primary-color);
}

.recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem;
}

.recent-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--bg-color);
    cursor: pointer;
}

.recent-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.recent-item:hover img {
    transform: scale(1.05);
}

.recent-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Highlights */
.landing-highlights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.highlight-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.highlight-icon-wrap {
    width: 40px;
    height: 40px;
    border-radius: 0.625rem;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.highlight-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.highlight-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Bottom Nav */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    z-index: 90;
    justify-content: space-around;
    padding: 0.4rem 0;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.65rem;
    padding: 0.25rem 0.5rem;
    flex: 1;
}

.bottom-nav-item i {
    font-size: 1.1rem;
}

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

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.875rem;
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.data-table tr:hover {
    background: var(--bg-color);
}

.text-center {
    text-align: center;
    color: var(--text-secondary);
}

/* Badge */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 0.75rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

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

/* Form Elements */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: white;
    padding: 1rem 1.25rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: toastSlideIn 0.3s ease;
    min-width: 300px;
}

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

.toast-success {
    border-left: 4px solid var(--success-color);
}

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

.toast-warning {
    border-left: 4px solid var(--warning-color);
}

.toast-info {
    border-left: 4px solid var(--primary-color);
}

/* Responsive */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 0.375rem;
}

.mobile-menu-toggle:hover {
    background: var(--bg-color);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding-bottom: 64px;
    }

    .content-header {
        padding: 1rem;
    }

    .header-left h1 {
        font-size: 1.25rem;
    }

    .content-body {
        padding: 1rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .balance-widget {
        padding: 0.75rem 1rem;
    }

    .balance-value {
        font-size: 1.25rem;
    }

    .sidebar-footer {
        gap: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
    }

    .guest-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .bottom-nav {
        display: flex;
    }

    /* Mobile generator adjustments */
    .generator-card {
        padding: 0.875rem;
    }

    .hero-section {
        padding: 1rem 0.25rem 0.25rem;
    }

    .result-image-wrap {
        min-height: 160px;
    }

    #generated-image {
        max-height: 60vh;
    }

    .recent-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }

    .result-actions-bar .btn {
        min-width: unset;
    }
}

@media (max-width: 380px) {
    .hero-title {
        font-size: 1.4rem;
    }

    .ratio-btn {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    .tag-btn {
        font-size: 0.75rem;
        padding: 0.3rem 0.55rem;
    }

    .result-actions-bar .btn {
        font-size: 0.8rem;
    }
}
