/* Freuds Brand Guidelines - Elegant, Professional Design */
:root {
    /* Brand Colors - Based on Freuds Guidelines */
    --charcoal: rgb(36, 31, 33);
    --charcoal-light: rgb(70, 67, 64);
    --sand: rgb(246, 240, 232);
    --sand-dark: rgb(235, 228, 218);
    --cream: rgb(252, 250, 247);
    --accent: var(--charcoal);
    
    /* Text Colors */
    --text-primary: var(--charcoal);
    --text-secondary: var(--charcoal-light);
    --text-muted: rgba(36, 31, 33, 0.5);
    --text-on-dark: #ffffff;
    
    /* Background Colors */
    --bg-primary: var(--sand);
    --bg-secondary: var(--cream);
    --bg-card: #ffffff;
    --bg-hover: var(--sand-dark);
    
    /* Status Colors */
    --success-color: #2d6a4f;
    --error-color: #9d0208;
    --warning-color: #e85d04;
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2.5rem;
    --spacing-xl: 4rem;
    --spacing-2xl: 6rem;
    
    /* Typography */
    --font-serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(36, 31, 33, 0.06);
    --shadow-md: 0 4px 16px rgba(36, 31, 33, 0.08);
    --shadow-lg: 0 8px 32px rgba(36, 31, 33, 0.12);
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.page-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Navigation with Freuds Logo */
.top-nav {
    background: var(--charcoal);
    padding: var(--spacing-sm) var(--spacing-lg);
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.35em;
}

.logo-letter {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-on-dark);
    letter-spacing: 0.3em;
    line-height: 1;
}

.logo-letter:last-child {
    letter-spacing: 0;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--spacing-lg) var(--spacing-md);
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid rgba(36, 31, 33, 0.1);
}

header h1 {
    font-family: var(--font-serif);
    font-size: 2.75rem;
    font-weight: 400;
    margin-bottom: var(--spacing-xs);
    color: var(--text-primary);
    letter-spacing: 0.02em;
    line-height: 1.1;
}

.subtitle {
    font-family: var(--font-sans);
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0.01em;
}

/* Main Content */
main {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    flex: 1;
}

/* Section Headers */
.section-header {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.section-number {
    font-family: var(--font-serif);
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.section-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

/* Input Section */
.input-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(36, 31, 33, 0.06);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.input-container {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.input-container label {
    display: block;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

#url-input {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid rgba(36, 31, 33, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    resize: vertical;
    transition: all 0.25s ease;
    line-height: 1.7;
    flex: 1;
    min-height: 120px;
}

#url-input:focus {
    outline: none;
    border-color: var(--charcoal);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(36, 31, 33, 0.08);
}

#url-input::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

/* Buttons */
.btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    letter-spacing: 0.02em;
}

.btn-primary {
    background: var(--charcoal);
    color: var(--text-on-dark);
}

.btn-primary:hover:not(:disabled) {
    background: var(--charcoal-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid rgba(36, 31, 33, 0.2);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: rgba(36, 31, 33, 0.3);
}

.btn-download {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.875rem;
}

.btn-download svg {
    width: 16px;
    height: 16px;
}

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

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--text-on-dark);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* Button Loading State */
.btn-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-loader::after {
    content: 'Capturing...';
    font-size: 0.95rem;
}

.btn-primary:disabled {
    background: var(--charcoal);
    opacity: 1;
}

.btn-primary:disabled .btn-loader {
    animation: btnPulse 1.5s ease-in-out infinite;
}

@keyframes btnPulse {
    0%, 100% { opacity: 0.85; }
    50% { opacity: 1; }
}

/* Progress Section */
.progress-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(36, 31, 33, 0.06);
}

.progress-content {
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
}

/* Loading Animation Container */
.loading-animation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-bottom: var(--spacing-lg);
    height: 40px;
}

.loading-dot {
    width: 10px;
    height: 10px;
    background: var(--charcoal);
    border-radius: 50%;
    animation: loadingBounce 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.16s; }
.loading-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes loadingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loading Status Text */
.loading-status {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    min-height: 1.5em;
}

.loading-substatus {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: var(--spacing-lg);
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: var(--spacing-md);
}

.progress-bar {
    height: 100%;
    background: var(--charcoal);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* Indeterminate progress bar for initial loading */
.progress-bar.indeterminate {
    width: 30%;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(400%);
    }
}

.progress-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Results Section */
.results-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(36, 31, 33, 0.06);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid rgba(36, 31, 33, 0.08);
}

.results-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.results-stats {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.session-expiry {
    font-size: 0.85rem;
    font-weight: 500;
}

.session-expiry .expiry-ok {
    color: var(--success-color);
}

.session-expiry .expiry-warning {
    color: var(--warning-color);
}

.session-expiry .expiry-critical {
    color: var(--error-color);
    animation: pulse 1s ease-in-out infinite;
}

.session-expiry .expiry-expired {
    color: var(--error-color);
    font-weight: 600;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.results-actions {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.btn-clear-cache {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.875rem;
}

.btn-clear-cache svg {
    width: 16px;
    height: 16px;
}

/* Screenshot Gallery */
.screenshot-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-md);
}

.screenshot-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(36, 31, 33, 0.06);
    transition: all 0.25s ease;
}

.screenshot-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.screenshot-card.error {
    border-color: var(--error-color);
    background: rgba(157, 2, 8, 0.03);
}

.screenshot-preview {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--bg-card);
    cursor: pointer;
    display: block;
    border-bottom: 1px solid rgba(36, 31, 33, 0.06);
}

.screenshot-info {
    padding: var(--spacing-md);
}

