/* ============================================
   Slides Icons - PowerPoint Add-in
   Modern icon browser with 94K+ icons
   ============================================ */

:root {
    /* Colors - Light Theme */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;

    --bg-app: #ffffff;
    --bg-sidebar: #f8fafc;
    --bg-header: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-active: #e2e8f0;

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border: #e2e8f0;
    --divider: #f1f5f9;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);

    --radius: 8px;
    --radius-sm: 4px;

    --header-height: 60px;
    --header-height: 60px;
    --sidebar-width: 240px;

    --icon-size: 48px;
}

.hidden {
    display: none !important;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--bg-dark) 100%);
    padding: 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#toggleSidebar {
    position: absolute;
    left: 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#toggleSidebar:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.logo-container {
    text-align: center;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.tagline {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Controls */
.controls {
    padding: 12px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.search-box {
    position: relative;
    flex: 1;
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary);
}

.toggle-control input {
    cursor: pointer;
}

.toggle-control:hover {
    color: var(--text-primary);
}


.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
}

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

.divider {
    width: 1px;
    height: 24px;
    background: var(--divider);
}

.control-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bg-control {
    background: var(--bg-hover);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

input[type='color'] {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

input[type='color']:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.control-select {
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 8px;
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, opacity 0.3s ease;
}

/* Collapsed Sidebar State */
body.sidebar-collapsed .sidebar {
    width: 0;
    opacity: 0;
    border-right: none;
}

.sidebar-header {
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.total-count {
    color: var(--primary);
}

.library-list {
    flex: 1;
    overflow-y: auto;
}

.library-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    border-left: 2px solid transparent;
    transition: all 0.15s;
}

.library-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.library-item.active {
    background: var(--bg-card);
    color: var(--primary);
    border-left-color: var(--primary);
}

.library-item .count {
    font-size: 10px;
    color: var(--text-muted);
}

/* Icons Panel */
.icons-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.icons-header {
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.icon-count {
    color: var(--text-muted);
    font-weight: normal;
}

.icons-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--icon-size), 1fr));
    gap: 8px;
    align-content: start;
}

.icon-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 8px;
    transition: all 0.15s;
}

.icon-item:hover {
    border-color: var(--primary);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.icon-item:active {
    transform: scale(0.95);
}

/* Loading State */
.loading-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Toast */
.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 12px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 100;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--accent);
}

.toast.error {
    border-color: #e53e3e;
}

/* Mini spinner for icon placeholders */
.icon-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Icon limit message */
.icon-limit-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: 11px;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* Robust rendering container */
.icon-preview {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image tag with drop-shadow color trick */
.icon-img-shadowed {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Move image far away and cast a shadow back to original position */
    /* This allows coloring any transparent SVG/PNG with currentColor */
    filter: drop-shadow(0 1000px 0 currentColor);
    transform: translateY(-1000px);
    display: block;
}

/* Fallback/Direct Image */
.icon-img-direct {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Load More Button */
.load-more-container {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 16px;
}

.load-more-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.load-more-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.load-more-btn:active {
    transform: translateY(0);
}