/* --- Font Manager Main Container --- */
#fontManager {
    position: relative; /* Needed for the loader overlay */
    width: 100%;
    background-color: #f9f9f9;
    border: 1px solid #000;
    border-radius: 8px;
    padding: 10px;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin-top:15px;
    min-height: 400px; /* Ensure it has some height during load */
}

.fm-error {
    padding: 20px;
    text-align: center;
    color: #d8000c;
    background-color: #ffbaba;
    border: 1px solid #d8000c;
    border-radius: 4px;
}

/* --- Tabs Header --- */
.fm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.fm-tabs {
    display: flex;
    gap: 5px;
}

.fm-tab {
    padding: 8px 16px;
    cursor: pointer;
    border: 1px solid #ccc;
    border-bottom: none;
    background-color: #e9e9e9;
    border-radius: 4px 4px 0 0;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.fm-tab:hover {
    background-color: #dcdcdc;
}

.fm-tab.active {
    background-color: #fff;
    border-color: #ccc;
    border-bottom: 1px solid #fff;
    margin-bottom: -1px;
    color: #03740c;
}

.fm-selected-count {
    font-size: 0.9em;
    font-weight: bold;
    color: #333;
}

#fm-selected-count-badge {
    background-color: #03740c;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.9em;
}

/* --- Tag Filters --- */
.fm-tag-filters {
    padding: 5px 0;
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fm-tag-filter {
    padding: 4px 12px;
    font-size: 0.85em;
    background-color: #e0e0e0;
    border: 1px solid transparent;
    border-radius: 15px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.fm-tag-filter:hover {
    background-color: #d0d0d0;
}

.fm-tag-filter.active {
    background-color: #4a90e2;
    color: white;
    font-weight: bold;
}


/* --- Grid and Font Items --- */
.fm-grid-container {
    position: relative;
    height: 400px; /* Or adjust as needed */
    overflow-y: auto;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    align-content: start;
}

.fm-font-item {
    position: relative;
    border: 2px solid #eee;
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100px;
}

.fm-font-item:hover {
    border-color: #4a90e2;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.fm-font-item.selected {
    border-color: #03740c;
    box-shadow: 0 0 10px rgba(3, 116, 12, 0.4);
}

.fm-font-item.premium::after {
    content: '★';
    color: #f5a623;
    font-size: 1.2em;
    position: absolute;
    top: -5px;
    right: 2px;
    cursor: help;
}

/* Tooltip for premium star - only for disabled (non-member) items */
.fm-font-item.premium.disabled::before {
    content: 'Premium font';
    position: absolute;
    bottom: 0;
    right: 0;
    background-color: #333;
    color: white;
    padding: 3px 8px;
    border-radius: 4px 0 5px 0;
    font-size: 0.75em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 10;
}

/* Show tooltip on hover over the disabled premium item */
.fm-font-item.premium.disabled:hover::before {
    opacity: 1;
    visibility: visible;
}

.fm-font-item.disabled {
    cursor: not-allowed;
    opacity: 0.6;
    background-color: #f8f8f8;
}

.fm-font-name {
    font-weight: bold;
    font-size: 0.85em;
    color: #333;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fm-font-preview {
    font-size: 32px; /* Increased from 28px */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 5px 0;
    color: #222;
    line-height: 1.2;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Loader --- */
.fm-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

.fm-loader::after {
    content: '';
    border: 8px solid #f3f3f3; /* Light grey */
    border-top: 8px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: fm-spin 1s linear infinite;
}

@keyframes fm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- My Stash Specific Styles --- */
.fm-stash-promo {
    padding: 20px;
    text-align: center;
    grid-column: 1 / -1; /* Span all columns */
}

.fm-stash-banner {
    grid-column: 1 / -1; /* Make the banner span the full width of the grid */
    padding: 10px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 10px;
    text-align: center;
}

.fm-stash-warning {
    font-size: 0.9em;
    color: #c00;
    background-color: #fbeaea;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #e5c0c0;
    margin-bottom: 10px;
}

.fm-button-primary {
    padding: 10px 20px;
    border: none;
    background-color: #03740c;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
}

.fm-button-primary:hover {
    background-color: #025c0a;
}

#fm-manage-local-fonts {
    background-color: #4a90e2;
}

#fm-manage-local-fonts:hover {
    background-color: #357abd;
}

.fm-handwriting-banner {
    grid-column: 1 / -1; /* Span full width */
    padding: 10px;
    margin-bottom: 10px;
    background-color: #e8f4fd;
    border: 1px solid #b3d7f0;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    color: #2c5282;
}

/* --- Swal2 Modal Styles for Font List --- */
.swal-wide {
    width: 80% !important;
    max-width: 800px;
}

#fontlist {
    text-align: left;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 10px;
    margin-top: 15px;
}

#fontlist .font-item {
    display: flex;
    align-items: center;
    padding: 5px;
    border-bottom: 1px solid #f0f0f0;
}

#fontlist .font-item:last-child {
    border-bottom: none;
}

#fontlist .font-select {
    margin-right: 10px;
}

#fontlist h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: #333;
}
#fontlist .saved-fonts-section {
    margin-bottom: 20px;
}