:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2236;
    --bg-card-hover: #1e2a42;
    --border-color: #2a3654;
    --border-glow: #3b82f6;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --gradient-primary: linear-gradient(135deg, #3b82f6, #06b6d4);
    --gradient-scan: linear-gradient(135deg, #10b981, #3b82f6);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s ease;
}

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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

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

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

.nfc-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nfc-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.status-badge, .mode-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge {
    border: 1px solid var(--border-color);
}

.status-available {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
    border-color: var(--accent-green);
}

.status-unavailable {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border-color: var(--accent-red);
}

.status-unknown {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-yellow);
    border-color: var(--accent-yellow);
}

.mode-badge {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
    border: 1px solid var(--accent-purple);
}

.mode-badge.auto {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
    border-color: var(--accent-green);
}

main {
    display: grid;
    grid-template-columns: 400px 1fr;
    grid-template-rows: auto auto;
    gap: 24px;
}

.scanner-section {
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.radar-display {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 380px;
    margin: 0 auto;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.05) 0%, transparent 70%);
    border-radius: 50%;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.radar-ring {
    position: absolute;
    border: 1px solid rgba(59, 130, 246, 0.15);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ring-1 { width: 25%; height: 25%; }
.ring-2 { width: 50%; height: 50%; }
.ring-3 { width: 75%; height: 75%; }
.ring-4 { width: 95%; height: 95%; }

.radar-sweep {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-cyan), transparent);
    transform-origin: left center;
    animation: sweep 3s linear infinite;
    opacity: 0.8;
}

.radar-sweep::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 0;
    width: 100%;
    height: 60px;
    background: conic-gradient(from -30deg, transparent, rgba(6, 182, 212, 0.15), transparent);
    transform-origin: left center;
}

@keyframes sweep {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.radar-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
    z-index: 2;
}

.radar-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: white;
    letter-spacing: 1px;
}

.tag-dots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}

.tag-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent-green);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: pulse-dot 2s ease-in-out infinite;
    box-shadow: 0 0 10px var(--accent-green);
}

@keyframes pulse-dot {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.5); opacity: 0.7; }
}

.scanner-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

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

.btn-large {
    flex: 1;
    padding: 14px 24px;
    font-size: 1rem;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.scanning {
    background: linear-gradient(135deg, #ef4444, #f97316);
    animation: pulse-btn 1.5s ease-in-out infinite;
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 4px 25px rgba(239, 68, 68, 0.5); }
}

.btn-secondary {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.btn-secondary:hover {
    background: rgba(139, 92, 246, 0.25);
}

.btn-secondary.active {
    background: var(--accent-purple);
    color: white;
}

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

.btn-outline:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

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

.signal-info {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.signal-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.signal-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 110px;
}

.signal-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.signal-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-scan);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.signal-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-cyan);
    min-width: 60px;
    text-align: right;
}

.info-section {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-bottom: none;
}

