:root {
    --primary-color: #2E7D32;
    --secondary-color: #C8E6C9;
    --dark-color: #1B5E20;
    --error-color: #f44336;
    --copy-color: #1976D2;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #f5f5f5;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 30px;
}

.scanner-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto 30px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    background: #000;
    aspect-ratio: 16/9;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    display: block;
    filter: contrast(1.1) brightness(1.1) saturate(1.1);
}

.scan-area {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 2px;
    background: #ff0000;
    animation: scan 2s infinite linear;
}

@keyframes scan {
    0%, 100% { top: 20%; }
    50% { top: 80%; }
}

.controls-container {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.main-controls {
    justify-content: center;
    gap: 15px;
}

.focus-buttons-row {
    justify-content: center;
    gap: 8px;
}

.btn {
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.secondary {
    background: #757575;
    color: white;
}

.btn.copy {
    background: var(--copy-color);
    color: white;
    white-space: nowrap;
}

.btn.success {
    background: #388e3c;
    color: white;
}

.btn.danger {
    background: #d32f2f;
    color: white;
}

.btn.large {
    padding: 14px 28px;
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    max-width: 200px;
}

.btn.small {
    padding: 10px 16px;
    font-size: 14px;
    flex: 1;
    max-width: 140px;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.results {
    gap: 10px;
}

#result {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    min-width: 0;
}

#copy-btn {
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 16px;
}

.focus-controls {
    justify-content: center;
}

.focus-slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 400px;
}

.focus-slider-container label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
}

#focus-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

#focus-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

#focus-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

#focus-value {
    font-size: 14px;
    font-weight: 500;
    color: #666;
    min-width: 40px;
    text-align: center;
}

.history {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#history-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

#history-list li {
    padding: 10px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
}

.d-none {
    display: none !important;
}

.error-message {
    background: #ffebee;
    color: var(--error-color);
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    text-align: center;
    border: 1px solid #ffcdd2;
}

.scan-quality {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 5;
}

.quality-good {
    background: rgba(76, 175, 80, 0.8);
}

.quality-poor {
    background: rgba(255, 152, 0, 0.8);
}

.quality-bad {
    background: rgba(244, 67, 54, 0.8);
}

.focus-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.focus-crosshair {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid #00ff00;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: pulse 2s infinite;
}

.focus-crosshair::before,
.focus-crosshair::after {
    content: '';
    position: absolute;
    background: #00ff00;
}

.focus-crosshair::before {
    width: 2px;
    height: 20px;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
}

.focus-crosshair::after {
    width: 20px;
    height: 2px;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.focus-lock {
    border-color: #ff0000 !important;
}

.focus-lock::before,
.focus-lock::after {
    background: #ff0000 !important;
}

.tips {
    background: #e3f2fd;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #2196f3;
}

.tips h3 {
    margin-top: 0;
    color: #1976d2;
    font-size: 16px;
}

.tips ul {
    margin: 10px 0;
    padding-left: 20px;
}

.tips li {
    margin-bottom: 5px;
    font-size: 14px;
    color: #555;
}

.database-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.database-section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 10px;
}

.product-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
}

.product-form h3 {
    margin-top: 0;
    color: var(--dark-color);
    margin-bottom: 15px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 5px;
    color: #333;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

.search-filters {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 15px;
    margin-bottom: 20px;
    align-items: end;
}

.search-box {
    display: flex;
    gap: 10px;
}

.search-box input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filters select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-width: 150px;
}

