/* =========================================
   Longform Factory - Design System
   현대적 SaaS 대시보드 스타일
   ========================================= */

/* ============== CSS Variables ============== */
:root {
    /* Colors */
    --color-primary: #1E40AF;
    --color-primary-hover: #1E3A8A;
    --color-primary-light: #3B82F6;
    --color-bg: #FFFFFF;
    --color-bg-secondary: #F9FAFB;
    --color-bg-tertiary: #F3F4F6;
    --color-text: #111827;
    --color-text-muted: #6B7280;
    --color-text-light: #9CA3AF;
    --color-border: #E5E7EB;
    --color-border-light: #F3F4F6;

    /* Status Colors */
    --color-success: #10B981;
    --color-warning: #F59E0B;
    --color-error: #EF4444;
    --color-info: #3B82F6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Spacing */
    --sidebar-width: 260px;
    --topbar-height: 64px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ============== Reset & Base ============== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--color-bg-secondary);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ============== Typography ============== */
h1 {
    font-size: 1.875rem;
    font-weight: 700;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

h4 {
    font-size: 1.125rem;
    font-weight: 600;
}

h5 {
    font-size: 1rem;
    font-weight: 600;
}

h6 {
    font-size: 0.875rem;
    font-weight: 600;
}

.text-muted {
    color: var(--color-text-muted);
}

.text-light {
    color: var(--color-text-light);
}

.text-success {
    color: var(--color-success);
}

.text-warning {
    color: var(--color-warning);
}

.text-error {
    color: var(--color-error);
}

.text-primary {
    color: var(--color-primary);
}

/* ============== Layout ============== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 0.9375rem;
}

.nav-item:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
    text-decoration: none;
}

.nav-item.active {
    background: var(--color-primary);
    color: white;
}

.nav-item.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.nav-divider {
    height: 1px;
    background: var(--color-border);
    margin: 0.75rem 1.5rem;
}

.nav-section-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-muted);
}

.page-content {
    padding: 2rem;
    flex: 1;
}

/* ============== Buttons ============== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-border);
}

.btn-danger {
    background: var(--color-error);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #DC2626;
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #059669;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* ============== Forms ============== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-input::placeholder {
    color: var(--color-text-light);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--color-primary);
}

.form-radio {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-radio input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--color-primary);
}

.form-error {
    color: var(--color-error);
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

/* ============== Cards ============== */
.card {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1.0625rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============== Tables ============== */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--color-bg-secondary);
}

.table tbody tr:hover {
    background: var(--color-bg-tertiary);
}

/* ============== Badge ============== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

.badge-primary {
    background: rgba(30, 64, 175, 0.1);
    color: var(--color-primary);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--color-warning);
}

.badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
}

.badge-gray {
    background: var(--color-bg-tertiary);
    color: var(--color-text-muted);
}

/* ============== Modal ============== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.95) translateY(-10px);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============== Toast ============== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 1rem 1.25rem;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-error {
    border-left: 4px solid var(--color-error);
}

.toast-warning {
    border-left: 4px solid var(--color-warning);
}

.toast-info {
    border-left: 4px solid var(--color-info);
}

/* ============== Progress Bar ============== */
.progress {
    height: 8px;
    background: var(--color-bg-tertiary);
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

.progress-bar.success {
    background: var(--color-success);
}

.progress-bar.error {
    background: var(--color-error);
}

/* ============== Loading ============== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* ============== Empty State ============== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

/* ============== Scene Card ============== */
.scene-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    overflow: hidden;
}

.scene-card-header {
    padding: 1rem 1.25rem;
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.scene-number {
    font-weight: 700;
    color: var(--color-primary);
    font-size: 1rem;
}

.scene-cast {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.scene-card-body {
    padding: 1.25rem;
}

.scene-script {
    font-size: 0.9375rem;
    color: var(--color-text);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.scene-prompt {
    background: var(--color-bg-tertiary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    font-family: 'Monaco', 'Consolas', monospace;
}

.scene-image-container {
    position: relative;
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 1rem;
}

.scene-image {
    width: 100%;
    height: auto;
    display: block;
}

.scene-image-placeholder {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-light);
}

.scene-time-range {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.scene-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.scene-effects {
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.effects-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.effects-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
    min-width: 120px;
}

.effects-options {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ============== Stats Grid ============== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

/* ============== Tabs ============== */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text-muted);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all var(--transition-fast);
}

.tab:hover {
    color: var(--color-text);
}

.tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ============== Grid Utilities ============== */
.grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* ============== Flex Utilities ============== */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: 0.25rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

.flex-1 {
    flex: 1;
}

/* ============== Spacing Utilities ============== */
.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 0.75rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

/* ============== Auth Pages (Login/Register) ============== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-bg-secondary) 0%, var(--color-bg) 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h1 {
    font-size: 1.5rem;
    color: var(--color-primary);
}

.auth-logo p {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
    margin-top: 0.5rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

/* ============== Pending Screen ============== */
.pending-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    padding: 2rem;
}

.pending-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
}

.pending-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.pending-message {
    color: var(--color-text-muted);
    margin-bottom: 2rem;
    max-width: 400px;
}

/* ============== Responsive ============== */
/* 모바일 메뉴 버튼 */
.mobile-menu-btn {
    display: none;
    background: var(--color-primary);
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem 0.7rem;
    color: white;
    border-radius: var(--radius-md);
    line-height: 1;
    transition: all var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--color-primary-hover);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }

    .sidebar-close-btn {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page-content {
        padding: 1rem;
    }

    .topbar {
        padding: 0 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.5rem;
        margin: 1rem;
    }

    .scene-actions {
        flex-direction: column;
    }

    .scene-actions .btn {
        width: 100%;
    }
}