/* FertilityFriend Line Reader - Styles */

/* CSS Variables - FF Color Scheme */
:root {
    --ff-purple: #8E4585;
    --ff-purple-light: #c47abd;
    --ff-purple-dark: #6a3364;
    --bg-dark: #1a1a1a;
    --bg-medium: #2a2a2a;
    --bg-light: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --control-green: #006400;
    --control-green-light: #228B22;
    --test-red: #8B0000;
    --test-red-light: #B22222;
    --success-green: #4caf50;
    --danger-red: #dc3545;
}

/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--ff-purple) 0%, var(--ff-purple-dark) 100%);
    color: white;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    gap: 8px;
}

.logo {
    height: 36px;
    width: auto;
}

.logo-text {
    color: white;
    font-size: 18px;
    font-weight: bold;
}

.app-icon {
    height: 44px;
    width: 44px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.site-name {
    color: white;
    font-size: 18px;
    font-weight: 600;
}

.site-name .big-letter {
    font-size: 1.3em;
}

.title {
    font-size: 22px;
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
}

/* Sections */
section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ff-purple);
    margin-bottom: 8px;
}

.section-desc {
    color: #666;
    font-size: 14px;
    margin-bottom: 16px;
}

/* Description Section */
.description-section {
    text-align: left;
    padding: 0 16px;
    margin-bottom: 8px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.description-section p {
    color: #666;
    font-size: 15px;
    line-height: 1.5;
}

/* Upload Section */
.upload-section {
    text-align: center;
}

.upload-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.upload-btn.primary {
    background: var(--ff-purple);
    color: white;
}

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

.upload-btn.secondary {
    background: white;
    color: var(--ff-purple);
    border: 2px solid var(--ff-purple);
}

.upload-btn.secondary:hover {
    background: #f8f4f7;
}

.upload-hint {
    color: #888;
    font-size: 13px;
    margin-top: 12px;
}

/* Icons */
.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Canvas Section */
.canvas-section {
    padding: 16px;
}

.canvas-section.hidden {
    display: none;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: #f0f0f0;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #666;
}

.mode-btn.active {
    background: var(--ff-purple);
    color: white;
}

/* Instructions */
.instructions {
    background: #f8f8f8;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #555;
}

.instructions.hidden {
    display: none;
}

/* Canvas Wrapper */
.canvas-wrapper {
    position: relative;
    overflow: visible;
    margin-top: 30px;
    width: 100%;
    min-height: 300px;
    max-height: 500px;
    background-color: black;
    border-radius: 8px;
    touch-action: none;
}

.canvas-clip-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 300px;
    overflow: hidden;
    isolation: isolate;
    contain: layout paint;
}

/* Canvases */
#imageCanvas, #overlayCanvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    will-change: transform;
}

#overlayCanvas {
    pointer-events: auto;
    cursor: pointer;
}

/* Centerline */
.centerline-horizontal {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: repeating-linear-gradient(
        to right,
        rgba(255, 255, 255, 0.7) 0px,
        rgba(255, 255, 255, 0.7) 5px,
        transparent 5px,
        transparent 10px
    );
    pointer-events: none;
    z-index: 10;
    transform: translateY(-0.5px);
}

.centerline-horizontal.hidden {
    display: none;
}

/* Guide Lines */
.guideline-vertical {
    position: absolute;
    top: -30px;
    height: calc(100% + 30px);
    width: 24px; /* Wide hit area */
    pointer-events: auto;
    cursor: ew-resize;
    z-index: 10;
    transform: translateX(-12px); /* Center on left position */
    touch-action: none;
}

.guideline-vertical::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%); /* Center the visible line */
    top: 30px; /* Start below the labels */
    bottom: 0;
    width: 4px;
}

.guideline-vertical.control-line::before {
    background: var(--control-green);
}

.guideline-vertical.test-line::before {
    background: var(--test-red);
}

.guideline-vertical.hidden {
    display: none;
}

/* Guide Line Labels */
.guideline-label {
    position: absolute;
    top: -28px;
    transform: translateX(-50%);
    font-weight: bold;
    font-size: 18px;
    padding: 6px 12px;
    pointer-events: auto;
    cursor: ew-resize;
    z-index: 11;
    user-select: none;
    touch-action: none;
    border-radius: 4px;
}

.guideline-label.control-label {
    color: var(--control-green-light);
}

.guideline-label.test-label {
    color: var(--test-red-light);
}

.guideline-label.hidden {
    display: none;
}

/* Buttons */
.button-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.button-row.hidden {
    display: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #ddd;
    background: white;
    color: #333;
}

.btn:hover {
    background: #f5f5f5;
}

