/* ========================================
   Tufter Studio - Main Stylesheet
   ======================================== */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --dark: #1e293b;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px 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);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
}

/* Navigation */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--dark);
}

.logo { font-size: 1.5rem; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--gray-600);
    font-weight: 500;
    transition: var(--transition);
    padding: 0.5rem 0;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: var(--white) !important;
    padding: 0.5rem 1.25rem !important;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

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

/* Hero */
.hero {
    text-align: center;
    padding: 3rem 2rem 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Tool Container */
.tool-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

/* Steps */
.step {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

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

.step h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--gray-100);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.upload-icon { font-size: 3rem; display: block; margin-bottom: 1rem; }
.upload-content p { color: var(--gray-600); font-size: 1rem; }
.upload-content .link { color: var(--primary); font-weight: 500; }
.upload-content small { color: var(--gray-400); }

.preview-container {
    position: relative;
    margin-top: 1rem;
}

.preview-container img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.btn-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger);
    color: var(--white);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
}

/* Palette Grid */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.palette-card {
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition);
    background: var(--white);
}

.palette-card:hover {
    border-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.palette-card.selected {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.palette-card .palette-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.palette-card h4 { font-size: 1rem; margin-bottom: 0.25rem; }
.palette-card p { font-size: 0.875rem; color: var(--gray-500); }
.palette-card .palette-meta {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
}

.palette-meta span {
    background: var(--gray-100);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: var(--gray-600);
}

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.setting input[type="number"],
.setting select {
    padding: 0.625rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    background: var(--white);
}

.setting input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

.range-value {
    font-size: 0.875rem;
    color: var(--primary);
    font-weight: 600;
}

/* Toggle */
.toggle label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.toggle input { display: none; }

.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--gray-300);
    border-radius: 12px;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--white);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::after {
    left: 22px;
}

/* Action Button */
.action-area {
    text-align: center;
    padding: 2rem 0;
}

.btn-generate {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    border: none;
    padding: 1rem 3rem;
    border-radius: var(--radius);
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.3);
}

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

.btn-icon { font-size: 1.25rem; }

/* Progress */
.progress-bar {
    margin-top: 1.5rem;
    background: var(--gray-200);
    border-radius: var(--radius-sm);
    height: 8px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-sm);
    width: 0%;
    transition: width 0.3s ease;
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.progress-text {
    display: block;
    margin-top: 0.5rem;
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Results */
.results {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.results h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

/* Stats */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--white) 100%);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

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

/* Tabs */
.result-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--gray-200);
    padding-bottom: 0;
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
    padding: 1rem 0;
}

.tab-content.active { display: block; }

.tab-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

/* Materials Table */
.materials-section {
    margin-top: 2rem;
}

.materials-section h3 {
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    background: var(--gray-100);
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
}

tr:hover { background: var(--gray-50); }

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--gray-300);
    display: inline-block;
}

/* Download */
.download-area {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: center;
}

.btn-download {
    background: var(--success);
    color: var(--white);
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-download:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-download.secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-download.secondary:hover {
    background: var(--gray-300);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
}

.palette-editor {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

/* Auth Pages */
.auth-page {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.auth-box {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 1.75rem;
}

.auth-box h2 {
    text-align: center;
    color: var(--gray-500);
    font-weight: 400;
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    transition: var(--transition);
}

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

.btn-primary.full {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    border: none;
    cursor: pointer;
}

.auth-link {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--gray-500);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.alert {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
    font-size: 0.875rem;
}

footer p { margin-bottom: 0.5rem; }

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

/* Responsive */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.75rem; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .nav-links { gap: 1rem; }
    .tool-container { padding: 1rem; }
    .settings-grid { grid-template-columns: 1fr; }
    .download-area { flex-direction: column; }
}