.products-list {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.list-header {
    background: #f5f5f5;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
}

.list-header span {
    font-weight: 500;
    color: #333;
}

.products-container {
    max-height: 400px;
    overflow-y: auto;
}

.product-item {
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.product-item:hover {
    background: #f8f9fa;
}

.product-item:last-child {
    border-bottom: none;
}

.product-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.product-name {
    font-weight: 600;
    color: #333;
    margin: 0;
}

.product-barcode {
    color: #666;
    font-size: 12px;
    font-family: monospace;
}

.product-meta {
    display: flex;
    gap: 15px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #666;
}

.meta-item .label {
    font-weight: 500;
}

.meta-item .value {
    padding: 2px 8px;
    background: #e3f2fd;
    border-radius: 12px;
    font-size: 12px;
}

.quality-new { background: #e8f5e8; color: #2e7d32; }
.quality-excellent { background: #e3f2fd; color: #1565c0; }
.quality-good { background: #fff3e0; color: #ef6c00; }
.quality-satisfactory { background: #fce4ec; color: #c2185b; }
.quality-used { background: #f5f5f5; color: #616161; }

.product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

.product-description {
    color: #666;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 5px;
}

.product-notes {
    color: #888;
    font-size: 13px;
    font-style: italic;
}

.price-history {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e0e0e0;
}

.price-history-title {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    margin-bottom: 5px;
}

.price-history-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.price-history-item {
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #666;
}

.no-products {
    text-align: center;
    padding: 40px;
    color: #666;
    font-style: italic;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.product-form {
    animation: slideDown 0.3s ease-out;
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }
    
    .controls-container {
        padding: 15px;
    }
    
    .control-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .main-controls {
        flex-direction: row;
        gap: 10px;
    }
    
    .focus-buttons-row {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .btn.large {
        padding: 12px 20px;
        font-size: 16px;
        max-width: none;
    }
    
    .btn.small {
        padding: 8px 12px;
        font-size: 13px;
        max-width: none;
        flex: 1;
        min-width: 0;
    }
    
    .focus-slider-container {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
    
    .scanner-container {
        aspect-ratio: 4/3;
        max-width: 100%;
    }
    
    .results {
        flex-direction: column;
    }
    
    #copy-btn {
        width: 100%;
    }
    
    .tips {
        padding: 12px;
    }
    
    .tips ul {
        padding-left: 15px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .search-filters {
        grid-template-columns: 1fr;
    }
    
    .filters {
        flex-wrap: wrap;
    }
    
    .product-header {
        flex-direction: column;
        gap: 5px;
    }
    
    .product-meta {
        flex-direction: column;
        gap: 5px;
    }
    
    .form-buttons {
        flex-direction: column;
    }
}

@supports not (aspect-ratio: 16/9) {
    .scanner-container {
        height: 300px;
    }
    
    @media (max-width: 600px) {
        .scanner-container {
            height: 250px;
        }
    }
}

@media (max-width: 380px) {
    .scanner-container {
        aspect-ratio: 1/1;
    }
    
    .container {
        padding: 8px;
    }
    
    h1 {
        font-size: 24px;
        margin-bottom: 20px;
    }
    
    .controls-container {
        padding: 12px;
    }
    
    .btn.small {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    .history {
        padding: 15px;
    }
    
    #history-list {
        max-height: 150px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 900px;
    }
    
    .scanner-container {
        max-width: 600px;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .container {
        padding: 10px;
        max-width: 100%;
    }
    
    .scanner-container {
        aspect-ratio: 16/9;
        max-width: 60%;
        margin: 0 auto 15px;
    }
    
    .controls-container {
        margin-bottom: 15px;
    }
    
    .tips {
        display: none;
    }
    
    .history {
        padding: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scan-area {
        animation: none;
    }
    
    .focus-crosshair {
        animation: none;
    }
    
    .btn {
        transition: none;
    }
    
    .product-form {
        animation: none;
    }
}

@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .controls-container {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .history {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    #result {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #444;
    }
    
    .tips {
        background: #1e3a5f;
        color: #e0e0e0;
        border-left-color: #3b82f6;
    }
    
    .tips h3 {
        color: #93c5fd;
    }
    
    .tips li {
        color: #cbd5e1;
    }
    
    #history-list li {
        border-bottom-color: #444;
    }
    
    .focus-slider-container label {
        color: #e0e0e0;
    }
    
    #focus-value {
        color: #bbb;
    }
    
    .database-section {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .product-form {
        background: #3d3d3d;
    }
    
    .form-group label {
        color: #e0e0e0;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .list-header {
        background: #3d3d3d;
    }
    
    .product-item {
        border-bottom-color: #444;
    }
    
    .product-item:hover {
        background: #3d3d3d;
    }
    
    .product-name {
        color: #e0e0e0;
    }
    
    .meta-item .value {
        background: #4d4d4d;
        color: #e0e0e0;
    }
    
    .search-box input {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .price-history-item {
        background: #4d4d4d;
        color: #e0e0e0;
    }
}

.btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

#result:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

#focus-slider:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

@supports (padding: max(0px)) {
    .container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}