:root {
    --color-primary: #D2002D;
    --color-primary-dark: #A50024;
    --color-background: #F8F9FA;
    --color-surface: #FFFFFF;
    --color-text: #1A1A1A;
    --color-text-secondary: #6E6E73;
    --color-border: #E5E5EA;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --picker-height: 216px;
    --picker-item-height: 44px;
}

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

html, body {
    font-family: var(--font-family);
    background-color: var(--color-background);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    /* Disable page scrolling completely */
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
    /* Prevent bounce/elastic scrolling on mobile */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    /* Prevent text selection and highlights */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent tap highlighting */
    -webkit-tap-highlight-color: transparent;
}

/* Additional mobile app optimizations */
input, button, textarea, select {
    /* Prevent zoom on focus for iOS */
    font-size: 16px;
    /* Remove default styling */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* Prevent callouts and user selection */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Prevent any possible page movement */
html {
    overflow: hidden;
    touch-action: none;
    -ms-touch-action: none;
}

body {
    touch-action: pan-x pan-y;
    -ms-touch-action: pan-x pan-y;
}

/* Ensure pickers are still interactive */
.picker {
    touch-action: pan-y;
    -ms-touch-action: pan-y;
}

.app {
    /* Full screen mobile app layout */
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for better mobile support */
    max-width: none; /* Remove max-width constraint for full mobile experience */
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.main {
    /* Fill entire viewport like a mobile app */
    flex: 1;
    height: 100%;
    padding: var(--space-md);
    background-color: var(--color-background);
    overflow-y: auto;
    overflow-x: hidden;
    /* Enable smooth scrolling for the main content area only */
    -webkit-overflow-scrolling: touch;
    /* Add safe area padding for notched devices */
    padding-top: max(var(--space-md), env(safe-area-inset-top));
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
}

.price-display {
    margin-bottom: var(--space-lg);
}

.price-card {
    background: linear-gradient(135deg, #D2002D 0%, #A50024 100%);
    border-radius: 20px;
    padding: var(--space-lg);
    color: white;
    box-shadow: 0 8px 24px rgba(210, 0, 45, 0.25);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.price-card.updating {
    opacity: 0.7;
    position: relative;
}

.price-card.updating::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.2) 50%,
        transparent 100%
    );
    animation: shimmer 1s infinite;
    border-radius: 20px;
    pointer-events: none;
}

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

.price-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.price-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    opacity: 0.95;
}

.info-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    padding: 5px 9px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.info-badge svg {
    opacity: 0.85;
}

.report-date {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.9;
    letter-spacing: 0.2px;
}

.price-segments {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.price-segment {
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: var(--space-md);
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: flex;
    flex-direction: column;
    min-width: 0; /* Allow segment to shrink below content size */
    overflow: hidden; /* Prevent content overflow */
}

.price-segment.discounted {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.segment-header {
    margin-bottom: var(--space-sm);
}

.segment-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.segment-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.price-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-sm);
    min-width: 0; /* Allow flex children to shrink */
}

.item-label {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.8;
    white-space: nowrap;
}

.item-value {
    font-size: clamp(14px, 3vw, 18px);
    font-weight: 700;
    line-height: 1.1;
    text-align: right;
    letter-spacing: -0.3px;
    white-space: nowrap;
    min-width: 0;
}

.item-value.large {
    font-size: clamp(20px, 4.5vw, 28px);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.item-value.small {
    font-size: 15px;
    opacity: 0.9;
}

.inputs {
    background-color: var(--color-surface);
    border-radius: 16px;
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
}

.input-group {
    margin-bottom: var(--space-lg);
}

.input-label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: var(--space-xs);
    display: block;
}

.carat-input-wrapper {
    position: relative;
}

#carat-input {
    width: 100%;
    padding: var(--space-sm) var(--space-lg);
    font-size: 18px;
    font-weight: 600;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background-color: var(--color-surface);
    text-align: left;
    color: var(--color-text);
}

#carat-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(210, 0, 45, 0.1);
}

.carat-unit {
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
    font-size: 16px;
}

.carat-mm-display {
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    margin-right: 36px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-primary);
    background: rgba(210, 0, 45, 0.08);
    border-radius: 12px;
    opacity: 0.9;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.pickers-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.picker-group {
    display: flex;
    flex-direction: column;
}