.screenshot-title {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.screenshot-url {
    color: var(--text-muted);
    font-size: 0.75rem;
    word-break: break-all;
    margin-bottom: var(--spacing-xs);
    line-height: 1.4;
    font-family: var(--font-sans);
}

.screenshot-actions {
    display: flex;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
}

.btn-small {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
    flex: 1;
}

.btn-success {
    background: var(--charcoal);
    color: var(--text-on-dark);
}

.btn-success:hover {
    background: var(--charcoal-light);
}

/* Error Section */
.error-section {
    background: rgba(157, 2, 8, 0.03);
    border: 1px solid var(--error-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
}

.error-icon {
    color: var(--error-color);
    flex-shrink: 0;
}

.error-message {
    color: var(--error-color);
    font-weight: 500;
    font-size: 0.95rem;
}

/* Footer */
footer {
    text-align: center;
    padding: var(--spacing-md) 0;
    margin-top: auto;
    border-top: 1px solid rgba(36, 31, 33, 0.08);
}

footer p {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: var(--spacing-lg) var(--spacing-sm);
    }
    
    .top-nav {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .logo-letter {
        font-size: 1.25rem;
    }
    
    header {
        margin-bottom: var(--spacing-xl);
        padding-bottom: var(--spacing-lg);
    }
    
    header h1 {
        font-size: 2.5rem;
    }
    
    .input-section,
    .results-section,
    .progress-section {
        padding: var(--spacing-lg);
    }
    
    .section-header {
        flex-direction: column;
        gap: var(--spacing-xs);
    }
    
    .screenshot-gallery {
        grid-template-columns: 1fr;
    }
    
    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .input-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}

/* Modal for full-size screenshot */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(36, 31, 33, 0.95);
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    margin-top: 5%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 40px;
    color: var(--text-on-dark);
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    transition: opacity 0.25s ease;
    font-family: var(--font-sans);
}

.modal-close:hover {
    opacity: 0.6;
}

/* Focus states */
*:focus-visible {
    outline: 2px solid var(--charcoal);
    outline-offset: 2px;
}

/* Smooth transitions */
a, button, input, textarea {
    transition: all 0.25s ease;
}

/* Selection */
::selection {
    background: var(--charcoal);
    color: var(--text-on-dark);
}

/* Crop Modal */
.crop-modal {
    display: none;
    position: fixed;
    z-index: 1100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(36, 31, 33, 0.95);
    backdrop-filter: blur(8px);
    overflow: auto;
}

.crop-modal-content {
    background: var(--bg-card);
    margin: 2% auto;
    padding: 0;
    width: 95%;
    max-width: 1100px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 94vh;
}

.crop-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid rgba(36, 31, 33, 0.08);
    background: var(--bg-secondary);
}

.crop-modal-header h3 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
}

.crop-modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.crop-modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.crop-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--spacing-lg);
    background: var(--charcoal);
    overflow: auto;
    min-height: 300px;
    max-height: calc(94vh - 200px);
}

.crop-canvas-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
    /* Size controlled by JavaScript */
}

/* Overlay divs for darkening non-selected areas */
.crop-overlay {
    position: absolute;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.crop-overlay-top {
    top: 0;
    left: 0;
    right: 0;
}

.crop-overlay-left {
    left: 0;
}

.crop-overlay-right {
    right: 0;
}

.crop-overlay-bottom {
    bottom: 0;
    left: 0;
    right: 0;
}

#crop-canvas {
    display: block;
    /* Canvas size is controlled entirely by JavaScript - do not use CSS constraints */
}

/* Crop Selection Area */
.crop-selection {
    position: absolute;
    border: 2px solid #fff;
    background: transparent;
    cursor: move;
    display: none;
    z-index: 10;
}

.crop-selection.active {
    display: block;
}

/* Crop Handles */
.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid var(--charcoal);
    border-radius: 2px;
}

.crop-handle-nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle-n { top: -6px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle-ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle-e { top: 50%; right: -6px; transform: translateY(-50%); cursor: e-resize; }
.crop-handle-se { bottom: -6px; right: -6px; cursor: se-resize; }
.crop-handle-s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle-sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle-w { top: 50%; left: -6px; transform: translateY(-50%); cursor: w-resize; }

.crop-info {
    padding: var(--spacing-sm) var(--spacing-lg);
    background: var(--bg-secondary);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-top: 1px solid rgba(36, 31, 33, 0.08);
}

.crop-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid rgba(36, 31, 33, 0.08);
    background: var(--bg-card);
}

.crop-modal-actions .btn {
    min-width: 140px;
}

/* Screenshot card crop button */
.btn-crop {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid rgba(36, 31, 33, 0.2);
    gap: 6px;
}

.btn-crop:hover {
    background: var(--bg-hover);
    border-color: rgba(36, 31, 33, 0.3);
}

.btn-crop svg {
    flex-shrink: 0;
}

.crop-btn-text {
    white-space: nowrap;
}

/* Cropped card indicator */
.screenshot-card.cropped {
    border-color: var(--success-color);
}

.screenshot-card.cropped::before {
    content: 'Cropped';
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--success-color);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    z-index: 5;
}

.screenshot-card {
    position: relative;
}

/* Danger outline button */
.btn-danger-outline {
    background: transparent;
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.btn-danger-outline:hover {
    background: rgba(157, 2, 8, 0.08);
}

/* Responsive adjustments for crop modal */
@media (max-width: 768px) {
    .crop-modal-content {
        margin: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .crop-container {
        max-height: calc(100vh - 200px);
    }
    
    #crop-canvas {
        max-height: calc(100vh - 250px);
    }
    
    .crop-modal-actions {
        flex-direction: column;
    }
    
    .crop-modal-actions .btn {
        width: 100%;
    }
}
