:root {
    --bg: #f4f4f9;
    --surface: #ffffff;
    --primary: #0070f3;
    --primary-light: #e6f1ff;
    --text: #333;
    --border: #ddd;
    --danger: #ff4d4f;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Helpers */
.hidden { display: none !important; }

/* Header */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    box-sizing: border-box;
}

.logo { font-weight: bold; font-size: 1.2rem; }

.actions { display: flex; gap: 0.5rem; align-items: center; }

.actions button {
    margin-left: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.actions button.primary { background: var(--primary); color: white; border-color: var(--primary); }
.actions button.btn-del { color: var(--danger); border-color: #ffd6d7; background: #fff1f0; }

.label { margin-right: 1rem; font-weight: 500; color: var(--primary); }

/* Main Area */
main {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

#breadcrumbs {
    font-family: monospace;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: #eef;
    border-radius: 4px;
    color: var(--primary);
}

/* File Grid */
.file-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.file-item {
    background: var(--surface);
    border: 2px solid transparent; /* Reserve space for border */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 1rem;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.file-item:hover { background: #fafafa; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

/* Selection State */
.file-item.selected {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.item-icon { 
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
    font-size: 3rem;
    border-radius: 4px;
    overflow: hidden;
}

.file-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Don't crop, show full image */
    background: #eee;
}

.item-name { 
    font-weight: 500; 
    font-size: 0.9rem; 
    word-break: break-all;
    line-height: 1.3;
}
.item-meta { font-size: 0.75rem; color: #666; margin-top: 0.25rem; }

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
}

.modal-content {
    background: white;
    width: 80%;
    height: 80%;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.modal-content.auto-width { width: auto; max-width: 90%; height: auto; max-height: 90%; }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-body { padding: 1rem 0; }
.modal-footer { margin-top: 1rem; text-align: right; }

.full-input {
    width: 300px;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

#editorTextarea {
    flex: 1;
    font-family: monospace;
    padding: 1rem;
    border: 1px solid var(--border);
    resize: none;
    outline: none;
}

.image-container { display: flex; justify-content: center; background: black; padding: 10px; border-radius: 4px; }
.image-container img { max-width: 100%; max-height: 75vh; }