/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-card: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --danger: #e74c3c;
    --success: #2ecc71;
    --border: #333333;
    --shadow: 0 4px 20px rgba(0,0,0,0.5);
    --font-size: 16px;
    --font-color: #ffffff;
}

.light-theme {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --border: #e0e0e0;
    --shadow: 0 4px 20px rgba(0,0,0,0.1);
}

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

html {
    font-size: var(--font-size);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-secondary);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--border);
}

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
    color: var(--text-primary);
}

.btn-icon:active {
    background: var(--border);
}

.quick-access {
    background: var(--bg-secondary);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    animation: slideDown 0.3s ease;
}

.quick-access.hidden {
    display: none;
}

.quick-access-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.quick-card {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover)) !important;
    color: white !important;
}

.search-bar {
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 60px;
    z-index: 99;
}

.search-bar input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    border-color: var(--accent);
}

.cards-list {
    padding: 12px;
    padding-bottom: 100px;
}

.card-item {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.card-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--card-color, var(--accent));
    border-radius: 16px 0 0 16px;
}

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

.card-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    flex-shrink: 0;
}

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

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

.card-number {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

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

.empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

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

.empty-sub {
    font-size: 0.9rem;
    opacity: 0.7;
}

.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 2rem;
    font-weight: 300;
    box-shadow: 0 4px 20px rgba(52, 152, 219, 0.4);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab:active {
    transform: scale(0.9);
    box-shadow: 0 2px 10px rgba(52, 152, 219, 0.3);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    z-index: 2000;
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
    align-items: flex-end;
}

.modal-content {
    background: var(--bg-secondary);
    width: 100%;
    max-height: 90vh;
    border-radius: 24px 24px 0 0;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

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

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.icon-picker,
.color-picker {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.icon-option {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.icon-option.selected {
    border-color: var(--accent);
    background: var(--accent);
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s;
}

.color-option.selected {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.photo-preview {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 12px;
    margin-top: 8px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions button {
    flex: 1;
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-scan {
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

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

.btn-primary:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

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

.btn-secondary:active {
    background: var(--border);
}

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

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

.details-body {
    text-align: center;
}

.details-card {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-radius: 20px;
    padding: 32px 20px;
    margin-bottom: 24px;
    color: white;
    box-shadow: 0 8px 32px rgba(52, 152, 219, 0.3);
}

.details-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.details-name {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.details-number {
    font-size: 1.2rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    opacity: 0.9;
}

.qr-container {
    background: white;
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 20px;
    display: inline-block;
}

#qr-canvas {
    max-width: 100%;
}

.details-notes {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 12px;
    text-align: left;
    margin-bottom: 20px;
    white-space: pre-wrap;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.details-actions {
    display: flex;
    gap: 12px;
}

.details-actions button {
    flex: 1;
}

.scanner-content {
    max-height: 100vh;
    border-radius: 0;
}

.scanner-body {
    position: relative;
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scanner-frame {
    width: 250px;
    height: 250px;
    border: 3px solid var(--accent);
    border-radius: 20px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
}

.scanner-hint {
    color: white;
    margin-top: 20px;
    font-size: 1rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.btn-capture {
    margin: 20px;
}

.settings-section {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.settings-section button {
    width: 100%;
    margin-bottom: 12px;
}

.settings-section input[type="range"] {
    width: 100%;
    margin: 8px 0;
}

.settings-section input[type="color"] {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

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

.hidden {
    display: none !important;
}

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

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

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(16px + env(safe-area-inset-top));
    }
    .fab {
        bottom: calc(24px + env(safe-area-inset-bottom));
    }
}
