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

/* Loading / Skeleton */
.loading {
    position: fixed; inset: 0; z-index: 9999;
    background: #fafafa; display: flex; align-items: center; justify-content: center;
    transition: opacity 0.3s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-skeleton { width: 90%; max-width: 800px; }
.sk-bar { height: 12px; width: 120px; background: #eee; border-radius: 6px; margin-bottom: 2rem; animation: shimmer 1.5s infinite; }
.sk-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.sk-card { height: 80px; background: #f0f0f0; border-radius: 14px; animation: shimmer 1.5s infinite; }
.sk-card:nth-child(2) { animation-delay: 0.1s; }
.sk-card:nth-child(3) { animation-delay: 0.2s; }
.sk-card:nth-child(4) { animation-delay: 0.3s; }
@keyframes shimmer { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } }
.error-state { text-align: center; padding: 4rem 2rem; color: #999; font-size: 0.9rem; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'PingFang SC', 'Inter', sans-serif;
    background: #fafafa;
    color: #1a1a1a;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(250,250,250,0.92);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    padding: 1.5rem 3rem;
    display: flex; align-items: center; gap: 3rem;
}
.logo { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.nav { display: flex; gap: 2rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
    text-decoration: none; color: #999; font-size: 0.85rem; font-weight: 500;
    white-space: nowrap; transition: color 0.2s; padding: 0.3rem 0;
    border-bottom: 2px solid transparent;
}
.nav a:hover { color: #1a1a1a; }
.nav a.active { color: #1a1a1a; border-bottom-color: #1a1a1a; }

.edit-toggle {
    width: 32px; height: 32px; border-radius: 50%; border: 1px solid #eee;
    background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: #999; transition: all 0.2s; flex-shrink: 0;
}
.edit-toggle:hover { color: #1a1a1a; border-color: #ccc; }
body.edit-mode .edit-toggle { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

/* Main */
.main { max-width: 1400px; margin: 0 auto; padding: 2rem 3rem 4rem; }

/* Sections */
.section { margin-bottom: 4rem; }
.section-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 1.5rem; }
.section-subtitle {
    font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: #999; margin-top: 2rem; margin-bottom: 1rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.subtitle-actions { display: none; gap: 0.3rem; }
body.edit-mode .subtitle-actions { display: flex; }
body.edit-mode .cat-section[draggable] { cursor: grab; }
body.edit-mode .cat-section[draggable]:active { cursor: grabbing; }

/* Section drag states */
.cat-section { transition: opacity 0.2s, transform 0.2s; }
.cat-section.section-dragging { opacity: 0.4; transform: scale(0.98); }
.cat-section.section-drag-over {
    border-top: 2px dashed #bbb; padding-top: 1rem; margin-top: -2px;
}
.subtitle-btn {
    width: 20px; height: 20px; border: none; background: none;
    cursor: pointer; font-size: 0.7rem; color: #bbb; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
}
.subtitle-btn:hover { color: #666; background: #f0f0f0; }

/* Cards */
.cards-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem;
}
.card {
    background: #fff; border-radius: 14px; padding: 1.3rem;
    text-decoration: none; color: inherit;
    transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
    border: 1px solid transparent; position: relative;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 40px rgba(0,0,0,0.06); border-color: #eee; }
.card.dragging { opacity: 0.4; transform: scale(0.95); transition: all 0.15s; }
.card.drag-over { border: 2px dashed #ccc; transform: scale(1.02); background: #fcfcfc; }
body.edit-mode .card[draggable] { cursor: grab; }
body.edit-mode .card[draggable]:active { cursor: grabbing; }
.card-icon { width: 36px; height: 36px; border-radius: 10px; margin-bottom: 0.8rem; object-fit: cover; }
.card-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.3rem; }
.card-desc { font-size: 0.8rem; color: #888; }

.card-edit-controls {
    position: absolute; top: 0.7rem; right: 0.7rem;
    display: none; gap: 0.3rem; opacity: 0.15; transition: opacity 0.2s;
}
body.edit-mode .card-edit-controls { display: flex; }
body.edit-mode .card:hover .card-edit-controls { opacity: 1; }
.card-edit-btn {
    width: 24px; height: 24px; border-radius: 6px; border: none;
    background: transparent; cursor: pointer; font-size: 0.7rem;
    display: flex; align-items: center; justify-content: center; color: #999;
    transition: all 0.15s;
}
.card-edit-btn:hover { color: #333; background: rgba(0,0,0,0.04); }
.card-edit-btn.del:hover { color: #FF3B30; background: rgba(255,59,48,0.06); }

/* Add card placeholder */
.card-add {
    border: 1.5px dashed #ddd; background: transparent; border-radius: 14px;
    display: none; align-items: center; justify-content: center;
    cursor: pointer; min-height: 100px; color: #ccc; font-size: 0.85rem;
    transition: all 0.2s;
}
body.edit-mode .card-add { display: flex; }
.card-add:hover { border-color: #999; color: #999; }

/* Add category button */
.add-category-btn {
    display: none; margin-top: 2rem; padding: 0.6rem 1rem;
    border: 1.5px dashed #ddd; border-radius: 10px; background: transparent;
    color: #ccc; font-size: 0.82rem; cursor: pointer; transition: all 0.2s;
}
body.edit-mode .add-category-btn { display: inline-block; }
.add-category-btn:hover { border-color: #999; color: #999; }

/* Dims & Copy */
.dims-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
.dim-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.8rem 1rem; background: #fff; border-radius: 10px;
    cursor: pointer; transition: all 0.15s; position: relative;
}
.dim-item:hover { background: #f0f0f0; }
.dim-item:active { transform: scale(0.98); }
.dim-label { font-size: 0.82rem; color: #666; }
.dim-value { font-size: 0.8rem; font-weight: 600; font-family: 'SF Mono','Menlo',monospace; background: #f5f5f5; padding: 0.2rem 0.5rem; border-radius: 5px; }

.copy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.6rem; }
.copy-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.9rem 1.1rem; background: #fff; border-radius: 10px;
    cursor: pointer; transition: all 0.15s; gap: 1rem; position: relative;
}
.copy-item:hover { background: #f0f0f0; }
.copy-item:active { transform: scale(0.98); }
.copy-label { font-size: 0.82rem; font-weight: 500; white-space: nowrap; }
.copy-value { font-size: 0.78rem; color: #888; font-family: 'SF Mono','Menlo',monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.copy-icon { opacity: 0; font-size: 0.7rem; color: #999; transition: opacity 0.2s; flex-shrink: 0; }
.copy-item:hover .copy-icon { opacity: 1; }
.color-swatch { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.06); }

.item-edit-controls {
    position: absolute; top: 50%; right: 0.5rem; transform: translateY(-50%);
    display: none; gap: 0.2rem; opacity: 0.15; transition: opacity 0.2s;
}
body.edit-mode .item-edit-controls { display: flex; }
body.edit-mode .dim-item:hover .item-edit-controls,
body.edit-mode .copy-item:hover .item-edit-controls { opacity: 1; }
body.edit-mode .copy-icon { display: none; }

.item-add {
    display: none; padding: 0.7rem 1rem; border: 1.5px dashed #ddd;
    border-radius: 10px; background: transparent; color: #ccc;
    font-size: 0.78rem; cursor: pointer; transition: all 0.2s; text-align: center;
}
body.edit-mode .item-add { display: block; }
.item-add:hover { border-color: #999; color: #999; }

/* Toolbar */
.toolbar {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    background: rgba(255,255,255,0.75);
    backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid rgba(0,0,0,0.06); border-radius: 100px;
    padding: 0.45rem 0.6rem; display: none; gap: 0.3rem;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    z-index: 90;
}
body.edit-mode .toolbar { display: flex; }
.toolbar-btn {
    padding: 0.4rem 1rem; border: none; border-radius: 100px;
    background: transparent; font-size: 0.78rem; cursor: pointer;
    color: #666; transition: all 0.15s; white-space: nowrap;
}
.toolbar-btn:hover { background: rgba(0,0,0,0.04); color: #1a1a1a; }
.toolbar-btn.danger { color: #FF3B30; }
.toolbar-btn.danger:hover { background: rgba(255,59,48,0.06); }

/* Toast */
.toast {
    position: fixed; bottom: 2rem; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a1a1a; color: #fff; padding: 0.6rem 1.2rem;
    border-radius: 10px; font-size: 0.82rem; font-weight: 500;
    opacity: 0; transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
    pointer-events: none; z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
body.edit-mode .toast.show { transform: translateX(-50%) translateY(-40px); }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.2);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    z-index: 200; display: none; align-items: center; justify-content: center; padding: 1.5rem;
}
.modal-overlay.show { display: flex; }
.modal {
    background: rgba(255,255,255,0.95); backdrop-filter: blur(20px);
    border: 1px solid #eee; border-radius: 18px; padding: 2rem;
    width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
    width: 26px; height: 26px; border: none; background: #f0f0f0;
    border-radius: 50%; cursor: pointer; font-size: 0.85rem; color: #999;
    display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: #e0e0e0; }
.form-field { margin-bottom: 1rem; }
.form-field label { display: block; font-size: 0.72rem; font-weight: 500; color: #999; margin-bottom: 0.3rem; }
.form-field input {
    width: 100%; padding: 0.6rem 0.8rem; border: 1px solid #eee;
    border-radius: 8px; font-size: 0.88rem; outline: none;
    transition: border-color 0.2s; font-family: inherit; background: #fafafa;
}
.form-field input:focus { border-color: #1a1a1a; background: #fff; }
.form-field input.fetching {
    background: linear-gradient(90deg, #fafafa 25%, #f0f0f0 50%, #fafafa 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}
.form-field input.fetching::placeholder { color: #bbb; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; }
.btn-submit {
    padding: 0.55rem 1.2rem; background: #1a1a1a; color: #fff;
    border: none; border-radius: 8px; font-size: 0.82rem; font-weight: 500; cursor: pointer;
}
.btn-submit:hover { background: #333; }
.btn-cancel {
    padding: 0.55rem 1.2rem; background: #f5f5f5; color: #666;
    border: none; border-radius: 8px; font-size: 0.82rem; cursor: pointer;
}
.btn-cancel:hover { background: #eee; }

/* Batch Modal */
.modal-wide { max-width: 480px; }
.form-select {
    width: 100%; padding: 0.6rem 0.8rem; border: 1px solid #eee;
    border-radius: 8px; font-size: 0.88rem; outline: none;
    background: #fafafa; font-family: inherit; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.8rem center;
    transition: border-color 0.2s; cursor: pointer;
}
.form-select:focus { border-color: #1a1a1a; background-color: #fff; }
.form-textarea {
    width: 100%; padding: 0.7rem 0.8rem; border: 1px solid #eee;
    border-radius: 8px; font-size: 0.82rem; outline: none; resize: vertical;
    font-family: 'SF Mono','Menlo',monospace; line-height: 1.6;
    background: #fafafa; transition: border-color 0.2s; min-height: 120px;
}
.form-textarea:focus { border-color: #1a1a1a; background: #fff; }
.batch-status {
    font-size: 0.75rem; color: #999; min-height: 1.2rem; margin-bottom: 0.5rem;
    transition: opacity 0.3s;
}
.btn-submit.loading {
    opacity: 0.6; pointer-events: none;
    background: linear-gradient(90deg, #1a1a1a 25%, #333 50%, #1a1a1a 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite;
}

/* Responsive */
@media (max-width: 768px) {
    .header { padding: 1rem 1.5rem; flex-direction: column; align-items: flex-start; gap: 0.8rem; }
    .edit-toggle { position: absolute; top: 1rem; right: 1.5rem; }
    .nav { gap: 1.2rem; }
    .main { padding: 1.5rem; }
    .section-title { font-size: 1.3rem; }
    .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 0.8rem; }
    .dims-grid { grid-template-columns: 1fr; }
    .copy-grid { grid-template-columns: 1fr; }
    .card { padding: 1rem; }
}
@media (max-width: 480px) { .cards-grid { grid-template-columns: 1fr; } }