.picker {
    height: var(--picker-height);
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background-color: var(--color-surface);
    position: relative;
    /* Mobile touch optimizations */
    touch-action: pan-y; /* Only allow vertical scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    cursor: grab;
}

.picker:active {
    cursor: grabbing;
}

.picker-items {
    position: absolute;
    width: 100%;
    transition: transform 0.2s ease-out;
    /* Better GPU acceleration */
    transform-style: preserve-3d;
    will-change: transform;
}

.picker-selection {
    position: absolute;
    top: calc(50% - var(--picker-item-height)/2);
    left: 0;
    right: 0;
    height: var(--picker-item-height);
    background-color: rgba(210, 0, 45, 0.08);
    border-top: 2px solid rgba(210, 0, 45, 0.3);
    border-bottom: 2px solid rgba(210, 0, 45, 0.3);
    pointer-events: none; /* let clicks reach items */
    z-index: 2;
    box-shadow: 0 0 0 1px rgba(210, 0, 45, 0.1) inset;
}

.picker-item {
    height: var(--picker-item-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    user-select: none;
    /* Better touch targets on mobile */
    min-height: 44px; /* iOS recommended touch target */
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    /* Prevent text selection on mobile */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

.picker-item:hover {
    background-color: rgba(210, 0, 45, 0.08);
}

.picker-item:active {
    background-color: rgba(210, 0, 45, 0.15);
    transform: scale(0.96);
}

.picker-item.selected {
    font-weight: 700;
    color: var(--color-primary);
    background-color: rgba(210, 0, 45, 0.12);
    font-size: 15px;
    z-index: 3;
    text-shadow: 0 0 1px rgba(210, 0, 45, 0.3);
    scale: 1.05;
}

.calculate-btn {
    width: 100%;
    padding: var(--space-md);
    background: linear-gradient(135deg, rgba(210, 0, 45, 0.06) 0%, rgba(210, 0, 45, 0.02) 100%);
    color: var(--color-text-secondary);
    border: 1px solid rgba(210, 0, 45, 0.15);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.calculate-btn:hover {
    background: linear-gradient(135deg, rgba(210, 0, 45, 0.1) 0%, rgba(210, 0, 45, 0.04) 100%);
    border-color: rgba(210, 0, 45, 0.25);
    color: var(--color-primary);
    transform: translateY(-1px);
}

.calculate-btn:active {
    transform: translateY(0);
}

.calculate-btn:focus {
    outline: none;
}

.calculate-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.calculate-icon {
    transition: transform 0.3s ease;
}

.calculate-btn:hover .calculate-icon {
    transform: rotate(90deg);
}

.calculate-btn.loading .calculate-icon {
    animation: spin 1s linear infinite;
}

.calculate-btn.loading {
    background: linear-gradient(135deg, rgba(210, 0, 45, 0.08) 0%, rgba(210, 0, 45, 0.04) 100%);
    color: var(--color-primary);
    cursor: wait;
    pointer-events: none;
}

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

.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.toast {
    background-color: rgba(0,0,0,0.8);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: 8px;
    font-size: 14px;
}

.picker-column {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    touch-action: none; /* prevent browser scroll during picker drag */
    overscroll-behavior: contain;
}

/* Inline input dialog */
.dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height (accounts for mobile keyboard) */
    min-height: 100vh;
    min-height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.25s ease-out;
    padding: var(--space-xl) var(--space-md) var(--space-md);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.dialog {
    background: var(--color-surface);
    border-radius: 20px;
    padding: var(--space-xl) var(--space-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2), 0 8px 16px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    margin: 0 auto;
}

.dialog h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
    text-align: center;
}

.dialog-label {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    margin: -var(--space-sm) 0 var(--space-sm) 0;
}

.dialog-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    background: var(--color-background);
    border-radius: 16px;
    padding: var(--space-md);
    border: 2px solid var(--color-border);
    transition: all 0.2s ease;
    min-height: 64px;
}

.dialog-input-wrapper:focus-within {
    border-color: var(--color-primary);
    background: var(--color-surface);
    box-shadow: 0 0 0 4px rgba(210, 0, 45, 0.1);
}

.dialog input {
    font-size: 26px;
    font-weight: 700;
    padding: var(--space-md);
    border: 1px solid rgba(210, 0, 45, 0.15);
    background: rgba(255, 255, 255, 0.8);
    min-width: 80px;
    flex: 1 1 auto;
    text-align: center;
    color: var(--color-text);
    outline: none;
    letter-spacing: -0.5px;
    border-radius: 8px;
}

.dialog input::-webkit-outer-spin-button,
.dialog input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.dialog input[type=number] {
    -moz-appearance: textfield;
}

.dialog-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-top: var(--space-sm);
}