.btn.primary {
    background: var(--ff-purple);
    color: white;
    border-color: var(--ff-purple);
}

.btn.primary:hover {
    background: var(--ff-purple-dark);
}

.btn.danger {
    background: var(--danger-red);
    color: white;
    border-color: var(--danger-red);
}

.btn.danger:hover {
    background: #c82333;
}

/* Results Section */
.results-section {
    margin-top: 16px;
    padding: 16px;
    background: #f8f8f8;
    border-radius: 8px;
}

.results-section.hidden {
    display: none;
}

.results-grid {
    display: flex;
    justify-content: space-around;
    margin-bottom: 12px;
}

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

.result-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
}

.result-value {
    display: block;
    font-size: 20px;
    font-weight: bold;
    margin-top: 4px;
}

.result-value.control {
    color: var(--control-green);
}

.result-value.test {
    color: var(--test-red);
}

.interpretation {
    font-size: 14px;
    line-height: 1.5;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    color: #555;
}

/* Progression Section */
.progression-section {
    text-align: center;
}

.progression-list {
    margin-top: 16px;
    text-align: left;
}

.progression-list.hidden {
    display: none;
}

.progression-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.progression-item {
    position: relative;
    height: 50px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.progression-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    background: #1a1a1a;
}

.progression-item:hover {
    border-color: var(--ff-purple);
}

.progression-item .item-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
}

.progression-item .item-number {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--ff-purple);
    color: white;
    font-size: 12px;
    font-weight: bold;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progression-item .item-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 4px;
    background: rgba(220, 53, 69, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.progression-item .item-delete svg {
    width: 14px;
    height: 14px;
    stroke: white;
}

.progression-item .item-delete:hover {
    background: rgba(200, 35, 51, 1);
}

.progression-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Progression Preview */
.progression-preview {
    margin-top: 16px;
    text-align: center;
}

.progression-preview.hidden {
    display: none;
}

.progression-preview img {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.preview-actions {
    margin-top: 12px;
}

/* Help Section */
.help-section {
    background: #fafafa;
}

.help-section h3 {
    color: var(--ff-purple);
    margin-bottom: 16px;
}

.help-content {
    display: grid;
    gap: 16px;
}

.help-item h4 {
    font-size: 15px;
    color: #333;
    margin-bottom: 8px;
}

.help-item ol {
    padding-left: 20px;
    color: #666;
    font-size: 14px;
}

.help-item li {
    margin-bottom: 4px;
}

.privacy-note {
    margin-top: 16px;
    font-size: 14px;
    color: #666;
}

/* Footer */
.footer {
    background: var(--bg-dark);
    color: var(--text-secondary);
    padding: 20px 16px;
    text-align: center;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer a {
    color: var(--ff-purple-light);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.disclaimer {
    font-size: 12px;
    margin-top: 8px;
    opacity: 0.7;
}

.copyright {
    font-size: 11px;
    margin-top: 16px;
    opacity: 0.6;
}

.footer-downloads {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
    margin: 16px 0;
}

.footer-free {
    color: #4caf50;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 1px;
}

.footer-downloads .store-badge {
    height: 36px;
    width: auto;
}

.footer-downloads .btn-webapp {
    height: 36px;
    font-size: 13px;
    padding: 6px 14px;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    font-size: 18px;
    color: var(--ff-purple);
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: #666;
}

.modal-body {
    padding: 16px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--ff-purple);
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid #eee;
    justify-content: flex-end;
}

/* Full-screen modal on mobile (metadata and crop modals) */
@media (max-width: 600px) {
    #metadataModal,
    #cropModal {
        padding: 0;
        align-items: stretch;
    }

    #metadataModal .modal-content,
    #cropModal .modal-content {
        max-width: none;
        max-height: none;
        width: 100%;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    #metadataModal .modal-header,
    #cropModal .modal-header {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
    }

    #metadataModal .modal-body,
    #cropModal .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #metadataModal .modal-footer,
    #cropModal .modal-footer {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: white;
        z-index: 1;
    }

    /* Storage modals stay centered but with some padding */
    .storage-modal-content {
        margin: 16px;
        max-height: calc(100vh - 32px);
    }
}

.crop-modal-footer {
    border-top: none;
    border-bottom: 1px solid #eee;
    padding: 12px 16px;
}

/* Crop Modal */
.crop-modal-content {
    max-width: 500px;
}

.crop-modal-body {
    padding: 16px;
}

.crop-instructions {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
    text-align: center;
}

.crop-controls {
    margin-bottom: 12px;
}

.crop-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    touch-action: none;
}

#cropCanvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    will-change: transform;
}

