/* ============================================
   FreeOTP Web + QR - Styling
   ============================================ */

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

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: rgba(30, 41, 59, 0.8);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #06b6d4;
    --accent-hover: #0891b2;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: rgba(148, 163, 184, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    padding-bottom: 100px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== App Container ========== */
.app {
    max-width: 480px;
    margin: 0 auto;
}

/* ========== Header ========== */
header {
    text-align: center;
    margin-bottom: 24px;
    padding: 20px 0;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ========== Push Status ========== */
.push-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.push-status #pushIcon {
    font-size: 1.1rem;
}

.push-status.active #pushText {
    color: var(--success);
}

.push-status.inactive #pushText {
    color: var(--text-secondary);
}

/* ========== TOTP List ========== */
.otp-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.otp-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    backdrop-filter: blur(10px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}

.otp-item.selected {
    border-left-color: var(--success);
    box-shadow: 0 0 0 2px var(--success);
}

.otp-item:active {
    transform: scale(0.98);
}

.otp-info {
    flex: 1;
    min-width: 0;
}

.otp-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.otp-code {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--success);
    letter-spacing: 4px;
    margin: 6px 0;
}

.timer-bar-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.timer-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 1s linear;
}

.timer-bar.warning {
    background: var(--warning);
}

.timer-bar.danger {
    background: var(--danger);
}

.btn-delete {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 12px;
    transition: opacity 0.2s ease;
}

.btn-delete:active {
    opacity: 0.7;
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 0.85rem;
    opacity: 0.7;
}

/* ========== Add Buttons ========== */
.add-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.add-buttons .btn {
    flex: 1;
}

.btn-add {
    background: var(--accent);
    color: white;
}

.btn-qr {
    background: var(--success);
    color: white;
}

.btn-add:hover {
    background: var(--accent-hover);
}

.btn-qr:hover {
    background: #16a34a;
}

/* ========== Buttons ========== */
.btn {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    text-align: center;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.15);
}

.actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.actions .btn {
    flex: 1;
}

/* ========== Badge Display ========== */
.badge-display {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--danger);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform 0.2s ease;
}

.badge-display:active {
    transform: scale(0.9);
}

/* ========== Modal ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
}

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

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px 16px 12px 12px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    border: 1px solid var(--border);
}

.modal-content h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.modal-content label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    margin-top: 16px;
}

.modal-content label:first-of-type {
    margin-top: 0;
}

.modal-content input,
.modal-content select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

.modal-content input:focus,
.modal-content select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.modal-actions .btn {
    flex: 1;
}

/* ========== QR Scanner Specific ========== */
.qr-modal {
    max-height: 90vh;
}

.qr-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.qr-header h2 {
    margin-bottom: 0;
}

.btn-close {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.btn-close:active {
    opacity: 0.7;
}

.qr-scanner-container {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin: 0 auto 20px;
    aspect-ratio: 1;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
}

.qr-scanner-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.qr-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
}

/* ========== QR Scanner Specific ========== */
.qr-modal .qr-scanner-container {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin: 0 auto 20px;
    aspect-ratio: 1;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    display: block;
}

.qr-scanner-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.qr-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 15;
    pointer-events: none;
}

.qr-scan-frame {
    width: 65%;
    height: 65%;
    max-width: 220px;
    max-height: 220px;
    border: 4px solid var(--accent);
    border-radius: 20px;
    position: relative;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}

.qr-scan-frame::before,
.qr-scan-frame::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: var(--accent);
    border-style: solid;
}

.qr-scan-frame::before {
    top: -4px;
    left: -4px;
    border-width: 6px 0 0 6px;
    border-radius: 20px 0 0 0;
}

.qr-scan-frame::after {
    bottom: -4px;
    right: -4px;
    border-width: 0 6px 6px 0;
    border-radius: 0 0 20px 0;
}

.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: scan 2s ease-in-out infinite;
    box-shadow: 0 0 15px var(--accent);
}

@keyframes scan {
    0% { top: 0; opacity: 0.5; }
    50% { opacity: 1; }
    100% { top: 100%; opacity: 0.5; }
}

.qr-hint {
    position: absolute;
    bottom: -45px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
    z-index: 20;
    white-space: nowrap;
}

/* Kamera-Wechsel Button */
.btn-camera-switch {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    font-size: 1.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.btn-camera-switch:active {
    transform: scale(0.9);
    background: rgba(6, 182, 212, 0.6);
}

/* QR Upload */
.qr-upload {
    text-align: center;
    padding: 20px 0;
    border-top: 2px solid var(--border);
    margin-top: 20px;
}

.upload-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
    font-weight: 500;
}

.btn-qr-upload {
    background: var(--success);
    color: white;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.btn-qr-upload:active {
    background: #16a34a;
    transform: scale(0.98);
}

.qr-result {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    display: none;
}

.success-text {
    color: var(--success);
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 16px;
    text-align: center;
}

.qr-otp-preview {
    margin-bottom: 16px;
}

.preview-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
    margin-bottom: 2px;
}

.preview-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    word-break: break-all;
}

.preview-value.key {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    letter-spacing: 2px;
    font-size: 0.9rem;
}

.qr-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.qr-manual {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.qr-manual p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-align: center;
}

.qr-manual input {
    margin-bottom: 10px;
}

/* ========== Toast Notifications ========== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ========== Responsive ========== */
@media (min-width: 481px) {
    .modal {
        align-items: center;
    }
    
    .modal-content {
        border-radius: 16px;
    }
    
    .qr-scanner-container {
        max-width: 360px;
    }
    
    .qr-scan-frame {
        width: 260px;
        height: 260px;
    }
}

/* ========== Dark Mode Support ========== */
@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #f8fafc;
        --bg-secondary: #ffffff;
        --bg-card: rgba(255, 255, 255, 0.9);
        --text-primary: #0f172a;
        --text-secondary: #475569;
        --border: rgba(0, 0, 0, 0.1);
    }
    
    .modal {
        background: rgba(0, 0, 0, 0.5);
    }
    
    .otp-item {
        backdrop-filter: blur(10px);
    }
}

/* ========== Landscape Mobile ========== */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 10px 0;
        margin-bottom: 12px;
    }
    
    header h1 {
        font-size: 1.25rem;
    }
    
    .otp-item {
        padding: 12px;
    }
    
    .otp-code {
        font-size: 1.5rem;
    }
    
    .qr-scanner-container {
        max-width: 200px;
    }
    
    .qr-scan-frame {
        width: 160px;
        height: 160px;
    }
}

/* ========== Print ========== */
@media print {
    .btn, .badge-display, .push-status, .modal, .add-buttons {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .otp-item {
        break-inside: avoid;
        border: 1px solid #ccc;
    }
}
