/* Design: Dark theme with warm accent, inspired by card wallets */
:root {
    --bg-primary: #0f0f12;
    --bg-secondary: #1a1b22;
    --bg-card: #25262e;
    --accent: #e8a838;
    --accent-dim: #c4952e;
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --danger: #ef4444;
    --radius: 16px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

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

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 20px 16px;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.btn-add {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    font-size: 1.75rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.btn-add:hover, .btn-add:active {
    background: var(--accent-dim);
    transform: scale(1.05);
}

/* Card list */
.card-list {
    flex: 1;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state.hidden {
    display: none;
}

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

.empty-hint {
    font-size: 0.9rem;
    margin-top: 8px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (min-width: 480px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card-item {
    aspect-ratio: 1;
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.card-item-logo-wrap {
    margin: -4px 0 8px 0;
}

.card-item-logo-wrap .card-logo-badge {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    border-radius: 10px;
}

.card-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

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

.card-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.card-item-preview {
    width: 100%;
    height: 36px;
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-item-preview svg {
    max-width: 100%;
    max-height: 100%;
}

/* Card detail (fullscreen) */
.card-detail {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding: calc(16px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}

.card-detail[hidden] {
    display: none;
}

.btn-close {
    position: absolute;
    top: calc(16px + var(--safe-top));
    right: 20px;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    font-size: 1.75rem;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
}

.card-detail-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.card-header-detail {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.card-header-with-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-logo-badge {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    overflow: hidden;
    flex-shrink: 0;
}

.card-logo-badge img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-header-detail h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.btn-delete {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(239,68,68,0.2);
    color: var(--danger);
    font-size: 1.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.barcode-container {
    background: white;
    padding: 32px 24px;
    border-radius: var(--radius);
    text-align: center;
    max-width: 100%;
    border: 3px solid transparent;
    transition: border-color 0.2s;
}

.barcode-container svg {
    max-width: 100%;
    height: auto;
}

.barcode-number {
    margin-top: 16px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 1rem;
    color: #333;
    letter-spacing: 0.05em;
}

.btn-fullscreen-barcode {
    margin-top: 24px;
    width: 100%;
    padding: 16px 24px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-fullscreen-barcode:hover, .btn-fullscreen-barcode:active {
    background: var(--accent-dim);
}

/* Fullscreen barcode for checkout - bright for scanning */
.barcode-fullscreen {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 500;
    display: flex;
    flex-direction: column;
    padding: calc(16px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}

.barcode-fullscreen[hidden] {
    display: none;
}

.btn-close-fullscreen {
    position: absolute;
    top: calc(16px + var(--safe-top));
    right: 20px;
    width: 48px;
    height: 48px;
    border: none;
    background: rgba(0,0,0,0.08);
    color: #333;
    font-size: 1.75rem;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
}

.barcode-fullscreen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

.barcode-fullscreen-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    overflow: hidden;
}

.barcode-fullscreen-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.barcode-fullscreen-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 24px;
}

.barcode-fullscreen-svg-wrap {
    width: 100%;
    max-width: 100%;
    padding: 24px 16px;
    background: #fff;
    border: 2px solid #eee;
    border-radius: var(--radius);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
}

.barcode-fullscreen-svg-wrap svg {
    width: 100% !important;
    max-width: 100%;
    height: auto !important;
    max-height: 40vh;
}

.barcode-fullscreen-number {
    margin-top: 20px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 1.125rem;
    color: #333;
    letter-spacing: 0.08em;
}

.barcode-fullscreen-hint {
    margin-top: 24px;
    font-size: 0.85rem;
    color: #888;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    padding-bottom: calc(24px + var(--safe-bottom));
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 24px;
    font-size: 1.25rem;
}

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

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

.form-group input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--bg-card);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.form-group input[type="color"] {
    width: 64px;
    height: 48px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
}

.color-preset-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-group input[type="url"] {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--bg-card);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
}

.btn-scan {
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px dashed var(--text-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
}

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

.btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

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

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

/* Scanner */
.scanner-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 400;
    display: flex;
    flex-direction: column;
}

.scanner-overlay[hidden] {
    display: none;
}

.scanner-header {
    padding: calc(16px + var(--safe-top)) 20px 16px;
    background: rgba(0,0,0,0.8);
    color: white;
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-close-scanner {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: white;
    font-size: 1.75rem;
    cursor: pointer;
}

.scanner-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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