.crop-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    /* Radial gradient creates the darkened edges effect */
    background: radial-gradient(
        circle at center,
        transparent 35%,
        rgba(0, 0, 0, 0.6) 70%
    );
}

.crop-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 75%;
    height: 20%; /* Strip for test strips */
    transform: translate(-50%, -50%);
    border: 2px dashed rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    pointer-events: none;
}

.crop-align-line {
    position: absolute;
    right: 25%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(0, 128, 0, 0.9);
    box-shadow: 0 0 4px rgba(0, 255, 0, 0.5);
}

.crop-align-label {
    position: absolute;
    right: 25%;
    top: -20px;
    transform: translateX(50%);
    font-size: 10px;
    color: rgba(0, 200, 0, 0.9);
    white-space: nowrap;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

.crop-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    padding: 10px;
    border-radius: 50%;
}

.icon-btn svg {
    width: 100%;
    height: 100%;
}

/* Add to Progression Button */
.add-to-progression-row {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.btn.secondary {
    background: white;
    color: var(--ff-purple);
    border: 2px solid var(--ff-purple);
}

.btn.secondary:hover {
    background: #f8f4f7;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 600px) {
    .header-content {
        gap: 12px;
    }

    .logo {
        height: 28px;
    }

    .app-icon {
        height: 36px;
        width: 36px;
    }

    .site-name {
        font-size: 14px;
    }

    .title {
        font-size: 18px;
    }

    .mode-toggle {
        flex-direction: column;
    }

    .help-item ol {
        font-size: 13px;
    }
}

@media (max-width: 400px) {
    .upload-btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* ==================== Promo Card ==================== */
.promo-card {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    padding: 24px;
    margin: 24px auto;
    max-width: 600px;
}

.promo-content {
    text-align: center;
}

.promo-text h3 {
    color: #c47abd;
    font-size: 24px;
    font-weight: 600;
    margin: 0 0 10px 0;
}

.promo-text p {
    color: #aaaaaa;
    font-size: 16px;
    line-height: 1.5;
    margin: 0 0 12px 0;
}

.promo-free {
    color: #4caf50;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    margin: 0 0 16px 0;
}

.download-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

.store-link {
    display: block;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.store-link:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.store-badge {
    height: 40px;
    width: auto;
}

/* Web App Button */
.btn-webapp {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background-color: #000000;
    border: 1px solid #a6a6a6;
    border-radius: 5px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    height: 40px;
    box-sizing: border-box;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-webapp:hover {
    background-color: #8E4585;
    border-color: #8E4585;
}

.btn-webapp svg {
    width: 18px;
    height: 18px;
}

/* Platform-specific visibility - JS handles this, but set defaults */
#iosLink, #androidLink {
    display: block;
}
#webappLink {
    display: inline-flex;
}

/* Promo card mobile adjustments */
@media (max-width: 600px) {
    .promo-card {
        margin: 16px;
        padding: 20px 16px;
    }

    .promo-text h3 {
        font-size: 20px;
    }

    .promo-text p {
        font-size: 14px;
    }

    .promo-free {
        font-size: 16px;
    }

    .download-buttons {
        flex-direction: column;
        gap: 10px;
    }
}

/* ==================== Storage Modals ==================== */
.storage-modal-content {
    max-width: 360px;
    text-align: center;
}

.storage-modal-body {
    padding: 20px 24px;
}

.storage-prompt {
    font-size: 16px;
    color: #333;
    margin-bottom: 16px;
}

.storage-benefits {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

.storage-benefits li {
    position: relative;
    padding-left: 24px;
    margin-bottom: 10px;
    color: #555;
    font-size: 14px;
}

.storage-benefits li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: #4caf50;
    font-weight: bold;
}

.storage-modal-footer {
    flex-direction: column;
    gap: 10px;
    padding: 16px 24px 24px;
}

.storage-modal-footer .btn {
    width: 100%;
    justify-content: center;
}

/* Storage Stats in Manage Data Modal */
.storage-stats {
    text-align: left;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: #666;
    font-size: 14px;
}

.stat-value {
    color: #333;
    font-weight: 500;
    font-size: 14px;
}

/* Storage Indicator */
.storage-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    margin-bottom: 16px;
    background: #f0f8f0;
    border: 1px solid #c8e6c9;
    border-radius: 8px;
    font-size: 14px;
    color: #2e7d32;
}

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

.storage-indicator-icon {
    font-size: 16px;
}

.storage-indicator-text {
    flex: 1;
}

.storage-indicator-link {
    background: none;
    border: none;
    color: var(--ff-purple);
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.storage-indicator-link:hover {
    color: var(--ff-purple-dark);
}
