* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f4f5;
    color: #222;
}

header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 16px 24px;
    background: #fff;
    border-bottom: 1px solid #e4e4e7;
}

h1 {
    margin: 0 0 12px;
    font-size: 20px;
}

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

#search {
    flex: 1;
    max-width: 360px;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid #d4d4d8;
    border-radius: 6px;
}

#count {
    font-size: 13px;
    color: #71717a;
}

#gallery {
    padding: 8px 24px 24px;
}

.group h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 24px 0 12px;
    font-size: 16px;
}

.badge {
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 500;
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 999px;
}

.badge-sample {
    color: #b45309;
    background: #fffbeb;
    border-color: #fcd34d;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

[hidden] {
    display: none !important;
}

.card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
}

.card:hover {
    border-color: #a1a1aa;
}

.card.failed {
    border-color: #fca5a5;
}

.card.sample {
    border: 2px dashed #f59e0b;
}

.card.sample img {
    opacity: 0.6;
}

.thumb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    /* พื้นตารางหมากรุก ให้เห็นส่วนที่โปร่งใส */
    background: repeating-conic-gradient(#f4f4f5 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}

.sample-label {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: #d97706;
    border-radius: 4px;
}

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

.thumb.error {
    background: #fef2f2;
    color: #dc2626;
    font-size: 13px;
}

.info {
    padding: 8px 10px;
    font-size: 13px;
}

.name {
    font-weight: 600;
    word-break: break-all;
}

.size {
    margin-top: 2px;
    color: #71717a;
    font-size: 12px;
    word-break: break-all;
}

.message {
    text-align: center;
    color: #71717a;
}
