/* ========================================
   Hair.Gen AI — Professional Medical System
   Color System: Teal-based healthcare theme
   ======================================== */

:root {
    --color-primary: #0F766E;
    --color-primary-dark: #0D4F4F;
    --color-accent: #14B8A6;
    --color-bg: #F8FAFB;
    --color-surface: #FFFFFF;
    --color-text: #1E293B;
    --color-text-secondary: #64748B;
    --color-success: #059669;
    --color-warning: #D97706;
    --color-border: #E2E8F0;
}

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

body {
    font-family: 'Noto Sans KR', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    width: 100%;
}

.container {
    max-width: 100%;
    margin: 0;
    padding: 15px 20px;
}

header {
    background: var(--color-surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    padding: 0;
    margin-bottom: 0;
    border-bottom: 2px solid var(--color-primary);
}

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

h1 {
    color: var(--color-primary-dark);
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    font-weight: 400;
    margin: 0;
}

.main-content {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    margin: 0 16px 20px 16px;
    border: 1px solid var(--color-border);
}

/* Step Progress Bar */
.step-progress {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 8px 24px;
}

.step-progress-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0 32px;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.step-item:hover {
    background: rgba(15, 118, 110, 0.05);
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    border: 2px solid var(--color-border);
    color: var(--color-text-secondary);
    background: var(--color-surface);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.step-label {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    font-weight: 500;
    transition: color 0.2s ease;
}

.step-connector {
    width: 40px;
    height: 2px;
    background: var(--color-border);
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.step-item.active .step-number {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.step-item.active .step-label {
    color: var(--color-primary);
    font-weight: 600;
}

.step-item.completed .step-number {
    background: var(--color-success);
    border-color: var(--color-success);
    color: white;
}

.step-item.completed .step-label {
    color: var(--color-success);
}

.step-connector.completed {
    background: var(--color-success);
}

/* Upload Section */
.upload-section {
    text-align: center;
    padding: 0;
    border: none;
    border-radius: 12px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.upload-section.drag-over {
    border-color: var(--color-primary);
    background: rgba(15, 118, 110, 0.03);
}

.upload-section h2 {
    color: var(--color-text);
    margin-bottom: 20px;
}

.upload-area {
    position: relative;
}

#fileInput {
    display: none;
}

.upload-btn {
    background: var(--color-primary);
    color: white;
    padding: 12px 32px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 8px;
}

.upload-btn:hover {
    background: var(--color-primary-dark);
}

.camera-btn {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

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

.preview-section {
    margin: 24px 0;
}

.preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    flex-wrap: wrap;
}

.preview-box {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
}

.preview-box h3 {
    color: var(--color-text);
    margin-bottom: 10px;
}

.preview-image {
    width: 100%;
    max-width: 400px;
    height: 400px;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
    margin: 0 auto;
}

.templates-section {
}

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

.filter-btn {
    padding: 8px 20px;
    border: 2px solid var(--color-border);
    background: white;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

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

.templates-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.template-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 2px solid transparent;
    position: relative;
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.template-card.selected {
    border-color: var(--color-primary);
}

.template-image {
    width: 100%;
    height: 180px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #f1f5f9;
}

.template-info {
    padding: 12px;
}

.template-name {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
    font-size: 0.85rem;
}

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

/* Template hover overlay */
.template-card:hover::after {
    content: '선택';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 118, 110, 0.7);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 8px;
}

.template-card.ring-2::after {
    display: none;
}

.process-btn {
    background: var(--color-primary);
    color: white;
    padding: 14px 48px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    margin: 24px auto;
    transition: all 0.2s ease;
}

.process-btn:hover {
    background: var(--color-primary-dark);
}

.process-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.loading {
    display: none;
    text-align: center;
    padding: 50px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-border);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.animate-shake {
    animation: shake 0.4s ease-in-out;
}

.result-section {
    text-align: center;
}

.result-container {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 24px 0;
    flex-wrap: wrap;
    align-items: flex-start;
}

.result-box {
    max-width: 400px;
    text-align: center;
    position: relative;
}

.result-box h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    padding: 8px 16px;
    border-radius: 8px;
}

.result-box:first-child h3 {
    background: #FEE2E2;
    color: #991B1B;
}

.result-box:last-child h3 {
    background: #D1FAE5;
    color: #065F46;
}

.result-image {
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.result-image:hover {
    transform: scale(1.02);
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

/* Comparison Slider */
.comparison-slider {
    max-width: 900px;
    margin: 24px auto;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.comparison-container {
    position: relative;
    width: 100%;
    height: 500px;
}

.comparison-image {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.comparison-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.before-image-container {
    z-index: 2;
    width: 50%;
}

.after-image-container {
    z-index: 1;
}

.comparison-slider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    background: white;
    cursor: ew-resize;
    z-index: 3;
    transform: translateX(-50%);
}

.handle-bar {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.handle-bar::before,
.handle-bar::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 0;
    height: 0;
    border-style: solid;
    transform: translateY(-50%);
}

.handle-bar::before {
    left: 5px;
    border-width: 6px 6px 6px 0;
    border-color: transparent #333 transparent transparent;
}

.handle-bar::after {
    right: 5px;
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent #333;
}

.comparison-label {
    position: absolute;
    top: 20px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-weight: bold;
    border-radius: 20px;
    z-index: 4;
}

.before-image-container .comparison-label {
    left: 20px;
}

.after-image-container .comparison-label {
    right: 20px;
}

.view-toggle {
    text-align: center;
    margin: 16px 0;
}

.download-btn {
    background: var(--color-success);
}

.restart-btn {
    background: var(--color-warning);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
}

.close-modal {
    float: right;
    font-size: 24px;
    cursor: pointer;
    color: #94a3b8;
}

.close-modal:hover {
    color: var(--color-text);
}

#cameraModal video {
    width: 100%;
    border-radius: 10px;
    margin: 20px 0;
}

.camera-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.error-message {
    background: #EF4444;
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    display: none;
}

.success-message {
    background: var(--color-success);
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    display: none;
}

/* History Section */
.history-section {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    margin-top: 24px;
    border: 1px solid var(--color-border);
}

.history-section h2 {
    color: var(--color-text);
    margin-bottom: 20px;
    text-align: left;
    font-size: 1.1rem;
}

.history-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.history-item {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    border: 1px solid var(--color-border);
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.history-item-images {
    position: relative;
    width: 100%;
    height: 180px;
    overflow: hidden;
}

.history-item-images img {
    width: 50%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
}

.history-item-images .history-before {
    left: 0;
    border-right: 2px solid white;
}

.history-item-images .history-after {
    right: 0;
}

.history-item-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.5) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-item:hover .history-item-overlay {
    opacity: 1;
}

.history-item-labels {
    position: absolute;
    bottom: 8px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-item:hover .history-item-labels {
    opacity: 1;
}

.history-item-info {
    padding: 10px 12px;
    text-align: left;
}

.history-item-date {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.history-item-template {
    font-size: 0.8rem;
    color: var(--color-text);
    font-weight: 600;
    margin-top: 4px;
}

.history-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 500;
    background: #F0FDFA;
    color: var(--color-primary);
    border: 1px solid #CCFBF1;
    margin-top: 4px;
}

/* History delete button */
.history-delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-delete-btn:hover {
    background: rgba(239, 68, 68, 1);
    transform: scale(1.1);
}

.history-item:hover .history-delete-btn {
    opacity: 1;
}

/* Delete confirm modal */
.delete-confirm-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.delete-confirm-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.delete-confirm-content h3 {
    color: var(--color-text);
    margin-bottom: 15px;
}

.delete-confirm-content p {
    color: var(--color-text-secondary);
    margin-bottom: 25px;
}

.delete-confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.delete-confirm-buttons button {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.confirm-delete {
    background: #EF4444;
    color: white;
}

.confirm-delete:hover {
    background: #DC2626;
}

.cancel-delete {
    background: #f1f5f9;
    color: var(--color-text);
}

.cancel-delete:hover {
    background: #e2e8f0;
}

.no-history {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 40px;
    font-style: italic;
}

/* Responsive */
@media (min-width: 1280px) {
    .templates-grid {
        grid-template-columns: repeat(5, 1fr);
    }

    .history-container {
        grid-template-columns: repeat(5, 1fr);
    }

    .comparison-slider {
        max-width: 1000px;
    }

    .comparison-container {
        height: 600px;
    }
}

@media (max-width: 1024px) {
    .templates-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .history-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .templates-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .preview-container, .result-container {
        flex-direction: column;
    }

    h1 {
        font-size: 1.1rem;
    }

    .step-item {
        padding: 6px 10px;
    }

    .step-label {
        font-size: 0.7rem;
    }

    .step-connector {
        width: 24px;
    }
}

@media (max-width: 480px) {
    .templates-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .preview-image {
        max-width: 300px;
        height: 350px;
    }

    .preview-box {
        max-width: 300px;
    }

    .step-label {
        display: none;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        max-width: 100%;
    }

    header, .step-progress, footer,
    .action-buttons, .view-toggle,
    .upload-section, .templates-section,
    .history-section, #errorAlert, #successAlert {
        display: none !important;
    }

    .result-section {
        display: block !important;
    }

    .comparison-slider {
        display: none !important;
    }

    .result-container {
        display: flex !important;
    }

    .result-image {
        max-width: 300px;
        box-shadow: none;
    }

    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 24px;
        padding-bottom: 16px;
        border-bottom: 2px solid var(--color-primary);
    }

    .print-header h2 {
        font-size: 1.2rem;
        color: var(--color-primary-dark);
    }

    .print-header p {
        font-size: 0.8rem;
        color: var(--color-text-secondary);
    }
}

.print-header {
    display: none;
}
