/* ======================================================
   Bag Design Generator — Design System v2
   Day / Night theme support
   ====================================================== */

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

/* --- Dark Theme (default) --- */
:root,
[data-theme="dark"] {
    --bg-primary: #0c0c14;
    --bg-secondary: #13131f;
    --bg-surface: #1a1a2b;
    --bg-card: #1e1e32;
    --bg-input: #0f0f1a;
    --bg-elevated: #22223a;
    --accent-primary: #e94560;
    --accent-secondary: #1a3a5c;
    --accent-hover: #ff6b81;
    --accent-soft: rgba(233, 69, 96, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #a8a8be;
    --text-muted: #6e6e88;
    --border-color: #2a2a42;
    --border-light: #3a3a58;
    --success: #2ecc71;
    --error: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
    --overlay: rgba(0, 0, 0, 0.65);
    --gradient-accent: linear-gradient(135deg, #e94560 0%, #c23152 100%);
    --gradient-surface: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-primary: #f4f5f9;
    --bg-secondary: #ffffff;
    --bg-surface: #eef0f6;
    --bg-card: #ffffff;
    --bg-input: #f8f9fc;
    --bg-elevated: #ffffff;
    --accent-primary: #d63854;
    --accent-secondary: #e8f0fa;
    --accent-hover: #b82e48;
    --accent-soft: rgba(214, 56, 84, 0.08);
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a68;
    --text-muted: #8888a0;
    --border-color: #dde1ec;
    --border-light: #c8cedd;
    --shadow-sm: 0 2px 8px rgba(26, 26, 46, 0.06);
    --shadow: 0 8px 32px rgba(26, 26, 46, 0.1);
    --shadow-lg: 0 16px 48px rgba(26, 26, 46, 0.14);
    --overlay: rgba(26, 26, 46, 0.45);
    --gradient-accent: linear-gradient(135deg, #d63854 0%, #a82840 100%);
    --gradient-surface: linear-gradient(180deg, #ffffff 0%, #f4f5f9 100%);
}

:root {
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

html { scroll-behavior: smooth; }

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ======================================================
   Theme Toggle
   ====================================================== */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-soft);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }
.theme-toggle.is-dark .icon-sun { display: block; }
.theme-toggle:not(.is-dark) .icon-moon { display: block; }

/* ======================================================
   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: 22px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--accent-primary);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.3px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-soft);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.nav-menu {
    list-style: none;
    padding: 16px 12px;
    flex: 1;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 8px 14px 6px;
    margin-top: 8px;
}

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

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

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

.nav-link.active svg { stroke: var(--accent-primary); }

.sidebar-footer {
    padding: 16px 18px;
    border-top: 1px solid var(--border-color);
}

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

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-footer-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sidebar-footer-actions .logout-btn { flex: 1; }

/* ======================================================
   Top Bar
   ====================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    margin: -30px -30px 28px;
    backdrop-filter: blur(12px);
}

[data-theme="dark"] .topbar { background: rgba(19, 19, 31, 0.92); }
[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.92); }

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.topbar-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-menu-btn {
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px;
    color: var(--text-primary);
    cursor: pointer;
}

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

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

/* ======================================================
   Page Header (inline)
   ====================================================== */
.page-hero {
    margin-bottom: 28px;
}

.page-hero h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}

.page-hero p {
    color: var(--text-muted);
    font-size: 14px;
}

/* ======================================================
   Cards & Panels
   ====================================================== */
.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

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

.panel-card-header h2 {
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-card-header .badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-soft);
    color: var(--accent-primary);
}

/* ======================================================
   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: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--gradient-accent);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(233, 69, 96, 0.3);
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.4);
}

.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);
    background: var(--accent-soft);
}

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

.logout-btn { font-size: 12px; padding: 7px 12px; }

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

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

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 11px 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 var(--accent-soft);
}

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='%238888a0'%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: 5px;
}

/* ======================================================
   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: var(--error); }
.alert-success { background: rgba(46,204,113,0.1); border-color: var(--success); color: var(--success); }
.alert-info { background: rgba(52,152,219,0.1); border-color: var(--info); color: var(--info); }
.alert-warning { background: rgba(243,156,18,0.1); border-color: var(--warning); color: var(--warning); }

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

/* ======================================================
   Login Page
   ====================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--gradient-surface);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    pointer-events: none;
}

.login-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
    bottom: -150px;
    left: -150px;
    pointer-events: none;
}

.login-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

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

.login-container {
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 1;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
}

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

.login-logo {
    width: 64px;
    height: 64px;
    background: var(--accent-soft);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    color: var(--accent-primary);
}

.login-header h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

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

.login-features {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 14px;
}

.login-feature-tag {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.login-form .form-group { margin-bottom: 18px; }
.login-form .btn-block { margin-top: 8px; padding: 13px; font-size: 15px; }

/* ======================================================
   Dashboard
   ====================================================== */
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 24px;
    max-width: 1680px;
}

