:root {
    --primary: #2da44e;
    --danger: #cf222e;
    --bg: #f6f8fa;
    --border: #d0d7de;
    --text: #24292f;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 50px;
}

/* ------------------ HEADER ------------------ */
header {
    background: #24292f;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.2rem;
}
header button {
    cursor: pointer;
}

main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ------------------ READ-ONLY BANNER ------------------ */
.readonly-banner {
    background: #fff8c5;
    border: 1px solid #d4a72c;
    border-radius: 6px;
    padding: 10px 16px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #633c01;
}
.readonly-banner a {
    color: #0969da;
    font-weight: 600;
}

/* ------------------ TOOLBAR ------------------ */
.toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.search-box {
    position: relative;
}
.search-box input {
    padding: 8px 12px 8px 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 250px;
}
.search-box i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
}

button {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid rgba(27, 31, 35, 0.15);
    font-weight: 600;
    cursor: pointer;
}
button.primary { background: #0969da; color: white; border: none; }
button.success { background: var(--primary); color: white; border: none; }
button.danger  { background: var(--danger); color: white; border: none; }
button.secondary { background: #f3f4f6; }

/* ------------------ CATEGORY FILTERS ------------------ */
.category-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 1rem;
}

.filter-btn {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: white;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    color: #57606a;
    transition: all 0.15s;
}
.filter-btn:hover {
    border-color: #0969da;
    color: #0969da;
}
.filter-btn.active {
    background: #0969da;
    color: white;
    border-color: #0969da;
}
.filter-btn--all.active {
    background: #24292f;
    border-color: #24292f;
}

/* ------------------ CATEGORY BADGES ------------------ */
/* Generate a palette by cycling hues; add more as needed */
.category-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.category-badge--wiki     { background: #dbeafe; color: #1e40af; }
.category-badge--link     { background: #dcfce7; color: #166534; }
.category-badge--app      { background: #fef9c3; color: #854d0e; }
.category-badge--glyph    { background: #fce7f3; color: #9d174d; }
.category-badge--toy      { background: #ede9fe; color: #5b21b6; }
.category-badge--firmware { background: #ffedd5; color: #9a3412; }
/* Fallback for unknown categories */
.category-badge           { background: #f3f4f6; color: #374151; }

/* ------------------ TABLE ------------------ */
.table-container {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

th {
    background: #f6f8fa;
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: #57606a;
}

td {
    padding: 12px 8px;
    border-bottom: 1px solid #eaecef;
    vertical-align: middle;
    line-height: 1.4;
}

td[contenteditable="true"] {
    background: #fff;
    transition: background 0.2s;
}
td[contenteditable="true"]:focus {
    background: #fff8c5;
    outline: 2px solid #0969da;
    outline-offset: -2px;
    border-radius: 4px;
}

tr:hover td { background: #f8f9fa; }

.action-buttons { display: flex; gap: 8px; justify-content: center; }

.link-cell-text {
    word-break: break-all;
    font-family: monospace;
    font-size: 0.9rem;
    color: #0969da;
}

.copy-btn { padding: 6px 10px; transition: all 0.2s; }
.copy-btn:hover { background: #eef; }

/* Drag & Drop */
.drag-handle { cursor: grab; color: #bbb; text-align: center; }
tr.dragging  { opacity: 0.5; background: #eef; }

/* ------------------ MODAL ------------------ */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
.modal-content small   { display: block; color: #666; margin-top: 4px; font-size: 0.8rem; }
.modal-content label   { display: block; margin-bottom: 1rem; font-weight: 600; }
.modal-content input   { width: 100%; padding: 8px; margin-top: 5px; box-sizing: border-box; border: 1px solid var(--border); border-radius: 4px; }
.modal-actions         { margin-top: 1.5rem; display: flex; gap: 10px; justify-content: flex-end; }

/* ------------------ TOAST ------------------ */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #24292f;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    white-space: nowrap;
    z-index: 3000;
}
.toast--success { border-left: 4px solid var(--primary); }
.toast--error   { border-left: 4px solid var(--danger); }
.toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------ LOADER ------------------ */
.loading-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.loading-overlay[hidden] { display: none !important; }

.spinner {
    width: 40px; height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

[hidden] { display: none !important; }