.tab {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.tab:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

.tab.active {
    background: var(--bg-card);
    color: var(--accent-cyan);
}

.tab-content {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    min-height: 400px;
}

.tab-content.active {
    display: block;
}

.info-card {
    padding: 20px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state span {
    font-size: 0.8rem;
}

.tag-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.detail-row:nth-child(odd) {
    background: rgba(255, 255, 255, 0.02);
}

.detail-row:hover {
    background: rgba(59, 130, 246, 0.05);
}

.detail-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.detail-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-value.mono {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    color: var(--accent-cyan);
    letter-spacing: 0.5px;
}

.hidden {
    display: none !important;
}

.ndef-records {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ndef-record {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.ndef-record-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.ndef-type {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ndef-type.text { background: rgba(59, 130, 246, 0.2); color: var(--accent-blue); }
.ndef-type.url { background: rgba(16, 185, 129, 0.2); color: var(--accent-green); }
.ndef-type.smart-poster { background: rgba(139, 92, 246, 0.2); color: var(--accent-purple); }
.ndef-type.wifi { background: rgba(245, 158, 11, 0.2); color: var(--accent-yellow); }
.ndef-type.vcard { background: rgba(6, 182, 212, 0.2); color: var(--accent-cyan); }
.ndef-type.other { background: rgba(100, 116, 139, 0.2); color: var(--text-muted); }

.ndef-payload {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 6px;
    word-break: break-all;
    max-height: 150px;
    overflow-y: auto;
}

.raw-data-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hex-dump {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.75rem;
    line-height: 1.8;
    background: rgba(0, 0, 0, 0.3);
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
    white-space: pre;
}

.hex-offset {
    color: var(--text-muted);
    margin-right: 16px;
}

.hex-byte {
    color: var(--accent-cyan);
    margin-right: 6px;
}

.hex-ascii {
    color: var(--accent-green);
    margin-left: 16px;
}

.data-actions {
    display: flex;
    gap: 8px;
}

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

.history-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 340px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover {
    background: rgba(59, 130, 246, 0.05);
}

.history-icon {
    width: 36px;
    height: 36px;
    background: var(--gradient-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

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

.history-uid {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--accent-cyan);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.log-section {
    grid-column: 1 / -1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.log-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.log-container {
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.75rem;
}

.log-entry {
    display: flex;
    gap: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.log-entry:hover {
    background: rgba(255, 255, 255, 0.02);
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-msg {
    color: var(--text-secondary);
}

.log-info .log-msg { color: var(--accent-cyan); }
.log-success .log-msg { color: var(--accent-green); }
.log-warning .log-msg { color: var(--accent-yellow); }
.log-error .log-msg { color: var(--accent-red); }

footer {
    text-align: center;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 24px;
}

.chip-diagram {
    margin-top: 16px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
}

.chip-pinout {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    text-align: center;
}

.chip-pin {
    padding: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

@media (max-width: 1024px) {
    main {
        grid-template-columns: 350px 1fr;
        gap: 16px;
    }

    .radar-display {
        max-width: 320px;
    }
}

@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
    }

    .scanner-section {
        grid-row: auto;
    }

    .radar-display {
        max-width: 300px;
        margin: 0 auto;
    }

    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        min-width: 70px;
        font-size: 0.7rem;
        padding: 8px 10px;
        flex-shrink: 0;
    }

    header {
        flex-direction: column;
        gap: 12px;
    }

    .info-section {
        min-width: 0;
    }

    .tab-content {
        min-height: 300px;
    }
}

@media (max-width: 600px) {
    .app-container {
        padding: 12px;
    }

    .logo h1 {
        font-size: 1.2rem;
    }

    .nfc-icon {
        width: 34px;
        height: 34px;
    }

    .nfc-icon svg {
        width: 20px;
        height: 20px;
    }

    .radar-display {
        max-width: 260px;
    }

    .scanner-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .btn-large {
        grid-column: 1 / -1;
    }

    .signal-info {
        padding: 12px;
    }

    .signal-item {
        flex-wrap: wrap;
        gap: 6px;
    }

    .signal-label {
        min-width: 100%;
        font-size: 0.7rem;
    }

    .signal-bar {
        flex: 1;
    }

    .signal-value {
        min-width: auto;
    }

    .info-card {
        padding: 14px;
    }

    .detail-row {
        padding: 10px 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .detail-label {
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .detail-value {
        font-size: 0.8rem;
    }

    .ndef-payload {
        font-size: 0.7rem;
        padding: 10px;
    }

    .hex-dump {
        font-size: 0.65rem;
        padding: 10px;
    }

    .history-item {
        padding: 10px;
        gap: 10px;
    }

    .history-icon {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .history-uid {
        font-size: 0.7rem;
    }

    .history-meta {
        font-size: 0.6rem;
    }

    .log-container {
        max-height: 120px;
        font-size: 0.65rem;
    }

    .empty-state {
        padding: 30px 16px;
    }

    .empty-state svg {
        width: 40px;
        height: 40px;
    }

    .empty-state p {
        font-size: 0.9rem;
    }

    .empty-state span {
        font-size: 0.7rem;
    }
}

@media (max-width: 400px) {
    .app-container {
        padding: 8px;
    }

    .status-bar {
        gap: 6px;
    }

    .status-badge, .mode-badge {
        font-size: 0.65rem;
        padding: 4px 8px;
    }

    .scanner-controls {
        grid-template-columns: 1fr;
    }

    .btn-large {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .tabs {
        padding: 3px;
        gap: 1px;
    }

    .tab {
        min-width: 60px;
        font-size: 0.65rem;
        padding: 6px 8px;
    }

    .chip-pinout {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
    }

    .chip-pin {
        font-size: 0.55rem;
        padding: 4px;
    }
}

@media (max-height: 600px) and (orientation: landscape) {
    .radar-display {
        max-width: 180px;
    }

    .scanner-controls {
        flex-direction: row;
    }

    .signal-info {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .signal-item {
        flex: 1;
        min-width: 120px;
    }

    .log-section {
        max-height: 100px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    main {
        grid-template-columns: 380px 1fr;
    }
}

@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .tab {
        min-height: 44px;
    }

    .history-item {
        min-height: 56px;
    }
}

.scan-found-animation {
    animation: scanFound 0.6s ease;
}

@keyframes scanFound {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); border-color: var(--accent-green); }
    100% { transform: scale(1); }
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    .app-container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    footer {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Touch feedback */
@media (hover: none) {
    .btn:active {
        transform: scale(0.97);
        opacity: 0.9;
    }

    .tab:active {
        background: rgba(59, 130, 246, 0.1);
    }

    .history-item:active {
        background: rgba(59, 130, 246, 0.1);
    }
}

/* Prevent text selection on interactive elements */
.btn, .tab, .history-item, .status-badge, .mode-badge {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling on mobile */
html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

/* Better focus states for accessibility */
.btn:focus-visible, .tab:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

/* Loading state for buttons */
.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
