/* Base Styles */
:root {
    --primary-color: #3498db;
    --secondary-color: #2ecc71;
    --error-color: #e74c3c;
    --background: #f5f6fa;
    --text-color: #2c3e50;
    --key-bg: #ffffff;
    --key-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    touch-action: manipulation;
}

#app {
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Screen Styles */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-color: var(--background);
    transition: opacity 0.3s ease;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Keypad Styles */
.keypad-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    aspect-ratio: 1;
}

.keypad-btn {
    width: 100%;
    aspect-ratio: 1;
    border: none;
    border-radius: 50%;
    background: var(--key-bg);
    color: var(--text-color);
    font-size: 2rem;
    font-weight: 500;
    box-shadow: var(--key-shadow);
    cursor: pointer;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.keypad-btn:active,
.keypad-btn.active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* QR Code Container */
#qrcode {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    margin: 0 auto;
    max-width: 300px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* QR Container */
.qr-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin: 20px auto;
    max-width: 300px;
    text-align: center;
}

#qrcode, #export-qrcode {
    width: 100%;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 10px;
    margin: 0 auto;
    padding: 10px;
    justify-content: center;
}

#qrcode img, #export-qrcode img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Blank Screen */
.blank-container {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--background);
}

/* Logo Screen */
.logo-container {
    width: 100%;
    max-width: 300px;
    aspect-ratio: 1;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.logo {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Admin Panel */
.admin-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    max-height: 100vh;
    overflow-y: auto;
}

/* Accordion Styles */
.accordion-section {
    margin-bottom: 15px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    background: white;
}

.accordion-header {
    width: 100%;
    padding: 15px 20px;
    text-align: left;
    border: none;
    background: #f8f9fa;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    transition: background-color 0.2s ease;
}

.accordion-header:hover {
    background: #e9ecef;
}

.accordion-header:focus {
    outline: none;
}

.accordion-icon {
    transition: transform 0.3s ease;
    font-size: 0.8em;
    color: #6c757d;
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    background: white;
    transition: max-height 0.3s ease-out;
}

.accordion-section.active .accordion-content {
    max-height: 2000px; /* Adjust based on your content */
    padding: 15px 20px;
}

.accordion-section.active .accordion-icon {
    transform: rotate(180deg);
}

/* Scanner Container */
.scanner-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 15px auto;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

#scanner-video, #admin-scanner-video, #import-scanner-video {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* Scan Result */
#scan-result {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid #ddd;
}

/* Scan Rounds List */
.scan-rounds-list {
    max-height: 400px;
    overflow-y: auto;
}

.scan-round-item {
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary-color);
}

.scan-round-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #e0e0e0;
}

.scan-round-header:hover {
    background: #f0f0f0;
}

.scan-round-title {
    font-weight: bold;
    color: #2c3e50;
    font-size: 1rem;
}

.scan-round-time {
    font-size: 0.8rem;
    color: #666;
}

.scan-round-content {
    display: none;
    padding: 15px;
}

.scan-round-item.active .scan-round-content {
    display: block;
}

.scan-round-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.stat-item {
    text-align: center;
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: #666;
    margin-top: 2px;
}

.scan-round-keys {
    margin-top: 10px;
}

.keys-section {
    margin-bottom: 8px;
}

.keys-section-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.key-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.key-chip {
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.8rem;
    font-family: monospace;
}

.key-chip.valid {
    border-color: #4CAF50;
    background: #e8f5e8;
}

.key-chip.invalid {
    border-color: #f44336;
    background: #ffeaea;
}