.dialog button {
    width: 100%;
    padding: 18px;
    border: none;
    border-radius: 14px;
    font-weight: 600;
    font-size: 17px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialog button:active {
    transform: scale(0.98);
}

.dialog button.confirm {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    box-shadow: 0 2px 8px rgba(210, 0, 45, 0.3);
    order: 1;
}

.dialog button.confirm:active {
    box-shadow: 0 1px 4px rgba(210, 0, 45, 0.3);
}

.dialog button.cancel {
    background: transparent;
    color: var(--color-text-secondary);
    border: none;
    order: 2;
    min-height: 44px;
    font-weight: 500;
}

.dialog button.cancel:active {
    background: var(--color-background);
    color: var(--color-text);
}

.sign-btn {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
    height: 56px;
    border: 2px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: 700;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    flex-grow: 0;
}

.sign-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.sign-btn.negative {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.sign-btn.negative:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.discount-label {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

#discount-picker {
    background: rgba(210, 0, 45, 0.05);
    border: 2px solid var(--color-primary);
}

#discount-picker .picker-selection {
    border-color: var(--color-primary);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .price-card {
        padding: var(--space-md);
    }
    
    .price-title {
        font-size: 15px;
    }
    
    .info-badge {
        padding: 4px 8px;
    }
    
    .report-date {
        font-size: 10px;
    }
    
    .price-segments {
        gap: var(--space-sm);
    }
    
    .price-segment {
        padding: var(--space-sm);
    }
    
    .segment-label {
        font-size: 10px;
    }
    
    .item-label {
        font-size: 12px;
    }
    
    .item-value {
        font-size: 16px;
    }
    
    .item-value.large {
        font-size: 24px;
        font-weight: 800;
    }
    
    .item-value.small {
        font-size: 14px;
    }
    
    .pickers-grid {
        gap: var(--space-xs);
    }
    
    .picker {
        /* Slightly taller for better touch targets */
        min-height: calc(var(--picker-height) + 20px);
    }
    
    .picker-item {
        /* Ensure touch targets meet accessibility standards */
        min-height: var(--picker-item-height);
        font-size: 15px;
    }
    
    /* Prevent zoom on input focus */
    input[type="text"],
    input[type="number"] {
        font-size: 16px;
    }
    
    #carat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Better visual feedback on touch */
    .picker-item:active {
        background-color: rgba(210, 0, 45, 0.15);
        transform: scale(0.95);
    }
    
    .picker-item.selected {
        font-weight: 700;
        font-size: 16px;
        scale: 1.08;
        text-shadow: 0 0 2px rgba(210, 0, 45, 0.4);
    }
    
    /* Mobile dialog optimizations */
    .dialog {
        width: 92%;
        max-width: 400px;
        padding: var(--space-lg) var(--space-md);
        margin: 0 auto;
        border-radius: 16px;
    }
    
    .dialog-backdrop {
        padding: var(--space-lg) var(--space-md) var(--space-md);
    }
    
    .dialog input {
        font-size: 20px !important; /* Large but prevents iOS zoom (16px+ prevents auto-zoom) */
        min-height: 48px;
        flex: 1 !important;
        padding: var(--space-sm) !important;
    }
    
    .dialog h3 {
        font-size: 18px;
    }
    
    .dialog-input-wrapper {
        display: flex !important;
        flex-direction: row !important;
        min-height: 60px;
        gap: var(--space-sm) !important;
    }
    
    .sign-btn {
        width: 52px !important;
        min-width: 52px !important;
        max-width: 52px !important;
        height: 52px !important;
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        font-size: 20px !important;
    }
}

/* Touch device specific optimizations */
@media (hover: none) and (pointer: coarse) {
    .picker-item:hover {
        background-color: transparent; /* Remove hover effects on touch devices */
    }
    
    .calculate-btn:hover,
    .calculate-btn:active {
        background: linear-gradient(135deg, rgba(210, 0, 45, 0.06) 0%, rgba(210, 0, 45, 0.02) 100%);
        border-color: rgba(210, 0, 45, 0.15);
        color: var(--color-text-secondary);
        transform: none; /* No effects on mobile */
    }
    
    .calculate-btn:hover .calculate-icon {
        transform: none; /* No rotation on mobile */
    }
}

