:root {
    --primary-color: #4353FF;
    --primary-hover: #3240D9;
    --bg-color: #F8F9FA;
    --sidebar-bg: #FFFFFF;
    --card-bg: #FFFFFF;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --tag-bg: #F3F4F6;
    --tag-text: #4B5563;
    
    /* Layout Variables */
    --sidebar-width: 260px;
    --header-height: 72px;
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-color);
    line-height: 1.5;
    overflow-x: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.logo-icon {
    color: var(--primary-color);
}

.logo h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    padding: 2px 16px;
}

.category-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.category-link:hover {
    background-color: var(--tag-bg);
    color: var(--text-primary);
}

.category-link.active {
    background-color: #EBF0FF;
    color: var(--primary-color);
}

.category-count {
    font-size: 12px;
    background-color: var(--tag-bg);
    padding: 2px 8px;
    border-radius: 12px;
}

.category-link.active .category-count {
    background-color: #D6E4FF;
    color: var(--primary-color);
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-secondary);
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.top-header {
    height: var(--header-height);
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.search-container {
    position: relative;
    width: 400px;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-secondary);
}

#search-input {
    width: 100%;
    padding: 12px 40px 12px 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: #FFFFFF;
    transition: all 0.2s ease;
    outline: none;
    font-family: inherit;
}

#search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 83, 255, 0.1);
}

.keyboard-shortcut {
    position: absolute;
    right: 14px;
    font-size: 12px;
    color: var(--text-secondary);
    background-color: var(--tag-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 6px;
    pointer-events: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 24px;
}

.pattern-count {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.header-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.header-link:hover {
    color: var(--text-primary);
}

.btn-primary {
    background-color: var(--primary-color);
    color: #FFFFFF;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

/* Content Body */
.content-body {
    padding: 40px 32px;
}

.category-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

/* Grid Layout */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* Card Styling */
.component-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.component-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary-color);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.05);
}

.card-preview {
    background-color: #F9FAFB;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    padding: 20px;
    overflow: hidden;
}

.card-info {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    flex: 1;
    line-height: 1.6;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    background-color: var(--tag-bg);
    color: var(--tag-text);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: #FFFFFF;
    width: 100%;
    max-width: 960px;
    max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.modal-overlay.open .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 10;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-header {
    padding: 32px 40px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 24px;
    margin-bottom: 12px;
}

.modal-tags {
    display: flex;
    gap: 8px;
}

.modal-tabs {
    display: flex;
    padding: 0 40px;
    border-bottom: 1px solid var(--border-color);
    background-color: #F9FAFB;
}

.tab-btn {
    background: none;
    border: none;
    padding: 16px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.modal-body {
    padding: 40px;
    overflow-y: auto;
    flex: 1;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.preview-container {
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 40px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 32px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

/* Reset styles within preview to avoid main CSS leakage */
.preview-container * {
    all: revert;
    box-sizing: border-box;
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
}

.description-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.description-section p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.7;
}

.code-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: -10px;
    position: relative;
    z-index: 2;
}

.copy-btn {
    background-color: var(--tag-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background-color: #E5E7EB;
}

pre[class*="language-"] {
    border-radius: 12px !important;
    margin: 0 !important;
    padding: 24px !important;
    font-size: 14px;
    line-height: 1.5;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
    .main-content {
        margin-left: 200px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .main-content {
        margin-left: 0;
    }
    .top-header {
        padding: 0 16px;
    }
    .search-container {
        width: 100%;
        max-width: 300px;
    }
    .modal-content {
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
}

/* Standalone component frames use the full preview width. */
#modal-preview.isolated-preview { padding: 0; display: block; overflow: hidden; }
#modal-preview.isolated-preview iframe { width: 100%; display: block; border: 0; }
.component-card[role="button"]:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 3px; }
@media (max-width: 600px) {
    #component-modal { padding: 12px; }
    #component-modal .modal-content { margin: 0; width: 100%; max-height: calc(100dvh - 24px); }
    #component-modal .modal-header { padding: 22px 44px 16px 18px; }
    #component-modal .modal-header h2 { font-size: 18px; }
    #component-modal .modal-tags { flex-wrap: wrap; }
    #component-modal .modal-tabs { padding: 0 18px; }
    #component-modal .modal-body { padding: 14px; }
    #component-modal .modal-close { right: 16px; top: 15px; }
}

.card-preview.isolated-preview { padding: 0; align-items: flex-start; }