/* Scanned Keys List */
.scanned-keys {
    margin-top: 20px;
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.scanned-keys h4 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.scanned-keys-list {
    max-height: 300px;
    overflow-y: auto;
}

.scanned-keys-header {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr 1fr;
    font-weight: bold;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 8px;
}

.scanned-key-item {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr 1fr;
    padding: 8px 0;
    border-bottom: 1px solid #f5f5f5;
    align-items: center;
}

.key-round {
    font-family: monospace;
    font-size: 0.9em;
    color: #666;
    text-align: center;
}

.scanned-key-item:last-child {
    border-bottom: none;
}

.key-value {
    font-family: monospace;
    font-size: 0.9em;
}

.scanned-time {
    font-size: 0.85em;
    color: #666;
}

.key-status {
    text-align: center;
    font-weight: bold;
}

.key-status.valid {
    color: #4CAF50;
}

.key-status.invalid {
    color: #f44336;
}

/* Admin Buttons */
.admin-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary {
    background-color: #4CAF50;
    color: white;
}

.btn-danger {
    background-color: #f44336;
    color: white;
}

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

/* Responsive adjustments */
@media (max-width: 600px) {
    .admin-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
}

.admin-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
}

.admin-section h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.2rem;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 10px;
}

.admin-actions {
    margin: 15px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn .icon {
    font-size: 1.1em;
}

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

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background: var(--secondary-color);
}

.btn-remove {
    background: #e74c3c;
}

.btn-disabled {
    background: #95a5a6;
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.back-btn {
    background: #7f8c8d;
    margin-top: 20px;
    width: 100%;
}

/* Keys List */
.keys-container {
    margin-top: 15px;
}

.keys-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.key-item {
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.key-item.admin-key {
    border-left: 4px solid #e74c3c;
}

.key-info {
    flex: 1;
}

.key-value {
    display: block;
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 5px;
}

.key-name {
    display: block;
    font-size: 0.95rem;
    color: #34495e;
    margin-bottom: 8px;
}

.key-meta {
    display: block;
    font-size: 0.8rem;
    color: #7f8c8d;
    margin-top: 3px;
}

.key-actions {
    margin-left: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.uses-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

.uses-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.uses-display {
    font-size: 0.8rem;
    font-weight: bold;
    min-width: 50px;
    text-align: center;
    padding: 2px 4px;
    background: #f0f0f0;
    border-radius: 4px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .admin-container {
        max-width: 95%;
        padding: 15px;
    }
    
    .keys-grid {
        grid-template-columns: 1fr;
    }
    
    .admin-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .keypad-container {
        padding: 10px;
        justify-content: center;
    }
    
    .keypad-grid {
        max-width: 350px;
        gap: 12px;
    }
}

/* Scanner */
#scanner {
    width: 100%;
    max-width: 400px;
    margin: 20px 0;
    border-radius: 10px;
    overflow: hidden;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--error-color);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.toast.show {
    opacity: 1;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.scanner-modal-content {
    width: 100%;
    max-width: 400px;
    height: 400px;
    position: relative;
}

#admin-scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.scanner-grid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    height: 250px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.scanner-grid::before,
.scanner-grid::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid #4CAF50;
}

.scanner-grid::before {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
}

.scanner-grid::after {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
}

.scan-result {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid #ddd;
    font-weight: 600;
}

.scan-result.success {
    background: rgba(76, 175, 80, 0.95);
    color: white;
}

.scan-result.error {
    background: rgba(244, 67, 54, 0.95);
    color: white;
}

/* Enable/Disable Toggle */
.key-toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.key-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #4CAF50;
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.key-item.disabled {
    opacity: 0.6;
    background: #f8f9fa;
}

.key-item.disabled .key-value {
    color: #999;
}

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

/* Responsive Adjustments */
@media (max-width: 480px) {
    .screen {
        padding: 0;
        justify-content: center;
    }
    
    .keypad-container {
        padding: 15px;
        width: 100vw;
        max-width: 100%;
        min-height: 100vh;
    }
    
    .keypad-grid {
        gap: 12px;
        padding: 0;
        max-width: 300px;
        margin: 0 auto;
    }
    
    .keypad-btn {
        font-size: 1.8rem;
    }
    
    .qr-container, .logo-container {
        max-width: 100%;
        width: 280px;
        margin: 0 auto;
    }
}

/* Animation for keypad press */
@keyframes press {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.keypad-btn:active {
    animation: press 0.2s ease;
}