.generation-panel,
.result-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.generation-panel h2,
.result-panel h2 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.prompt-textarea {
    min-height: 110px;
    font-size: 14px;
    line-height: 1.6;
}

/* Template Grid */
.template-section {
    margin-bottom: 20px;
}

.template-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.template-section-header label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.template-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-surface);
    padding: 2px 8px;
    border-radius: 10px;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding: 2px;
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    user-select: none;
}

.template-card:hover {
    border-color: var(--accent-primary);
    background: var(--accent-soft);
    transform: translateY(-1px);
}

.template-card.active {
    border-color: var(--accent-primary);
    background: var(--accent-soft);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.template-card .template-icon {
    font-size: 20px;
    line-height: 1;
}

.template-card .template-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.2;
}

.template-card.active .template-label { color: var(--accent-primary); }

.selected-template-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    border-left: 3px solid var(--accent-primary);
    display: none;
}

.selected-template-hint.visible { display: block; }

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

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

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

.result-panel { display: flex; flex-direction: column; }

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

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

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

.placeholder-icon {
    width: 72px;
    height: 72px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    border: 1px solid var(--border-color);
}

.placeholder-text p { margin-bottom: 6px; font-size: 14px; }
.placeholder-text .placeholder-sub { font-size: 12px; color: var(--text-muted); }

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

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

.view-labels {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.view-label {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 6px;
    background: var(--bg-surface);
    border-radius: var(--radius);
}

/* Recent history */
.recent-history {
    grid-column: 1 / -1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
}

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

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

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

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

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

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

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

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

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

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

.provider-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.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: 14px;
}

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

.provider-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    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: var(--accent-soft);
    color: var(--accent-primary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    margin-left: 8px;
}

.provider-details { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.provider-details div { display: flex; gap: 8px; margin-bottom: 5px; 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: var(--overlay);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

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

.modal {
    background: var(--bg-card);
    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-lg);
}

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

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

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

.modal-body { padding: 24px; }

.modal-footer {
    padding: 14px 24px;
    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: 22px;
}

.history-header h2 { font-size: 20px; font-weight: 700; }

.history-filters {
    display: flex;
    gap: 12px;
    margin-bottom: 18px;
    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: 18px;
}

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

.design-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow);
}

.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;
    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 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
}

.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
   ====================================================== */
.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;
    font-weight: 500;
    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
   ====================================================== */
.image-viewer {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    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.4; }
.empty-state p { margin-bottom: 8px; }

/* ======================================================
   User Management
   ====================================================== */
.user-table-wrap { overflow-x: auto; margin-top: 20px; }

.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.user-table th, .user-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.user-table th {
    color: var(--text-muted);
    font-weight: 700;
    background: var(--bg-surface);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-table tr:hover td { background: var(--bg-surface); }

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

.role-badge.role-admin {
    background: var(--accent-soft);
    color: var(--accent-primary);
    border: 1px solid rgba(233, 69, 96, 0.25);
}

.role-badge.role-user {
    background: rgba(52,152,219,0.12);
    color: var(--info);
    border: 1px solid rgba(52,152,219,0.25);
}

.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
}

.form-control-sm {
    padding: 7px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    width: 100%;
}

.modal-wide { max-width: 860px; width: 95vw; }

.detail-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

.detail-analysis {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

.detail-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.detail-prompt { margin-bottom: 16px; }

.detail-prompt-text {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

/* Calculator overrides */
.calculator-container .input-panel,
.calculator-container .output-panel {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
}

/* ======================================================
   Responsive
   ====================================================== */
@media (max-width: 1200px) {
    .template-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
    .dashboard-container { grid-template-columns: 1fr; }
    .template-grid { grid-template-columns: repeat(5, 1fr); max-height: 160px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .content.with-sidebar { margin-left: 0; }
    .content { padding: 16px; }
    .topbar { margin: -16px -16px 20px; padding: 0 16px; }
    .mobile-menu-btn { display: flex; }
    .provider-grid { grid-template-columns: 1fr; }
    .history-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .template-grid { grid-template-columns: repeat(4, 1fr); }
    .topbar-subtitle { display: none; }
}

@media (max-width: 480px) {
    .template-grid { grid-template-columns: repeat(3, 1fr); }
    .login-card { padding: 28px 22px; }
}

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

@media (max-width: 600px) {
    .detail-images { grid-template-columns: 1fr; }
    .user-table th:nth-child(5),
    .user-table td:nth-child(5) { display: none; }
}